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
76b2fa3e
Commit
76b2fa3e
authored
Mar 30, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes method not replacing URL parameters correctly
parent
e7e93072
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
10 deletions
+57
-10
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+17
-10
changelogs/unreleased/30264-fix-vue-pagination.yml
changelogs/unreleased/30264-fix-vue-pagination.yml
+5
-0
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+35
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
76b2fa3e
...
@@ -263,7 +263,7 @@
...
@@ -263,7 +263,7 @@
});
});
/**
/**
* Updates the search parameter of a URL given the parameter and value
s
provided.
* Updates the search parameter of a URL given the parameter and value provided.
*
*
* If no search params are present we'll add it.
* If no search params are present we'll add it.
* If param for page is already present, we'll update it
* If param for page is already present, we'll update it
...
@@ -278,17 +278,24 @@
...
@@ -278,17 +278,24 @@
let
search
;
let
search
;
const
locationSearch
=
window
.
location
.
search
;
const
locationSearch
=
window
.
location
.
search
;
if
(
locationSearch
.
length
===
0
)
{
if
(
locationSearch
.
length
)
{
search
=
`?
${
param
}
=
${
value
}
`
;
const
parameters
=
locationSearch
.
substring
(
1
,
locationSearch
.
length
)
}
.
split
(
'
&
'
)
.
reduce
((
acc
,
element
)
=>
{
const
val
=
element
.
split
(
'
=
'
);
acc
[
val
[
0
]]
=
decodeURIComponent
(
val
[
1
]);
return
acc
;
},
{});
if
(
locationSearch
.
indexOf
(
param
)
!==
-
1
)
{
parameters
[
param
]
=
value
;
const
regex
=
new
RegExp
(
param
+
'
=
\\
d
'
);
search
=
locationSearch
.
replace
(
regex
,
`
${
param
}
=
${
value
}
`
);
}
if
(
locationSearch
.
length
&&
locationSearch
.
indexOf
(
param
)
===
-
1
)
{
const
toString
=
Object
.
keys
(
parameters
)
search
=
`
${
locationSearch
}
&
${
param
}
=
${
value
}
`
;
.
map
(
val
=>
`
${
val
}
=
${
encodeURIComponent
(
parameters
[
val
])}
`
)
.
join
(
'
&
'
);
search
=
`?
${
toString
}
`
;
}
else
{
search
=
`?
${
param
}
=
${
value
}
`
;
}
}
return
search
;
return
search
;
...
...
changelogs/unreleased/30264-fix-vue-pagination.yml
0 → 100644
View file @
76b2fa3e
---
title
:
Fixes method not replacing URL parameters correctly and breaking pipelines
pagination
merge_request
:
author
:
spec/javascripts/lib/utils/common_utils_spec.js
View file @
76b2fa3e
...
@@ -261,5 +261,40 @@ require('~/lib/utils/common_utils');
...
@@ -261,5 +261,40 @@ require('~/lib/utils/common_utils');
});
});
},
10000
);
},
10000
);
});
});
describe
(
'
gl.utils.setParamInURL
'
,
()
=>
{
it
(
'
should return the parameter
'
,
()
=>
{
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
156
)).
toBe
(
'
?page=156
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
'
156
'
)).
toBe
(
'
?page=156
'
);
});
it
(
'
should update the existing parameter when its a number
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?page=15
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
16
)).
toBe
(
'
?page=16
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
'
16
'
)).
toBe
(
'
?page=16
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
true
)).
toBe
(
'
?page=true
'
);
});
it
(
'
should update the existing parameter when its a string
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?scope=all
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
scope
'
,
'
finished
'
)).
toBe
(
'
?scope=finished
'
);
});
it
(
'
should update the existing parameter when more than one parameter exists
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?scope=all&page=15
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
scope
'
,
'
finished
'
)).
toBe
(
'
?scope=finished&page=15
'
);
});
it
(
'
should add a new parameter to the end of the existing ones
'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'
?scope=all
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
16
)).
toBe
(
'
?scope=all&page=16
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
'
16
'
)).
toBe
(
'
?scope=all&page=16
'
);
expect
(
gl
.
utils
.
setParamInURL
(
'
page
'
,
true
)).
toBe
(
'
?scope=all&page=true
'
);
});
});
});
});
})();
})();
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