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
79166d64
Commit
79166d64
authored
Dec 01, 2020
by
Thomas Randolph
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fileByFile setting to the diffs state
Mix the user setting with the URL parameter and the cookie
parent
a56e364a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
0 deletions
+68
-0
app/assets/javascripts/diffs/constants.js
app/assets/javascripts/diffs/constants.js
+3
-0
app/assets/javascripts/diffs/store/modules/diff_state.js
app/assets/javascripts/diffs/store/modules/diff_state.js
+3
-0
app/assets/javascripts/diffs/utils/preferences.js
app/assets/javascripts/diffs/utils/preferences.js
+22
-0
spec/frontend/diffs/utils/preferences_spec.js
spec/frontend/diffs/utils/preferences_spec.js
+40
-0
No files found.
app/assets/javascripts/diffs/constants.js
View file @
79166d64
...
...
@@ -77,6 +77,9 @@ export const ALERT_COLLAPSED_FILES = 'collapsed';
export
const
DIFF_FILE_AUTOMATIC_COLLAPSE
=
'
automatic
'
;
export
const
DIFF_FILE_MANUAL_COLLAPSE
=
'
manual
'
;
// Diff view single file mode
export
const
DIFF_FILE_BY_FILE_COOKIE_NAME
=
'
fileViewMode
'
;
export
const
DIFF_VIEW_FILE_BY_FILE
=
'
single
'
;
// State machine states
export
const
STATE_IDLING
=
'
idle
'
;
export
const
STATE_LOADING
=
'
loading
'
;
...
...
app/assets/javascripts/diffs/store/modules/diff_state.js
View file @
79166d64
...
...
@@ -5,6 +5,8 @@ import {
DIFF_VIEW_COOKIE_NAME
,
DIFF_WHITESPACE_COOKIE_NAME
,
}
from
'
../../constants
'
;
import
{
fileByFile
}
from
'
../../utils/preferences
'
;
import
{
getDefaultWhitespace
}
from
'
../utils
'
;
const
viewTypeFromQueryString
=
getParameterValues
(
'
view
'
)[
0
];
...
...
@@ -39,6 +41,7 @@ export default () => ({
highlightedRow
:
null
,
renderTreeList
:
true
,
showWhitespace
:
getDefaultWhitespace
(
whiteSpaceFromQueryString
,
whiteSpaceFromCookie
),
viewDiffsFileByFile
:
fileByFile
(),
fileFinderVisible
:
false
,
dismissEndpoint
:
''
,
showSuggestPopover
:
true
,
...
...
app/assets/javascripts/diffs/utils/preferences.js
0 → 100644
View file @
79166d64
import
Cookies
from
'
js-cookie
'
;
import
{
getParameterValues
}
from
'
~/lib/utils/url_utility
'
;
import
{
DIFF_FILE_BY_FILE_COOKIE_NAME
,
DIFF_VIEW_FILE_BY_FILE
}
from
'
../constants
'
;
export
function
fileByFile
(
pref
=
false
)
{
const
search
=
getParameterValues
(
DIFF_FILE_BY_FILE_COOKIE_NAME
)?.[
0
];
const
cookie
=
Cookies
.
get
(
DIFF_FILE_BY_FILE_COOKIE_NAME
);
let
viewFileByFile
=
pref
;
// use the cookie first, if it exists
if
(
cookie
)
{
viewFileByFile
=
cookie
===
DIFF_VIEW_FILE_BY_FILE
;
}
// the search parameter of the URL should override, if it exists
if
(
search
)
{
viewFileByFile
=
search
===
DIFF_VIEW_FILE_BY_FILE
;
}
return
viewFileByFile
;
}
spec/frontend/diffs/utils/preferences_spec.js
0 → 100644
View file @
79166d64
import
Cookies
from
'
js-cookie
'
;
import
{
getParameterValues
}
from
'
~/lib/utils/url_utility
'
;
import
{
fileByFile
}
from
'
~/diffs/utils/preferences
'
;
import
{
DIFF_FILE_BY_FILE_COOKIE_NAME
,
DIFF_VIEW_FILE_BY_FILE
,
DIFF_VIEW_ALL_FILES
,
}
from
'
~/diffs/constants
'
;
jest
.
mock
(
'
~/lib/utils/url_utility
'
);
describe
(
'
diffs preferences
'
,
()
=>
{
describe
(
'
fileByFile
'
,
()
=>
{
it
.
each
`
result | preference | cookie | searchParam
${
false
}
|
${
false
}
|
${
undefined
}
|
${
undefined
}
${
true
}
|
${
true
}
|
${
undefined
}
|
${
undefined
}
${
true
}
|
${
false
}
|
${
DIFF_VIEW_FILE_BY_FILE
}
|
${
undefined
}
${
false
}
|
${
true
}
|
${
DIFF_VIEW_ALL_FILES
}
|
${
undefined
}
${
true
}
|
${
false
}
|
${
undefined
}
|
${[
DIFF_VIEW_FILE_BY_FILE
]}
${
false
}
|
${
true
}
|
${
undefined
}
|
${[
DIFF_VIEW_ALL_FILES
]}
${
true
}
|
${
false
}
|
${
DIFF_VIEW_FILE_BY_FILE
}
|
${[
DIFF_VIEW_FILE_BY_FILE
]}
${
true
}
|
${
true
}
|
${
DIFF_VIEW_ALL_FILES
}
|
${[
DIFF_VIEW_FILE_BY_FILE
]}
${
false
}
|
${
false
}
|
${
DIFF_VIEW_ALL_FILES
}
|
${[
DIFF_VIEW_ALL_FILES
]}
${
false
}
|
${
true
}
|
${
DIFF_VIEW_FILE_BY_FILE
}
|
${[
DIFF_VIEW_ALL_FILES
]}
`
(
'
should return $result when { preference: $preference, cookie: $cookie, search: $searchParam }
'
,
({
result
,
preference
,
cookie
,
searchParam
})
=>
{
if
(
cookie
)
{
Cookies
.
set
(
DIFF_FILE_BY_FILE_COOKIE_NAME
,
cookie
);
}
getParameterValues
.
mockReturnValue
(
searchParam
);
expect
(
fileByFile
(
preference
)).
toBe
(
result
);
},
);
});
});
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