diff --git a/app/assets/javascripts/mr_notes/init_notes.js b/app/assets/javascripts/mr_notes/init_notes.js index 9a93e90c2bb6f0e27dc3ba1c980fcfccba23a0da..ff194d1a171610864bccd64f988ea0c455d8088a 100644 --- a/app/assets/javascripts/mr_notes/init_notes.js +++ b/app/assets/javascripts/mr_notes/init_notes.js @@ -25,6 +25,9 @@ export default () => { return { noteableData, + endpoints: { + metadata: notesDataset.endpointMetadata, + }, currentUserData: JSON.parse(notesDataset.currentUserData), notesData: JSON.parse(notesDataset.notesData), helpPagePath: notesDataset.helpPagePath, @@ -54,6 +57,7 @@ export default () => { }, created() { this.setActiveTab(window.mrTabs.getCurrentAction()); + this.setEndpoints(this.endpoints); }, mounted() { this.notesCountBadge = $('.issuable-details').find('.notes-tab .badge'); @@ -65,7 +69,7 @@ export default () => { window.mrTabs.eventHub.$off('MergeRequestTabChange', this.setActiveTab); }, methods: { - ...mapActions(['setActiveTab']), + ...mapActions(['setActiveTab', 'setEndpoints']), updateDiscussionTabCounter() { this.notesCountBadge.text(this.discussionTabCounter); }, diff --git a/app/assets/javascripts/mr_notes/stores/actions.js b/app/assets/javascripts/mr_notes/stores/actions.js index 426c6a00d5e622fca683a511427b445f048186dd..d1874dcb214abc52b52779df5c7fdd145675a014 100644 --- a/app/assets/javascripts/mr_notes/stores/actions.js +++ b/app/assets/javascripts/mr_notes/stores/actions.js @@ -1,7 +1,9 @@ import types from './mutation_types'; -export default { - setActiveTab({ commit }, tab) { - commit(types.SET_ACTIVE_TAB, tab); - }, -}; +export function setActiveTab({ commit }, tab) { + commit(types.SET_ACTIVE_TAB, tab); +} + +export function setEndpoints({ commit }, endpoints) { + commit(types.SET_ENDPOINTS, endpoints); +} diff --git a/app/assets/javascripts/mr_notes/stores/modules/index.js b/app/assets/javascripts/mr_notes/stores/modules/index.js index c28e666943bfc0d77e356d859af2f102c0ce7fd9..6e228c62a72e59cd4fc1ac91394007cbf9ea21e5 100644 --- a/app/assets/javascripts/mr_notes/stores/modules/index.js +++ b/app/assets/javascripts/mr_notes/stores/modules/index.js @@ -1,9 +1,10 @@ -import actions from '../actions'; +import * as actions from '../actions'; import getters from '../getters'; import mutations from '../mutations'; export default () => ({ state: { + endpoints: {}, activeTab: null, }, actions, diff --git a/app/assets/javascripts/mr_notes/stores/mutation_types.js b/app/assets/javascripts/mr_notes/stores/mutation_types.js index 105104361cf35c345751cc02ce47dabfb508bcab..67fa63f882d68e97a3fdd3d969b1fa846e691308 100644 --- a/app/assets/javascripts/mr_notes/stores/mutation_types.js +++ b/app/assets/javascripts/mr_notes/stores/mutation_types.js @@ -1,3 +1,4 @@ export default { SET_ACTIVE_TAB: 'SET_ACTIVE_TAB', + SET_ENDPOINTS: 'SET_ENDPOINTS', }; diff --git a/app/assets/javascripts/mr_notes/stores/mutations.js b/app/assets/javascripts/mr_notes/stores/mutations.js index 8175aa9488f1c8a3ef8ab0a7c9d63d00ebb15a37..3843103f4d01b74bc67f738239795a37f9e758b9 100644 --- a/app/assets/javascripts/mr_notes/stores/mutations.js +++ b/app/assets/javascripts/mr_notes/stores/mutations.js @@ -4,4 +4,7 @@ export default { [types.SET_ACTIVE_TAB](state, tab) { Object.assign(state, { activeTab: tab }); }, + [types.SET_ENDPOINTS](state, endpoints) { + Object.assign(state, { endpoints }); + }, }; diff --git a/app/views/projects/merge_requests/show.html.haml b/app/views/projects/merge_requests/show.html.haml index d664ee709dd9ef899256570e61d133cff6a7dc5c..2475a9b8afe73ab27f315fc4b2d3335afebc64f5 100644 --- a/app/views/projects/merge_requests/show.html.haml +++ b/app/views/projects/merge_requests/show.html.haml @@ -13,6 +13,8 @@ - add_page_specific_style 'page_bundles/reports' - add_page_specific_style 'page_bundles/ci_status' +- add_page_startup_api_call @endpoint_metadata_url + .merge-request{ data: { mr_action: mr_action, url: merge_request_path(@merge_request, format: :json), project_path: project_path(@merge_request.project), lock_version: @merge_request.lock_version } } = render "projects/merge_requests/mr_title" @@ -63,6 +65,7 @@ - add_page_startup_api_call widget_project_json_merge_request_path(@project, @merge_request, format: :json) - add_page_startup_api_call cached_widget_project_json_merge_request_path(@project, @merge_request, format: :json) #js-vue-mr-discussions{ data: { notes_data: notes_data(@merge_request, Feature.enabled?(:paginated_notes, @project)).to_json, + endpoint_metadata: @endpoint_metadata_url, noteable_data: serialize_issuable(@merge_request, serializer: 'noteable'), noteable_type: 'MergeRequest', target_type: 'merge_request', @@ -75,8 +78,6 @@ = render "projects/merge_requests/tabs/pane", name: "pipelines", id: "pipelines", class: "pipelines" do - if number_of_pipelines.nonzero? = render 'projects/commit/pipelines_list', disable_initialization: true, endpoint: pipelines_project_merge_request_path(@project, @merge_request) - - if mr_action === "diffs" - - add_page_startup_api_call @endpoint_metadata_url - params = request.query_parameters - if Feature.enabled?(:default_merge_ref_for_diffs, @project, default_enabled: :yaml) - params = params.merge(diff_head: true) diff --git a/spec/frontend/mr_notes/stores/actions_spec.js b/spec/frontend/mr_notes/stores/actions_spec.js new file mode 100644 index 0000000000000000000000000000000000000000..dbceedface1277382d2d0d48ea09b39d5cb3324f --- /dev/null +++ b/spec/frontend/mr_notes/stores/actions_spec.js @@ -0,0 +1,25 @@ +import testAction from 'helpers/vuex_action_helper'; +import { setEndpoints } from '~/mr_notes/stores/actions'; +import mutationTypes from '~/mr_notes/stores/mutation_types'; + +describe('MR Notes Mutator Actions', () => { + describe('setEndpoints', () => { + it('should trigger the SET_ENDPOINTS state mutation', (done) => { + const endpoints = { endpointA: 'a' }; + + testAction( + setEndpoints, + endpoints, + {}, + [ + { + type: mutationTypes.SET_ENDPOINTS, + payload: endpoints, + }, + ], + [], + done, + ); + }); + }); +}); diff --git a/spec/frontend/mr_notes/stores/mutations_spec.js b/spec/frontend/mr_notes/stores/mutations_spec.js new file mode 100644 index 0000000000000000000000000000000000000000..422db3d5a3805eb4c4c8f28c495425afa1a49f32 --- /dev/null +++ b/spec/frontend/mr_notes/stores/mutations_spec.js @@ -0,0 +1,15 @@ +import mutationTypes from '~/mr_notes/stores/mutation_types'; +import mutations from '~/mr_notes/stores/mutations'; + +describe('MR Notes Mutations', () => { + describe(mutationTypes.SET_ENDPOINTS, () => { + it('should set the endpoints value', () => { + const state = {}; + const endpoints = { endpointA: 'A', endpointB: 'B' }; + + mutations[mutationTypes.SET_ENDPOINTS](state, endpoints); + + expect(state.endpoints).toEqual(endpoints); + }); + }); +});