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
020eb30f
Commit
020eb30f
authored
Dec 13, 2021
by
Zack Cuddy
Committed by
Nicolò Maria Mezzopera
Dec 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Global Search Refactor - Fix Scoped Queries
parent
4b83234b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
73 deletions
+97
-73
app/assets/javascripts/header_search/store/getters.js
app/assets/javascripts/header_search/store/getters.js
+46
-38
spec/frontend/header_search/store/getters_spec.js
spec/frontend/header_search/store/getters_spec.js
+51
-35
No files found.
app/assets/javascripts/header_search/store/getters.js
View file @
020eb30f
import
{
omitBy
,
isNil
}
from
'
lodash
'
;
import
{
objectToQuery
}
from
'
~/lib/utils/url_utility
'
;
import
{
...
...
@@ -12,23 +13,29 @@ import {
}
from
'
../constants
'
;
export
const
searchQuery
=
(
state
)
=>
{
const
query
=
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
project_id
:
state
.
searchContext
.
project
?.
id
,
group_id
:
state
.
searchContext
.
group
?.
id
,
scope
:
state
.
searchContext
.
scope
,
};
const
query
=
omitBy
(
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
project_id
:
state
.
searchContext
.
project
?.
id
,
group_id
:
state
.
searchContext
.
group
?.
id
,
scope
:
state
.
searchContext
?.
scope
,
},
isNil
,
);
return
`
${
state
.
searchPath
}
?
${
objectToQuery
(
query
)}
`
;
};
export
const
autocompleteQuery
=
(
state
)
=>
{
const
query
=
{
term
:
state
.
search
,
project_id
:
state
.
searchContext
.
project
?.
id
,
project_ref
:
state
.
searchContext
.
ref
,
};
const
query
=
omitBy
(
{
term
:
state
.
search
,
project_id
:
state
.
searchContext
.
project
?.
id
,
project_ref
:
state
.
searchContext
?.
ref
,
},
isNil
,
);
return
`
${
state
.
autocompletePath
}
?
${
objectToQuery
(
query
)}
`
;
};
...
...
@@ -82,42 +89,43 @@ export const defaultSearchOptions = (state, getters) => {
};
export
const
projectUrl
=
(
state
)
=>
{
if
(
!
state
.
searchContext
.
project
||
!
state
.
searchContext
.
group
)
{
return
null
;
}
const
query
=
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
project_id
:
state
.
searchContext
.
project
.
id
,
group_id
:
state
.
searchContext
.
group
.
id
,
scope
:
state
.
searchContext
.
scope
,
};
const
query
=
omitBy
(
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
project_id
:
state
.
searchContext
?.
project
?.
id
,
group_id
:
state
.
searchContext
?.
group
?.
id
,
scope
:
state
.
searchContext
?.
scope
,
},
isNil
,
);
return
`
${
state
.
searchPath
}
?
${
objectToQuery
(
query
)}
`
;
};
export
const
groupUrl
=
(
state
)
=>
{
if
(
!
state
.
searchContext
.
group
)
{
return
null
;
}
const
query
=
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
group_id
:
state
.
searchContext
.
group
.
id
,
scope
:
state
.
searchContext
.
scope
,
};
const
query
=
omitBy
(
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
group_id
:
state
.
searchContext
?.
group
?.
id
,
scope
:
state
.
searchContext
?.
scope
,
},
isNil
,
);
return
`
${
state
.
searchPath
}
?
${
objectToQuery
(
query
)}
`
;
};
export
const
allUrl
=
(
state
)
=>
{
const
query
=
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
scope
:
state
.
searchContext
.
scope
,
};
const
query
=
omitBy
(
{
search
:
state
.
search
,
nav_source
:
'
navbar
'
,
scope
:
state
.
searchContext
?.
scope
,
},
isNil
,
);
return
`
${
state
.
searchPath
}
?
${
objectToQuery
(
query
)}
`
;
};
...
...
spec/frontend/header_search/store/getters_spec.js
View file @
020eb30f
...
...
@@ -37,18 +37,20 @@ describe('Header Search Store Getters', () => {
});
describe
.
each
`
group | project | expectedPath
${
null
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=undefined&group_id=undefined&scope=issues`
}
${
MOCK_GROUP
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=undefined&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
${
MOCK_GROUP
}
|
${
MOCK_PROJECT
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`
(
'
searchQuery
'
,
({
group
,
project
,
expectedPath
})
=>
{
describe
(
`when group is
${
group
?.
name
}
and
project
is
$
{
project
?.
name
}
`, () => {
group | project | scope | expectedPath
${
null
}
|
${
null
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
${
MOCK_GROUP
}
|
${
null
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
`
}
${
null
}
|
${
MOCK_PROJECT
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
`
}
${
MOCK_GROUP
}
|
${
MOCK_PROJECT
}
|
${
null
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
`
}
${
MOCK_GROUP
}
|
${
MOCK_PROJECT
}
|
${
'
issues
'
}
|
${
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`
(
'
searchQuery
'
,
({
group
,
project
,
scope
,
expectedPath
})
=>
{
describe
(
`when group is
${
group
?.
name
},
project
is
$
{
project
?.
name
},
and
scope
is
$
{
scope
}
`, () => {
beforeEach(() => {
createState({
searchContext: {
group,
project,
scope
: 'issues'
,
scope,
},
});
state.search = MOCK_SEARCH;
...
...
@@ -62,8 +64,9 @@ describe('Header Search Store Getters', () => {
describe.each`
project
|
ref
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
&project_id=undefined&project_ref=null`
}
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
&project_id=
${
MOCK_PROJECT
.
id
}
&project_ref=null`
}
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
`
}
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
&project_id=
${
MOCK_PROJECT
.
id
}
`
}
$
{
null
}
|
$
{
MOCK_PROJECT
.
id
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
&project_ref=
${
MOCK_PROJECT
.
id
}
`
}
$
{
MOCK_PROJECT
}
|
$
{
MOCK_PROJECT
.
id
}
|
$
{
`
${
MOCK_AUTOCOMPLETE_PATH
}
?term=
${
MOCK_SEARCH
}
&project_id=
${
MOCK_PROJECT
.
id
}
&project_ref=
${
MOCK_PROJECT
.
id
}
`
}
`('autocompleteQuery', ({ project, ref, expectedPath }) => {
describe(`
when
project
is
$
{
project
?.
name
}
and
project
ref
is
$
{
ref
}
`, () => {
...
...
@@ -132,18 +135,20 @@ describe('Header Search Store Getters', () => {
});
describe.each`
group
|
project
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
null
}
$
{
MOCK_GROUP
}
|
$
{
null
}
|
$
{
null
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`('projectUrl', ({ group, project, expectedPath }) => {
describe(`
when
group
is
$
{
group
?.
name
}
and
project
is
$
{
project
?.
name
}
`, () => {
group
|
project
|
scope
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
`
}
$
{
null
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
'
issues
'
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&project_id=
${
MOCK_PROJECT
.
id
}
&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`('projectUrl', ({ group, project, scope, expectedPath }) => {
describe(`
when
group
is
$
{
group
?.
name
},
project
is
$
{
project
?.
name
},
and
scope
is
$
{
scope
}
`, () => {
beforeEach(() => {
createState({
searchContext: {
group,
project,
scope
: 'issues'
,
scope,
},
});
state.search = MOCK_SEARCH;
...
...
@@ -156,18 +161,20 @@ describe('Header Search Store Getters', () => {
});
describe.each`
group
|
project
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
null
}
$
{
MOCK_GROUP
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`('groupUrl', ({ group, project, expectedPath }) => {
describe(`
when
group
is
$
{
group
?.
name
}
and
project
is
$
{
project
?.
name
}
`, () => {
group
|
project
|
scope
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
`
}
$
{
null
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
'
issues
'
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&group_id=
${
MOCK_GROUP
.
id
}
&scope=issues`
}
`('groupUrl', ({ group, project, scope, expectedPath }) => {
describe(`
when
group
is
$
{
group
?.
name
},
project
is
$
{
project
?.
name
},
and
scope
is
$
{
scope
}
`, () => {
beforeEach(() => {
createState({
searchContext: {
group,
project,
scope
: 'issues'
,
scope,
},
});
state.search = MOCK_SEARCH;
...
...
@@ -179,20 +186,29 @@ describe('Header Search Store Getters', () => {
});
});
describe('allUrl', () => {
const expectedPath = `
$
{
MOCK_SEARCH_PATH
}?
search
=
$
{
MOCK_SEARCH
}
&
nav_source
=
navbar
&
scope
=
issues
`;
beforeEach(() => {
createState({
searchContext: {
scope: 'issues',
},
describe.each`
group
|
project
|
scope
|
expectedPath
$
{
null
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
null
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
null
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
null
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar`
}
$
{
MOCK_GROUP
}
|
$
{
MOCK_PROJECT
}
|
$
{
'
issues
'
}
|
$
{
`
${
MOCK_SEARCH_PATH
}
?search=
${
MOCK_SEARCH
}
&nav_source=navbar&scope=issues`
}
`('allUrl', ({ group, project, scope, expectedPath }) => {
describe(`
when
group
is
$
{
group
?.
name
},
project
is
$
{
project
?.
name
},
and
scope
is
$
{
scope
}
`, () => {
beforeEach(() => {
createState({
searchContext: {
group,
project,
scope,
},
});
state.search = MOCK_SEARCH;
});
state.search = MOCK_SEARCH;
});
it(`
should
return
$
{
expectedPath
}
`, () => {
expect(getters.allUrl(state)).toBe(expectedPath);
it(`
should
return
$
{
expectedPath
}
`, () => {
expect(getters.allUrl(state)).toBe(expectedPath);
});
});
});
...
...
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