BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cfbbdde3
Commit
cfbbdde3
authored
Apr 03, 2017
by
Fatih Acet
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '30264-fix-vue-pagination' into 'master'
Fixes method not replacing URL parameters correctly Closes #30264 See merge request !10351
parents
8a6104d0
670e1d74
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
10 deletions
+79
-10
common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+17
-10
30264-fix-vue-pagination.yml
changelogs/unreleased/30264-fix-vue-pagination.yml
+5
-0
environment_spec.js
spec/javascripts/environments/environment_spec.js
+4
-0
common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+49
-0
table_pagination_spec.js
...avascripts/vue_shared/components/table_pagination_spec.js
+4
-0
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
cfbbdde3
...
...
@@ -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 param for page is already present, we'll update it
...
...
@@ -278,17 +278,24 @@
let
search
;
const
locationSearch
=
window
.
location
.
search
;
if
(
locationSearch
.
length
===
0
)
{
search
=
`?
${
param
}
=
${
value
}
`
;
}
if
(
locationSearch
.
length
)
{
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
)
{
const
regex
=
new
RegExp
(
param
+
'=
\\
d'
);
search
=
locationSearch
.
replace
(
regex
,
`
${
param
}
=
${
value
}
`
);
}
parameters
[
param
]
=
value
;
if
(
locationSearch
.
length
&&
locationSearch
.
indexOf
(
param
)
===
-
1
)
{
search
=
`
${
locationSearch
}
&
${
param
}
=
${
value
}
`
;
const
toString
=
Object
.
keys
(
parameters
)
.
map
(
val
=>
`
${
val
}
=
${
encodeURIComponent
(
parameters
[
val
])}
`
)
.
join
(
'&'
);
search
=
`?
${
toString
}
`
;
}
else
{
search
=
`?
${
param
}
=
${
value
}
`
;
}
return
search
;
...
...
changelogs/unreleased/30264-fix-vue-pagination.yml
0 → 100644
View file @
cfbbdde3
---
title
:
Fixes method not replacing URL parameters correctly and breaking pipelines
pagination
merge_request
:
author
:
spec/javascripts/environments/environment_spec.js
View file @
cfbbdde3
...
...
@@ -91,6 +91,10 @@ describe('Environment', () => {
});
describe
(
'pagination'
,
()
=>
{
afterEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
''
);
});
it
(
'should render pagination'
,
(
done
)
=>
{
setTimeout
(()
=>
{
expect
(
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
cfbbdde3
...
...
@@ -46,6 +46,10 @@ require('~/lib/utils/common_utils');
spyOn
(
window
.
document
,
'getElementById'
).
and
.
callThrough
();
});
afterEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
''
);
});
function
expectGetElementIdToHaveBeenCalledWith
(
elementId
)
{
expect
(
window
.
document
.
getElementById
).
toHaveBeenCalledWith
(
elementId
);
}
...
...
@@ -75,11 +79,56 @@ require('~/lib/utils/common_utils');
});
});
describe
(
'gl.utils.setParamInURL'
,
()
=>
{
afterEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
''
);
});
it
(
'should return the parameter'
,
()
=>
{
window
.
history
.
replaceState
({},
null
,
''
);
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'
);
});
});
describe
(
'gl.utils.getParameterByName'
,
()
=>
{
beforeEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
'?scope=all&p=2'
);
});
afterEach
(()
=>
{
window
.
history
.
replaceState
({},
null
,
null
);
});
it
(
'should return valid parameter'
,
()
=>
{
const
value
=
gl
.
utils
.
getParameterByName
(
'scope'
);
expect
(
value
).
toBe
(
'all'
);
...
...
spec/javascripts/vue_shared/components/table_pagination_spec.js
View file @
cfbbdde3
...
...
@@ -124,6 +124,10 @@ describe('Pagination component', () => {
});
describe
(
'paramHelper'
,
()
=>
{
afterEach
(()
=>
{
window
.
history
.
pushState
({},
null
,
''
);
});
it
(
'can parse url parameters correctly'
,
()
=>
{
window
.
history
.
pushState
({},
null
,
'?scope=all&p=2'
);
...
...
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