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
7289e143
Commit
7289e143
authored
Apr 23, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
860265ab
f34582fe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
64 deletions
+64
-64
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
.../javascripts/ide/stores/modules/file_templates/actions.js
+15
-10
app/assets/javascripts/ide/stores/modules/file_templates/mutations.js
...avascripts/ide/stores/modules/file_templates/mutations.js
+2
-1
changelogs/unreleased/58252-web-ide-dropdown-duplicates.yml
changelogs/unreleased/58252-web-ide-dropdown-duplicates.yml
+5
-0
spec/frontend/ide/stores/modules/file_templates/mutations_spec.js
...ntend/ide/stores/modules/file_templates/mutations_spec.js
+30
-11
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
...scripts/ide/stores/modules/file_templates/actions_spec.js
+12
-42
No files found.
app/assets/javascripts/ide/stores/modules/file_templates/actions.js
View file @
7289e143
...
...
@@ -23,22 +23,27 @@ export const receiveTemplateTypesError = ({ commit, dispatch }) => {
export
const
receiveTemplateTypesSuccess
=
({
commit
},
templates
)
=>
commit
(
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
,
templates
);
export
const
fetchTemplateTypes
=
({
dispatch
,
state
,
rootState
}
,
page
=
1
)
=>
{
export
const
fetchTemplateTypes
=
({
dispatch
,
state
,
rootState
})
=>
{
if
(
!
Object
.
keys
(
state
.
selectedTemplateType
).
length
)
return
Promise
.
reject
();
dispatch
(
'
requestTemplateTypes
'
);
return
Api
.
projectTemplates
(
rootState
.
currentProjectId
,
state
.
selectedTemplateType
.
key
,
{
page
})
.
then
(({
data
,
headers
})
=>
{
const
nextPage
=
parseInt
(
normalizeHeaders
(
headers
)[
'
X-NEXT-PAGE
'
],
10
);
const
fetchPages
=
(
page
=
1
,
prev
=
[])
=>
Api
.
projectTemplates
(
rootState
.
currentProjectId
,
state
.
selectedTemplateType
.
key
,
{
page
,
per_page
:
100
,
})
.
then
(({
data
,
headers
})
=>
{
const
nextPage
=
parseInt
(
normalizeHeaders
(
headers
)[
'
X-NEXT-PAGE
'
],
10
);
const
nextData
=
prev
.
concat
(
data
);
dispatch
(
'
receiveTemplateTypesSuccess
'
,
d
ata
);
dispatch
(
'
receiveTemplateTypesSuccess
'
,
nextD
ata
);
if
(
nextPage
)
{
dispatch
(
'
fetchTemplateTypes
'
,
nextPage
);
}
})
.
catch
(()
=>
dispatch
(
'
receiveTemplateTypesError
'
)
);
return
nextPage
?
fetchPages
(
nextPage
,
nextData
)
:
nextData
;
})
.
catch
(()
=>
dispatch
(
'
receiveTemplateTypesError
'
));
return
fetchPages
(
);
};
export
const
setSelectedTemplateType
=
({
commit
,
dispatch
,
rootGetters
},
type
)
=>
{
...
...
app/assets/javascripts/ide/stores/modules/file_templates/mutations.js
View file @
7289e143
...
...
@@ -3,13 +3,14 @@ import * as types from './mutation_types';
export
default
{
[
types
.
REQUEST_TEMPLATE_TYPES
](
state
)
{
state
.
isLoading
=
true
;
state
.
templates
=
[];
},
[
types
.
RECEIVE_TEMPLATE_TYPES_ERROR
](
state
)
{
state
.
isLoading
=
false
;
},
[
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
](
state
,
templates
)
{
state
.
isLoading
=
false
;
state
.
templates
=
state
.
templates
.
concat
(
templates
)
;
state
.
templates
=
templates
;
},
[
types
.
SET_SELECTED_TEMPLATE_TYPE
](
state
,
type
)
{
state
.
selectedTemplateType
=
type
;
...
...
changelogs/unreleased/58252-web-ide-dropdown-duplicates.yml
0 → 100644
View file @
7289e143
---
title
:
Resolve Web IDE template dropdown showing duplicates
merge_request
:
27237
author
:
type
:
fixed
spec/frontend/ide/stores/modules/file_templates/mutations_spec.js
View file @
7289e143
...
...
@@ -2,6 +2,9 @@ import createState from '~/ide/stores/modules/file_templates/state';
import
*
as
types
from
'
~/ide/stores/modules/file_templates/mutation_types
'
;
import
mutations
from
'
~/ide/stores/modules/file_templates/mutations
'
;
const
mockFileTemplates
=
[[
'
MIT
'
],
[
'
CC
'
]];
const
mockTemplateType
=
'
test
'
;
describe
(
'
IDE file templates mutations
'
,
()
=>
{
let
state
;
...
...
@@ -10,11 +13,21 @@ describe('IDE file templates mutations', () => {
});
describe
(
`
${
types
.
REQUEST_TEMPLATE_TYPES
}
`
,
()
=>
{
it
(
'
sets isLoading
'
,
()
=>
{
it
(
'
sets loading to true
'
,
()
=>
{
state
.
isLoading
=
false
;
mutations
[
types
.
REQUEST_TEMPLATE_TYPES
](
state
);
expect
(
state
.
isLoading
).
toBe
(
true
);
});
it
(
'
sets templates to an empty array
'
,
()
=>
{
state
.
templates
=
mockFileTemplates
;
mutations
[
types
.
REQUEST_TEMPLATE_TYPES
](
state
);
expect
(
state
.
templates
).
toEqual
([]);
});
});
describe
(
`
${
types
.
RECEIVE_TEMPLATE_TYPES_ERROR
}
`
,
()
=>
{
...
...
@@ -31,29 +44,33 @@ describe('IDE file templates mutations', () => {
it
(
'
sets isLoading to false
'
,
()
=>
{
state
.
isLoading
=
true
;
mutations
[
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
](
state
,
[]
);
mutations
[
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
](
state
,
mockFileTemplates
);
expect
(
state
.
isLoading
).
toBe
(
false
);
});
it
(
'
sets templates
'
,
()
=>
{
mutations
[
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
](
state
,
[
'
test
'
]);
it
(
'
sets templates to payload
'
,
()
=>
{
state
.
templates
=
[
'
test
'
];
mutations
[
types
.
RECEIVE_TEMPLATE_TYPES_SUCCESS
](
state
,
mockFileTemplates
);
expect
(
state
.
templates
).
toEqual
(
[
'
test
'
]
);
expect
(
state
.
templates
).
toEqual
(
mockFileTemplates
);
});
});
describe
(
`
${
types
.
SET_SELECTED_TEMPLATE_TYPE
}
`
,
()
=>
{
it
(
'
sets
selectedTemplateT
ype
'
,
()
=>
{
mutations
[
types
.
SET_SELECTED_TEMPLATE_TYPE
](
state
,
'
type
'
)
;
it
(
'
sets
templates type to selected t
ype
'
,
()
=>
{
state
.
selectedTemplateType
=
''
;
expect
(
state
.
selectedTemplateType
).
toBe
(
'
type
'
);
mutations
[
types
.
SET_SELECTED_TEMPLATE_TYPE
](
state
,
mockTemplateType
);
expect
(
state
.
selectedTemplateType
).
toBe
(
mockTemplateType
);
});
it
(
'
clears templates
'
,
()
=>
{
state
.
templates
=
[
'
test
'
]
;
it
(
'
sets templates to empty array
'
,
()
=>
{
state
.
templates
=
mockFileTemplates
;
mutations
[
types
.
SET_SELECTED_TEMPLATE_TYPE
](
state
,
'
type
'
);
mutations
[
types
.
SET_SELECTED_TEMPLATE_TYPE
](
state
,
mockTemplateType
);
expect
(
state
.
templates
).
toEqual
([]);
});
...
...
@@ -61,6 +78,8 @@ describe('IDE file templates mutations', () => {
describe
(
`
${
types
.
SET_UPDATE_SUCCESS
}
`
,
()
=>
{
it
(
'
sets updateSuccess
'
,
()
=>
{
state
.
updateSuccess
=
false
;
mutations
[
types
.
SET_UPDATE_SUCCESS
](
state
,
true
);
expect
(
state
.
updateSuccess
).
toBe
(
true
);
...
...
spec/javascripts/ide/stores/modules/file_templates/actions_spec.js
View file @
7289e143
...
...
@@ -69,18 +69,16 @@ describe('IDE file templates actions', () => {
describe
(
'
fetchTemplateTypes
'
,
()
=>
{
describe
(
'
success
'
,
()
=>
{
let
nextPage
;
const
pages
=
[[{
name
:
'
MIT
'
}],
[{
name
:
'
Apache
'
}],
[{
name
:
'
CC
'
}]]
;
beforeEach
(()
=>
{
mock
.
onGet
(
/api
\/(
.*
)\/
templates
\/
licenses/
).
replyOnce
(()
=>
[
200
,
[
{
name
:
'
MIT
'
,
},
],
{
'
X-NEXT-PAGE
'
:
nextPage
},
]);
mock
.
onGet
(
/api
\/(
.*
)\/
templates
\/
licenses/
).
reply
(({
params
})
=>
{
const
pageNum
=
params
.
page
;
const
page
=
pages
[
pageNum
-
1
];
const
hasNextPage
=
pageNum
<
pages
.
length
;
return
[
200
,
page
,
hasNextPage
?
{
'
X-NEXT-PAGE
'
:
pageNum
+
1
}
:
{}];
});
});
it
(
'
rejects if selectedTemplateType is empty
'
,
done
=>
{
...
...
@@ -112,43 +110,15 @@ describe('IDE file templates actions', () => {
},
{
type
:
'
receiveTemplateTypesSuccess
'
,
payload
:
[
{
name
:
'
MIT
'
,
},
],
},
],
done
,
);
});
it
(
'
dispatches actions for next page
'
,
done
=>
{
nextPage
=
'
2
'
;
state
.
selectedTemplateType
=
{
key
:
'
licenses
'
,
};
testAction
(
actions
.
fetchTemplateTypes
,
null
,
state
,
[],
[
{
type
:
'
requestTemplateTypes
'
,
payload
:
pages
[
0
],
},
{
type
:
'
receiveTemplateTypesSuccess
'
,
payload
:
[
{
name
:
'
MIT
'
,
},
],
payload
:
pages
[
0
].
concat
(
pages
[
1
]),
},
{
type
:
'
fetchTemplateType
s
'
,
payload
:
2
,
type
:
'
receiveTemplateTypesSucces
s
'
,
payload
:
pages
[
0
].
concat
(
pages
[
1
]).
concat
(
pages
[
2
])
,
},
],
done
,
...
...
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