diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-10-01 08:06:09 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-10-01 08:06:09 +0000 |
commit | 272e1482d6f96a9c139ddc6e3ab3e2d634184d4c (patch) | |
tree | 426915ed0202949e6f6301f9a987511ee7ded54c | |
parent | 2155ba8b402391d17426dae531d5d85f3f433d2a (diff) | |
parent | 17735dc876e7c7aa22a38caf2c42ee4dce645eca (diff) | |
download | gitlab-ce-272e1482d6f96a9c139ddc6e3ab3e2d634184d4c.tar.gz |
Merge branch 'ide-fetch-templates-pages' into 'master'
Fixed file templates not being fully fetched in Web IDE
Closes #51912
See merge request gitlab-org/gitlab-ce!21993
4 files changed, 60 insertions, 8 deletions
diff --git a/app/assets/javascripts/ide/stores/modules/file_templates/actions.js b/app/assets/javascripts/ide/stores/modules/file_templates/actions.js index dd53213ed18..cc9f6c8638c 100644 --- a/app/assets/javascripts/ide/stores/modules/file_templates/actions.js +++ b/app/assets/javascripts/ide/stores/modules/file_templates/actions.js @@ -1,5 +1,6 @@ import Api from '~/api'; import { __ } from '~/locale'; +import { normalizeHeaders } from '~/lib/utils/common_utils'; import * as types from './mutation_types'; import eventHub from '../../../eventhub'; @@ -22,13 +23,21 @@ export const receiveTemplateTypesError = ({ commit, dispatch }) => { export const receiveTemplateTypesSuccess = ({ commit }, templates) => commit(types.RECEIVE_TEMPLATE_TYPES_SUCCESS, templates); -export const fetchTemplateTypes = ({ dispatch, state }) => { +export const fetchTemplateTypes = ({ dispatch, state }, page = 1) => { if (!Object.keys(state.selectedTemplateType).length) return Promise.reject(); dispatch('requestTemplateTypes'); - return Api.templates(state.selectedTemplateType.key) - .then(({ data }) => dispatch('receiveTemplateTypesSuccess', data)) + return Api.templates(state.selectedTemplateType.key, { page }) + .then(({ data, headers }) => { + const nextPage = parseInt(normalizeHeaders(headers)['X-NEXT-PAGE'], 10); + + dispatch('receiveTemplateTypesSuccess', data); + + if (nextPage) { + dispatch('fetchTemplateTypes', nextPage); + } + }) .catch(() => dispatch('receiveTemplateTypesError')); }; diff --git a/app/assets/javascripts/ide/stores/modules/file_templates/mutations.js b/app/assets/javascripts/ide/stores/modules/file_templates/mutations.js index 674782a28ca..d519c033769 100644 --- a/app/assets/javascripts/ide/stores/modules/file_templates/mutations.js +++ b/app/assets/javascripts/ide/stores/modules/file_templates/mutations.js @@ -9,7 +9,7 @@ export default { }, [types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, templates) { state.isLoading = false; - state.templates = templates; + state.templates = state.templates.concat(templates); }, [types.SET_SELECTED_TEMPLATE_TYPE](state, type) { state.selectedTemplateType = type; diff --git a/changelogs/unreleased/ide-fetch-templates-pages.yml b/changelogs/unreleased/ide-fetch-templates-pages.yml new file mode 100644 index 00000000000..d4703e530f2 --- /dev/null +++ b/changelogs/unreleased/ide-fetch-templates-pages.yml @@ -0,0 +1,5 @@ +--- +title: Fixed file templates not fully being fetched in Web IDE +merge_request: +author: +type: fixed diff --git a/spec/javascripts/ide/stores/modules/file_templates/actions_spec.js b/spec/javascripts/ide/stores/modules/file_templates/actions_spec.js index c29dd9f0d06..734233100ab 100644 --- a/spec/javascripts/ide/stores/modules/file_templates/actions_spec.js +++ b/spec/javascripts/ide/stores/modules/file_templates/actions_spec.js @@ -69,11 +69,17 @@ describe('IDE file templates actions', () => { describe('fetchTemplateTypes', () => { describe('success', () => { + let nextPage; + beforeEach(() => { - mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(200, [ - { - name: 'MIT', - }, + mock.onGet(/api\/(.*)\/templates\/licenses/).replyOnce(() => [ + 200, + [ + { + name: 'MIT', + }, + ], + { 'X-NEXT-PAGE': nextPage }, ]); }); @@ -116,6 +122,38 @@ describe('IDE file templates actions', () => { done, ); }); + + it('dispatches actions for next page', done => { + nextPage = '2'; + state.selectedTemplateType = { + key: 'licenses', + }; + + testAction( + actions.fetchTemplateTypes, + null, + state, + [], + [ + { + type: 'requestTemplateTypes', + }, + { + type: 'receiveTemplateTypesSuccess', + payload: [ + { + name: 'MIT', + }, + ], + }, + { + type: 'fetchTemplateTypes', + payload: 2, + }, + ], + done, + ); + }); }); describe('error', () => { |