Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0b688ec8
Commit
0b688ec8
authored
May 06, 2020
by
Thomas Randolph
Committed by
Natalia Tepluhina
May 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Centralize logic for moving to neighboring commits in a Vuex action
parent
d154f922
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+20
-0
spec/frontend/diffs/store/actions_spec.js
spec/frontend/diffs/store/actions_spec.js
+41
-0
No files found.
app/assets/javascripts/diffs/store/actions.js
View file @
0b688ec8
...
...
@@ -665,5 +665,25 @@ export function changeCurrentCommit({ dispatch, commit, state }, { commitId }) {
return
dispatch
(
'
fetchDiffFilesMeta
'
);
}
export
function
moveToNeighboringCommit
({
dispatch
,
state
},
{
direction
})
{
const
previousCommitId
=
state
.
commit
?.
prev_commit_id
;
const
nextCommitId
=
state
.
commit
?.
next_commit_id
;
const
canMove
=
{
next
:
!
state
.
isLoading
&&
nextCommitId
,
previous
:
!
state
.
isLoading
&&
previousCommitId
,
};
let
commitId
;
if
(
direction
===
'
next
'
&&
canMove
.
next
)
{
commitId
=
nextCommitId
;
}
else
if
(
direction
===
'
previous
'
&&
canMove
.
previous
)
{
commitId
=
previousCommitId
;
}
if
(
commitId
)
{
dispatch
(
'
changeCurrentCommit
'
,
{
commitId
});
}
}
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export
default
()
=>
{};
spec/frontend/diffs/store/actions_spec.js
View file @
0b688ec8
...
...
@@ -44,6 +44,7 @@ import {
setExpandedDiffLines
,
setSuggestPopoverDismissed
,
changeCurrentCommit
,
moveToNeighboringCommit
,
}
from
'
~/diffs/store/actions
'
;
import
eventHub
from
'
~/notes/event_hub
'
;
import
*
as
types
from
'
~/diffs/store/mutation_types
'
;
...
...
@@ -1406,4 +1407,44 @@ describe('DiffsStoreActions', () => {
},
);
});
describe
(
'
moveToNeighboringCommit
'
,
()
=>
{
it
.
each
`
direction | expected | currentCommit
${
'
next
'
}
|
${
'
NEXTSHA
'
}
|
${{
next_commit_id
:
'
NEXTSHA
'
}
}
${
'
previous
'
}
|
${
'
PREVIOUSSHA
'
}
|
${{
prev_commit_id
:
'
PREVIOUSSHA
'
}
}
`
(
'
for the direction "$direction", dispatches the action to move to the SHA "$expected"
'
,
({
direction
,
expected
,
currentCommit
})
=>
{
return
testAction
(
moveToNeighboringCommit
,
{
direction
},
{
commit
:
currentCommit
},
[],
[{
type
:
'
changeCurrentCommit
'
,
payload
:
{
commitId
:
expected
}
}],
);
},
);
it
.
each
`
direction | diffsAreLoading | currentCommit
${
'
next
'
}
|
${
false
}
|
${{
prev_commit_id
:
'
PREVIOUSSHA
'
}
}
${
'
next
'
}
|
${
true
}
|
${{
prev_commit_id
:
'
PREVIOUSSHA
'
}
}
${
'
next
'
}
|
${
false
}
|
${
undefined
}
${
'
previous
'
}
|
${
false
}
|
${{
next_commit_id
:
'
NEXTSHA
'
}
}
${
'
previous
'
}
|
${
true
}
|
${{
next_commit_id
:
'
NEXTSHA
'
}
}
${
'
previous
'
}
|
${
false
}
|
${
undefined
}
`
(
'
given `{ "isloading": $diffsAreLoading, "commit": $currentCommit }` in state, no actions are dispatched
'
,
({
direction
,
diffsAreLoading
,
currentCommit
})
=>
{
return
testAction
(
moveToNeighboringCommit
,
{
direction
},
{
commit
:
currentCommit
,
isLoading
:
diffsAreLoading
},
[],
[],
);
},
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment