From ac808b755ab638ec639f62a37e9261f5ab98f773 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 12 Mar 2021 15:15:34 -0700 Subject: [PATCH 1/7] Move mutator actions to a special file just for mutators --- app/assets/javascripts/mr_notes/stores/actions.js | 8 +------- .../javascripts/mr_notes/stores/actions/mutators.js | 7 +++++++ app/assets/javascripts/mr_notes/stores/modules/index.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/mr_notes/stores/actions/mutators.js diff --git a/app/assets/javascripts/mr_notes/stores/actions.js b/app/assets/javascripts/mr_notes/stores/actions.js index 426c6a00d5e622..2fb894ca0c6f47 100644 --- a/app/assets/javascripts/mr_notes/stores/actions.js +++ b/app/assets/javascripts/mr_notes/stores/actions.js @@ -1,7 +1 @@ -import types from './mutation_types'; - -export default { - setActiveTab({ commit }, tab) { - commit(types.SET_ACTIVE_TAB, tab); - }, -}; +export * from './actions/mutators'; diff --git a/app/assets/javascripts/mr_notes/stores/actions/mutators.js b/app/assets/javascripts/mr_notes/stores/actions/mutators.js new file mode 100644 index 00000000000000..5d01c08863e4a2 --- /dev/null +++ b/app/assets/javascripts/mr_notes/stores/actions/mutators.js @@ -0,0 +1,7 @@ +import types from '../mutation_types'; + +// Actions that exclusively mutate the state (essentially wrappers for `commit`) + +export function setActiveTab({ commit }, tab) { + commit(types.SET_ACTIVE_TAB, tab); +} diff --git a/app/assets/javascripts/mr_notes/stores/modules/index.js b/app/assets/javascripts/mr_notes/stores/modules/index.js index c28e666943bfc0..ff0fbc16d10010 100644 --- a/app/assets/javascripts/mr_notes/stores/modules/index.js +++ b/app/assets/javascripts/mr_notes/stores/modules/index.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import * as actions from '../actions'; import getters from '../getters'; import mutations from '../mutations'; -- GitLab From 84c9a3d33cd2a2c10fe7429f391c53b79f096ed5 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 12 Mar 2021 17:16:46 -0700 Subject: [PATCH 2/7] Add a mutation that sets endpoints into the MR Notes state --- .../javascripts/mr_notes/stores/modules/index.js | 1 + .../mr_notes/stores/mutation_types.js | 1 + .../javascripts/mr_notes/stores/mutations.js | 3 +++ spec/frontend/mr_notes/stores/mutations_spec.js | 16 ++++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 spec/frontend/mr_notes/stores/mutations_spec.js diff --git a/app/assets/javascripts/mr_notes/stores/modules/index.js b/app/assets/javascripts/mr_notes/stores/modules/index.js index ff0fbc16d10010..6e228c62a72e59 100644 --- a/app/assets/javascripts/mr_notes/stores/modules/index.js +++ b/app/assets/javascripts/mr_notes/stores/modules/index.js @@ -4,6 +4,7 @@ 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 105104361cf35c..67fa63f882d68e 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 8175aa9488f1c8..3843103f4d01b7 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/spec/frontend/mr_notes/stores/mutations_spec.js b/spec/frontend/mr_notes/stores/mutations_spec.js new file mode 100644 index 00000000000000..3c5a83135e9a97 --- /dev/null +++ b/spec/frontend/mr_notes/stores/mutations_spec.js @@ -0,0 +1,16 @@ +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.endpointA).toBe('A'); + expect(state.endpoints.endpointB).toBe('B'); + }); + }); +}); -- GitLab From 433ae04f9404fc006911e9473d1287a370d9e819 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 12 Mar 2021 15:27:14 -0700 Subject: [PATCH 3/7] Add mutator action that ingests endpoints --- .../mr_notes/stores/actions/mutators.js | 4 +++ .../mr_notes/stores/actions/mutators_spec.js | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/frontend/mr_notes/stores/actions/mutators_spec.js diff --git a/app/assets/javascripts/mr_notes/stores/actions/mutators.js b/app/assets/javascripts/mr_notes/stores/actions/mutators.js index 5d01c08863e4a2..e099c2bdc67204 100644 --- a/app/assets/javascripts/mr_notes/stores/actions/mutators.js +++ b/app/assets/javascripts/mr_notes/stores/actions/mutators.js @@ -5,3 +5,7 @@ import types from '../mutation_types'; export function setActiveTab({ commit }, tab) { commit(types.SET_ACTIVE_TAB, tab); } + +export function setEndpoints({ commit }, endpoints) { + commit(types.SET_ENDPOINTS, endpoints); +} diff --git a/spec/frontend/mr_notes/stores/actions/mutators_spec.js b/spec/frontend/mr_notes/stores/actions/mutators_spec.js new file mode 100644 index 00000000000000..0271a337241c3f --- /dev/null +++ b/spec/frontend/mr_notes/stores/actions/mutators_spec.js @@ -0,0 +1,25 @@ +import testAction from 'helpers/vuex_action_helper'; +import { setEndpoints } from '~/mr_notes/stores/actions/mutators'; +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, + ); + }); + }); +}); -- GitLab From f43c5ef4dd13e020c91da909b7116203fadb4e12 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 12 Mar 2021 15:27:52 -0700 Subject: [PATCH 4/7] Bring the metadata endpoint into the MR Notes app --- app/assets/javascripts/mr_notes/init_notes.js | 6 +++++- app/views/projects/merge_requests/show.html.haml | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/mr_notes/init_notes.js b/app/assets/javascripts/mr_notes/init_notes.js index 9a93e90c2bb6f0..ff194d1a171610 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/views/projects/merge_requests/show.html.haml b/app/views/projects/merge_requests/show.html.haml index d664ee709dd9ef..cea0665ec8e1a9 100644 --- a/app/views/projects/merge_requests/show.html.haml +++ b/app/views/projects/merge_requests/show.html.haml @@ -63,6 +63,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', -- GitLab From 49a88f54426b96fac2fca15429a8770716b4ba3e Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 12 Mar 2021 15:28:16 -0700 Subject: [PATCH 5/7] Always preload the metadata for any MR page --- app/views/projects/merge_requests/show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/projects/merge_requests/show.html.haml b/app/views/projects/merge_requests/show.html.haml index cea0665ec8e1a9..2475a9b8afe73a 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" @@ -76,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) -- GitLab From 71d146f1cd865c778274b40750a65879cde4dc9a Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Mon, 15 Mar 2021 13:55:01 -0600 Subject: [PATCH 6/7] Revert back to single-file actions --- app/assets/javascripts/mr_notes/stores/actions.js | 10 +++++++++- .../javascripts/mr_notes/stores/actions/mutators.js | 11 ----------- .../{actions/mutators_spec.js => actions_spec.js} | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 app/assets/javascripts/mr_notes/stores/actions/mutators.js rename spec/frontend/mr_notes/stores/{actions/mutators_spec.js => actions_spec.js} (89%) diff --git a/app/assets/javascripts/mr_notes/stores/actions.js b/app/assets/javascripts/mr_notes/stores/actions.js index 2fb894ca0c6f47..d1874dcb214abc 100644 --- a/app/assets/javascripts/mr_notes/stores/actions.js +++ b/app/assets/javascripts/mr_notes/stores/actions.js @@ -1 +1,9 @@ -export * from './actions/mutators'; +import types from './mutation_types'; + +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/actions/mutators.js b/app/assets/javascripts/mr_notes/stores/actions/mutators.js deleted file mode 100644 index e099c2bdc67204..00000000000000 --- a/app/assets/javascripts/mr_notes/stores/actions/mutators.js +++ /dev/null @@ -1,11 +0,0 @@ -import types from '../mutation_types'; - -// Actions that exclusively mutate the state (essentially wrappers for `commit`) - -export function setActiveTab({ commit }, tab) { - commit(types.SET_ACTIVE_TAB, tab); -} - -export function setEndpoints({ commit }, endpoints) { - commit(types.SET_ENDPOINTS, endpoints); -} diff --git a/spec/frontend/mr_notes/stores/actions/mutators_spec.js b/spec/frontend/mr_notes/stores/actions_spec.js similarity index 89% rename from spec/frontend/mr_notes/stores/actions/mutators_spec.js rename to spec/frontend/mr_notes/stores/actions_spec.js index 0271a337241c3f..dbceedface1277 100644 --- a/spec/frontend/mr_notes/stores/actions/mutators_spec.js +++ b/spec/frontend/mr_notes/stores/actions_spec.js @@ -1,5 +1,5 @@ import testAction from 'helpers/vuex_action_helper'; -import { setEndpoints } from '~/mr_notes/stores/actions/mutators'; +import { setEndpoints } from '~/mr_notes/stores/actions'; import mutationTypes from '~/mr_notes/stores/mutation_types'; describe('MR Notes Mutator Actions', () => { -- GitLab From 0c3440b4461c670d6e86b266a87825c364ecac2f Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Wed, 17 Mar 2021 07:49:23 -0600 Subject: [PATCH 7/7] Test the entire object set into state as a single blob --- spec/frontend/mr_notes/stores/mutations_spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/frontend/mr_notes/stores/mutations_spec.js b/spec/frontend/mr_notes/stores/mutations_spec.js index 3c5a83135e9a97..422db3d5a3805e 100644 --- a/spec/frontend/mr_notes/stores/mutations_spec.js +++ b/spec/frontend/mr_notes/stores/mutations_spec.js @@ -9,8 +9,7 @@ describe('MR Notes Mutations', () => { mutations[mutationTypes.SET_ENDPOINTS](state, endpoints); - expect(state.endpoints.endpointA).toBe('A'); - expect(state.endpoints.endpointB).toBe('B'); + expect(state.endpoints).toEqual(endpoints); }); }); }); -- GitLab