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
218825a6
Commit
218825a6
authored
Jul 02, 2021
by
Miguel Rincon
Committed by
Enrique Alcántara
Jul 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace objectToQueryString with objectToQuery
This change removes objectToQueryString in favor of objectToQuery
parent
ca94c201
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
34 deletions
+22
-34
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
...ascripts/filtered_search/filtered_search_visual_tokens.js
+3
-2
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+0
-11
app/assets/javascripts/lib/utils/url_utility.js
app/assets/javascripts/lib/utils/url_utility.js
+4
-4
app/assets/javascripts/packages/details/components/app.vue
app/assets/javascripts/packages/details/components/app.vue
+2
-2
spec/frontend/lib/utils/common_utils_spec.js
spec/frontend/lib/utils/common_utils_spec.js
+0
-15
spec/frontend/lib/utils/url_utility_spec.js
spec/frontend/lib/utils/url_utility_spec.js
+13
-0
No files found.
app/assets/javascripts/filtered_search/filtered_search_visual_tokens.js
View file @
218825a6
import
{
objectToQueryString
,
spriteIcon
}
from
'
~/lib/utils/common_utils
'
;
import
{
spriteIcon
}
from
'
~/lib/utils/common_utils
'
;
import
{
objectToQuery
}
from
'
~/lib/utils/url_utility
'
;
import
FilteredSearchContainer
from
'
./container
'
;
import
VisualTokenValue
from
'
./visual_token_value
'
;
...
...
@@ -327,7 +328,7 @@ export default class FilteredSearchVisualTokens {
return
endpoint
;
}
const
queryString
=
objectToQuery
String
(
JSON
.
parse
(
endpointQueryParams
));
const
queryString
=
objectToQuery
(
JSON
.
parse
(
endpointQueryParams
));
return
`
${
endpoint
}
?
${
queryString
}
`
;
}
...
...
app/assets/javascripts/lib/utils/common_utils.js
View file @
218825a6
...
...
@@ -371,17 +371,6 @@ export const parseIntPagination = (paginationInformation) => ({
previousPage
:
parseInt
(
paginationInformation
[
'
X-PREV-PAGE
'
],
10
),
});
/**
* 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
)
=>
{
if
(
param
)
return
`
${
window
.
location
.
pathname
}${
param
}
`
;
...
...
app/assets/javascripts/lib/utils/url_utility.js
View file @
218825a6
...
...
@@ -501,15 +501,15 @@ export function queryToObject(query, { gatherArrays = false, legacySpacesDecode
/**
* Convert search query object back into a search query
*
* @param {Object
} obj
that needs to be converted
* @param {Object
?} params
that needs to be converted
* @returns {String}
*
* ex: {one: 1, two: 2} into "one=1&two=2"
*
*/
export
function
objectToQuery
(
obj
)
{
return
Object
.
keys
(
obj
)
.
map
((
k
)
=>
`
${
encodeURIComponent
(
k
)}
=
${
encodeURIComponent
(
obj
[
k
])}
`
)
export
function
objectToQuery
(
params
=
{}
)
{
return
Object
.
keys
(
params
)
.
map
((
k
)
=>
`
${
encodeURIComponent
(
k
)}
=
${
encodeURIComponent
(
params
[
k
])}
`
)
.
join
(
'
&
'
);
}
...
...
app/assets/javascripts/packages/details/components/app.vue
View file @
218825a6
...
...
@@ -11,8 +11,8 @@ import {
GlSprintf
,
}
from
'
@gitlab/ui
'
;
import
{
mapActions
,
mapState
}
from
'
vuex
'
;
import
{
objectToQueryString
}
from
'
~/lib/utils/common_utils
'
;
import
{
numberToHumanSize
}
from
'
~/lib/utils/number_utils
'
;
import
{
objectToQuery
}
from
'
~/lib/utils/url_utility
'
;
import
{
s__
,
__
}
from
'
~/locale
'
;
import
Tracking
from
'
~/tracking
'
;
import
PackageListRow
from
'
../../shared/components/package_list_row.vue
'
;
...
...
@@ -114,7 +114,7 @@ export default {
!
this
.
groupListUrl
||
document
.
referrer
.
includes
(
this
.
projectName
)
?
this
.
projectListUrl
:
this
.
groupListUrl
;
// to avoid security issue url are supplied from backend
const
modalQuery
=
objectToQuery
String
({
[
SHOW_DELETE_SUCCESS_ALERT
]:
true
});
const
modalQuery
=
objectToQuery
({
[
SHOW_DELETE_SUCCESS_ALERT
]:
true
});
window
.
location
.
replace
(
`
${
returnTo
}
?
${
modalQuery
}
`
);
},
handleFileDelete
(
file
)
{
...
...
spec/frontend/lib/utils/common_utils_spec.js
View file @
218825a6
...
...
@@ -139,21 +139,6 @@ 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
'
,
()
=>
{
it
(
'
should build an url with current location and given parameters
'
,
()
=>
{
expect
(
commonUtils
.
buildUrlWithCurrentLocation
()).
toEqual
(
window
.
location
.
pathname
);
...
...
spec/frontend/lib/utils/url_utility_spec.js
View file @
218825a6
...
...
@@ -718,6 +718,19 @@ describe('URL utility', () => {
expect
(
urlUtils
.
objectToQuery
(
searchQueryObject
)).
toEqual
(
'
one=1&two=2
'
);
});
it
(
'
returns empty string when `params` is undefined, null or empty string
'
,
()
=>
{
expect
(
urlUtils
.
objectToQuery
()).
toBe
(
''
);
expect
(
urlUtils
.
objectToQuery
(
''
)).
toBe
(
''
);
});
it
(
'
returns query string with values of `params`
'
,
()
=>
{
const
singleQueryParams
=
{
foo
:
true
};
const
multipleQueryParams
=
{
foo
:
true
,
bar
:
true
};
expect
(
urlUtils
.
objectToQuery
(
singleQueryParams
)).
toBe
(
'
foo=true
'
);
expect
(
urlUtils
.
objectToQuery
(
multipleQueryParams
)).
toBe
(
'
foo=true&bar=true
'
);
});
});
describe
(
'
cleanLeadingSeparator
'
,
()
=>
{
...
...
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