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
beb4e01c
Commit
beb4e01c
authored
Aug 27, 2020
by
Tom Quirk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract parseDesignRouteHash into util
And add tests, and use this new util
parent
e434318a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
app/assets/javascripts/design_management/pages/design/index.vue
...sets/javascripts/design_management/pages/design/index.vue
+2
-1
app/assets/javascripts/design_management/utils/design_management_utils.js
...cripts/design_management/utils/design_management_utils.js
+9
-0
spec/frontend/design_management/utils/design_management_utils_spec.js
...d/design_management/utils/design_management_utils_spec.js
+17
-0
No files found.
app/assets/javascripts/design_management/pages/design/index.vue
View file @
beb4e01c
...
...
@@ -20,6 +20,7 @@ import {
extractDesign
,
updateImageDiffNoteOptimisticResponse
,
toDiffNoteGid
,
parseDesignRouteHash
,
}
from
'
../../utils/design_management_utils
'
;
import
{
updateStoreAfterAddImageDiffNote
,
...
...
@@ -147,7 +148,7 @@ export default {
Mousetrap
.
bind
(
'
esc
'
,
this
.
closeDesign
);
this
.
trackEvent
();
// We need to reset the active discussion when opening a new design
const
[,
noteId
]
=
this
.
$route
.
hash
.
match
(
/#note_
([
0-9
]
+
)
/
)
||
[]
;
const
noteId
=
parseDesignRouteHash
(
this
.
$route
.
hash
)
;
const
diffNoteGid
=
noteId
?
toDiffNoteGid
(
noteId
)
:
undefined
;
return
this
.
updateActiveDiscussion
(
diffNoteGid
);
},
...
...
app/assets/javascripts/design_management/utils/design_management_utils.js
View file @
beb4e01c
...
...
@@ -36,6 +36,15 @@ export const extractDesign = data => (extractDesigns(data) || [])[0];
export
const
toDiffNoteGid
=
noteId
=>
`gid://gitlab/DiffNote/
${
noteId
}
`
;
/**
* Return the note ID from a URL hash parameter
* @param {String} hash URL hash
*/
export
const
parseDesignRouteHash
=
hash
=>
{
const
[,
noteId
]
=
hash
.
match
(
'
#note_([0-9]+$)
'
)
||
[];
return
noteId
;
};
/**
* Generates optimistic response for a design upload mutation
* @param {Array<File>} files
...
...
spec/frontend/design_management/utils/design_management_utils_spec.js
View file @
beb4e01c
...
...
@@ -6,6 +6,7 @@ import {
updateImageDiffNoteOptimisticResponse
,
isValidDesignFile
,
extractDesign
,
parseDesignRouteHash
,
}
from
'
~/design_management/utils/design_management_utils
'
;
import
mockResponseNoDesigns
from
'
../mock_data/no_designs
'
;
import
mockResponseWithDesigns
from
'
../mock_data/designs
'
;
...
...
@@ -171,3 +172,19 @@ describe('extractDesign', () => {
});
});
});
describe
(
'
parseDesignRouteHash
'
,
()
=>
{
it
.
each
`
hash | expectedNoteId
${
'
#note_0
'
}
|
${
'
0
'
}
${
'
#note_1
'
}
|
${
'
1
'
}
${
'
#note_23
'
}
|
${
'
23
'
}
${
'
#note_456
'
}
|
${
'
456
'
}
${
'
note_1
'
}
|
${
undefined
}
${
'
#note_
'
}
|
${
undefined
}
${
'
#note_asd
'
}
|
${
undefined
}
${
'
#note_1asd
'
}
|
${
undefined
}
`
(
'
returns $expectedNoteId when hash is $hash
'
,
({
hash
,
expectedNoteId
})
=>
{
expect
(
parseDesignRouteHash
(
hash
)).
toBe
(
expectedNoteId
);
});
});
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