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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
e4ec50b7
Commit
e4ec50b7
authored
Mar 02, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for query params for labels endpoint
parent
f29dbaf5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
2 deletions
+62
-2
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
...ascripts/filtered_search/filtered_search_visual_tokens.js
+21
-2
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+8
-0
spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js
...pts/filtered_search/filtered_search_visual_tokens_spec.js
+18
-0
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+15
-0
No files found.
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
View file @
e4ec50b7
import
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
import
AjaxCache
from
'
../lib/utils/ajax_cache
'
;
import
AjaxCache
from
'
~/lib/utils/ajax_cache
'
;
import
{
objectToQueryString
}
from
'
~/lib/utils/common_utils
'
;
import
Flash
from
'
../flash
'
;
import
Flash
from
'
../flash
'
;
import
FilteredSearchContainer
from
'
./container
'
;
import
FilteredSearchContainer
from
'
./container
'
;
import
UsersCache
from
'
../lib/utils/users_cache
'
;
import
UsersCache
from
'
../lib/utils/users_cache
'
;
...
@@ -16,6 +17,21 @@ export default class FilteredSearchVisualTokens {
...
@@ -16,6 +17,21 @@ export default class FilteredSearchVisualTokens {
};
};
}
}
/**
* Returns a computed API endpoint
* and query string composed of values from endpointQueryParams
* @param {String} endpoint
* @param {String} endpointQueryParams
*/
static
getEndpointWithQueryParams
(
endpoint
,
endpointQueryParams
)
{
if
(
!
endpointQueryParams
)
{
return
endpoint
;
}
const
queryString
=
objectToQueryString
(
JSON
.
parse
(
endpointQueryParams
));
return
`
${
endpoint
}
?
${
queryString
}
`
;
}
static
unselectTokens
()
{
static
unselectTokens
()
{
const
otherTokens
=
FilteredSearchContainer
.
container
.
querySelectorAll
(
'
.js-visual-token .selectable.selected
'
);
const
otherTokens
=
FilteredSearchContainer
.
container
.
querySelectorAll
(
'
.js-visual-token .selectable.selected
'
);
[].
forEach
.
call
(
otherTokens
,
t
=>
t
.
classList
.
remove
(
'
selected
'
));
[].
forEach
.
call
(
otherTokens
,
t
=>
t
.
classList
.
remove
(
'
selected
'
));
...
@@ -86,7 +102,10 @@ export default class FilteredSearchVisualTokens {
...
@@ -86,7 +102,10 @@ export default class FilteredSearchVisualTokens {
static
updateLabelTokenColor
(
tokenValueContainer
,
tokenValue
)
{
static
updateLabelTokenColor
(
tokenValueContainer
,
tokenValue
)
{
const
filteredSearchInput
=
FilteredSearchContainer
.
container
.
querySelector
(
'
.filtered-search
'
);
const
filteredSearchInput
=
FilteredSearchContainer
.
container
.
querySelector
(
'
.filtered-search
'
);
const
baseEndpoint
=
filteredSearchInput
.
dataset
.
baseEndpoint
;
const
baseEndpoint
=
filteredSearchInput
.
dataset
.
baseEndpoint
;
const
labelsEndpoint
=
`
${
baseEndpoint
}
/labels.json`
;
const
labelsEndpoint
=
FilteredSearchVisualTokens
.
getEndpointWithQueryParams
(
`
${
baseEndpoint
}
/labels.json`
,
filteredSearchInput
.
dataset
.
endpointQueryParams
,
);
return
AjaxCache
.
retrieve
(
labelsEndpoint
)
return
AjaxCache
.
retrieve
(
labelsEndpoint
)
.
then
(
FilteredSearchVisualTokens
.
preprocessLabel
.
bind
(
null
,
labelsEndpoint
))
.
then
(
FilteredSearchVisualTokens
.
preprocessLabel
.
bind
(
null
,
labelsEndpoint
))
...
...
app/assets/javascripts/lib/utils/common_utils.js
View file @
e4ec50b7
...
@@ -302,6 +302,14 @@ export const parseQueryStringIntoObject = (query = '') => {
...
@@ -302,6 +302,14 @@ export const parseQueryStringIntoObject = (query = '') => {
},
{});
},
{});
};
};
/**
* Converts object with key-value pairs
* into query-param string
*
* @param {Object} params
*/
export
const
objectToQueryString
=
(
params
=
{})
=>
Object
.
keys
(
params
).
map
(
param
=>
`
${
param
}
=
${
params
[
param
]}
`
).
join
(
'
&
'
);
export
const
buildUrlWithCurrentLocation
=
param
=>
(
param
?
`
${
window
.
location
.
pathname
}${
param
}
`
:
window
.
location
.
pathname
);
export
const
buildUrlWithCurrentLocation
=
param
=>
(
param
?
`
${
window
.
location
.
pathname
}${
param
}
`
:
window
.
location
.
pathname
);
/**
/**
...
...
spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js
View file @
e4ec50b7
...
@@ -128,6 +128,24 @@ describe('Filtered Search Visual Tokens', () => {
...
@@ -128,6 +128,24 @@ describe('Filtered Search Visual Tokens', () => {
});
});
});
});
describe
(
'
getEndpointWithQueryParams
'
,
()
=>
{
it
(
'
returns `endpoint` string as is when second param `endpointQueryParams` is undefined, null or empty string
'
,
()
=>
{
const
endpoint
=
'
foo/bar/labels.json
'
;
expect
(
subject
.
getEndpointWithQueryParams
(
endpoint
)).
toBe
(
endpoint
);
expect
(
subject
.
getEndpointWithQueryParams
(
endpoint
,
null
)).
toBe
(
endpoint
);
expect
(
subject
.
getEndpointWithQueryParams
(
endpoint
,
''
)).
toBe
(
endpoint
);
});
it
(
'
returns `endpoint` string with values of `endpointQueryParams`
'
,
()
=>
{
const
endpoint
=
'
foo/bar/labels.json
'
;
const
singleQueryParams
=
'
{"foo":"true"}
'
;
const
multipleQueryParams
=
'
{"foo":"true","bar":"true"}
'
;
expect
(
subject
.
getEndpointWithQueryParams
(
endpoint
,
singleQueryParams
)).
toBe
(
`
${
endpoint
}
?foo=true`
);
expect
(
subject
.
getEndpointWithQueryParams
(
endpoint
,
multipleQueryParams
)).
toBe
(
`
${
endpoint
}
?foo=true&bar=true`
);
});
});
describe
(
'
unselectTokens
'
,
()
=>
{
describe
(
'
unselectTokens
'
,
()
=>
{
it
(
'
does nothing when there are no tokens
'
,
()
=>
{
it
(
'
does nothing when there are no tokens
'
,
()
=>
{
const
beforeHTML
=
tokensContainer
.
innerHTML
;
const
beforeHTML
=
tokensContainer
.
innerHTML
;
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
e4ec50b7
...
@@ -166,6 +166,21 @@ describe('common_utils', () => {
...
@@ -166,6 +166,21 @@ describe('common_utils', () => {
});
});
});
});
describe
(
'
objectToQueryString
'
,
()
=>
{
it
(
'
returns empty string when `param` is undefined, null or empty string
'
,
()
=>
{
expect
(
commonUtils
.
objectToQueryString
()).
toBe
(
''
);
expect
(
commonUtils
.
objectToQueryString
(
''
)).
toBe
(
''
);
});
it
(
'
returns query string with values of `params`
'
,
()
=>
{
const
singleQueryParams
=
{
foo
:
true
};
const
multipleQueryParams
=
{
foo
:
true
,
bar
:
true
};
expect
(
commonUtils
.
objectToQueryString
(
singleQueryParams
)).
toBe
(
'
foo=true
'
);
expect
(
commonUtils
.
objectToQueryString
(
multipleQueryParams
)).
toBe
(
'
foo=true&bar=true
'
);
});
});
describe
(
'
buildUrlWithCurrentLocation
'
,
()
=>
{
describe
(
'
buildUrlWithCurrentLocation
'
,
()
=>
{
it
(
'
should build an url with current location and given parameters
'
,
()
=>
{
it
(
'
should build an url with current location and given parameters
'
,
()
=>
{
expect
(
commonUtils
.
buildUrlWithCurrentLocation
()).
toEqual
(
window
.
location
.
pathname
);
expect
(
commonUtils
.
buildUrlWithCurrentLocation
()).
toEqual
(
window
.
location
.
pathname
);
...
...
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