From b3e314317911306cdbfbc8c3456f3212dc13b08d Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Wed, 18 Sep 2019 11:51:25 +0100 Subject: [PATCH 1/9] Refactor Security Dashboard store This refactoring is part of the [Instance Security Dashboard MVC][1], to abstract away from the base Security Dashboard the logic for how the list of projects to filter with is set. It: * Adds a new `GroupSecurityDashboard` component that wraps the `SecurityDashboard` component. * Moves the `projects` module bindings/calls from the `SecurityDashboard` component to the new `GroupSecurityDashboard`. * Creates a new `projects` plugin for the Security Dashboard store which dynamically adds the `projects` module and sets up the appropriate store bindings between it and the `filters` module. * Updates the entry point for the Group Security Dashboard to add the `projects` plugin to the Security Dashboard store. * Moves the existing `mediator` and `sync_with_store` plugins into a `plugins` directory. * Renames `moderator` to `mediator`. [1]: https://gitlab.com/gitlab-org/gitlab/issues/6953 --- .../security_dashboard/components/app.vue | 9 -- .../components/group_security_dashboard.vue | 59 +++++++++++++ .../javascripts/security_dashboard/index.js | 5 +- .../security_dashboard/store/index.js | 10 +-- .../{moderator.js => plugins/mediator.js} | 16 +--- .../store/plugins/projects.js | 22 +++++ .../store/{ => plugins}/sync_with_router.js | 2 +- .../security_dashboard/components/app_spec.js | 13 --- .../group_security_dashboard_spec.js | 84 +++++++++++++++++++ .../store/plugins/projects_spec.js | 37 ++++++++ .../mediator_spec.js} | 19 +---- 11 files changed, 212 insertions(+), 64 deletions(-) create mode 100644 ee/app/assets/javascripts/security_dashboard/components/group_security_dashboard.vue rename ee/app/assets/javascripts/security_dashboard/store/{moderator.js => plugins/mediator.js} (52%) create mode 100644 ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js rename ee/app/assets/javascripts/security_dashboard/store/{ => plugins}/sync_with_router.js (96%) create mode 100644 ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js create mode 100644 ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js rename ee/spec/javascripts/security_dashboard/store/{moderator_spec.js => plugins/mediator_spec.js} (81%) diff --git a/ee/app/assets/javascripts/security_dashboard/components/app.vue b/ee/app/assets/javascripts/security_dashboard/components/app.vue index 60d3d10f0e79a4..c2f23eb899dd4e 100644 --- a/ee/app/assets/javascripts/security_dashboard/components/app.vue +++ b/ee/app/assets/javascripts/security_dashboard/components/app.vue @@ -25,11 +25,6 @@ export default { type: String, required: true, }, - projectsEndpoint: { - type: String, - required: false, - default: null, - }, vulnerabilitiesEndpoint: { type: String, required: true, @@ -62,7 +57,6 @@ export default { }, computed: { ...mapState('vulnerabilities', ['modal', 'pageInfo']), - ...mapState('projects', ['projects']), ...mapGetters('filters', ['activeFilters']), canCreateIssue() { const path = this.vulnerability.create_vulnerability_feedback_issue_path; @@ -106,14 +100,12 @@ export default { if (this.showHideDismissedToggle) { this.setHideDismissedToggleInitialState(); } - this.setProjectsEndpoint(this.projectsEndpoint); this.setVulnerabilitiesEndpoint(this.vulnerabilitiesEndpoint); this.setVulnerabilitiesCountEndpoint(this.vulnerabilitiesCountEndpoint); this.setVulnerabilitiesHistoryEndpoint(this.vulnerabilitiesHistoryEndpoint); this.fetchVulnerabilities({ ...this.activeFilters, page: this.pageInfo.page }); this.fetchVulnerabilitiesCount(this.activeFilters); this.fetchVulnerabilitiesHistory(this.activeFilters); - this.fetchProjects(); }, methods: { ...mapActions('vulnerabilities', [ @@ -136,7 +128,6 @@ export default { 'undoDismiss', 'downloadPatch', ]), - ...mapActions('projects', ['setProjectsEndpoint', 'fetchProjects']), ...mapActions('filters', ['lockFilter', 'setHideDismissedToggleInitialState']), emitVulnerabilitiesCountChanged(count) { this.$emit('vulnerabilitiesCountChanged', count); diff --git a/ee/app/assets/javascripts/security_dashboard/components/group_security_dashboard.vue b/ee/app/assets/javascripts/security_dashboard/components/group_security_dashboard.vue new file mode 100644 index 00000000000000..b37d58bd7bf8e7 --- /dev/null +++ b/ee/app/assets/javascripts/security_dashboard/components/group_security_dashboard.vue @@ -0,0 +1,59 @@ + + + diff --git a/ee/app/assets/javascripts/security_dashboard/index.js b/ee/app/assets/javascripts/security_dashboard/index.js index c8f150d5b526fa..3e2a664c97d744 100644 --- a/ee/app/assets/javascripts/security_dashboard/index.js +++ b/ee/app/assets/javascripts/security_dashboard/index.js @@ -1,8 +1,9 @@ import Vue from 'vue'; -import GroupSecurityDashboardApp from './components/app.vue'; +import GroupSecurityDashboardApp from './components/group_security_dashboard.vue'; import UnavailableState from './components/unavailable_state.vue'; import createStore from './store'; import router from './store/router'; +import projectsPlugin from './store/plugins/projects'; export default function() { const el = document.getElementById('js-group-security-dashboard'); @@ -22,7 +23,7 @@ export default function() { }); } - const store = createStore(); + const store = createStore({ plugins: [projectsPlugin] }); return new Vue({ el, store, diff --git a/ee/app/assets/javascripts/security_dashboard/store/index.js b/ee/app/assets/javascripts/security_dashboard/store/index.js index 2d9e64e3a2e944..41f8125b50a9a0 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/index.js +++ b/ee/app/assets/javascripts/security_dashboard/store/index.js @@ -1,22 +1,20 @@ import Vue from 'vue'; import Vuex from 'vuex'; import router from './router'; -import configureModerator from './moderator'; -import syncWithRouter from './sync_with_router'; +import mediator from './plugins/mediator'; +import syncWithRouter from './plugins/sync_with_router'; import filters from './modules/filters/index'; -import projects from './modules/projects/index'; import vulnerabilities from './modules/vulnerabilities/index'; Vue.use(Vuex); -export default () => { +export default ({ plugins = [] } = {}) => { const store = new Vuex.Store({ modules: { filters, - projects, vulnerabilities, }, - plugins: [configureModerator, syncWithRouter(router)], + plugins: [mediator, syncWithRouter(router), ...plugins], }); store.$router = router; diff --git a/ee/app/assets/javascripts/security_dashboard/store/moderator.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js similarity index 52% rename from ee/app/assets/javascripts/security_dashboard/store/moderator.js rename to ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js index 0328a3907867df..f2c874dc978e21 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/moderator.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js @@ -1,22 +1,8 @@ -import * as filtersMutationTypes from './modules/filters/mutation_types'; -import * as projectsMutationTypes from './modules/projects/mutation_types'; -import { BASE_FILTERS } from './modules/filters/constants'; +import * as filtersMutationTypes from '../modules/filters/mutation_types'; export default function configureModerator(store) { store.subscribe(({ type, payload }) => { switch (type) { - case `projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`: - store.dispatch('filters/setFilterOptions', { - filterId: 'project_id', - options: [ - BASE_FILTERS.project_id, - ...payload.projects.map(project => ({ - name: project.name, - id: project.id.toString(), - })), - ], - }); - break; case `filters/${filtersMutationTypes.SET_ALL_FILTERS}`: case `filters/${filtersMutationTypes.SET_FILTER}`: case `filters/${filtersMutationTypes.SET_TOGGLE_VALUE}`: { diff --git a/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js new file mode 100644 index 00000000000000..a0b613f033bccf --- /dev/null +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js @@ -0,0 +1,22 @@ +import projects from '../modules/projects'; +import * as projectsMutationTypes from '../modules/projects/mutation_types'; +import { BASE_FILTERS } from '../modules/filters/constants'; + +export default store => { + store.registerModule('projects', projects); + + store.subscribe(({ type, payload }) => { + if (type === `projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`) { + store.dispatch('filters/setFilterOptions', { + filterId: 'project_id', + options: [ + BASE_FILTERS.project_id, + ...payload.projects.map(project => ({ + name: project.name, + id: project.id.toString(), + })), + ], + }); + } + }); +}; diff --git a/ee/app/assets/javascripts/security_dashboard/store/sync_with_router.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/sync_with_router.js similarity index 96% rename from ee/app/assets/javascripts/security_dashboard/store/sync_with_router.js rename to ee/app/assets/javascripts/security_dashboard/store/plugins/sync_with_router.js index db943fed712107..09bc3d003ab322 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/sync_with_router.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/sync_with_router.js @@ -1,7 +1,7 @@ import { SET_VULNERABILITIES_HISTORY_DAY_RANGE, RECEIVE_VULNERABILITIES_SUCCESS, -} from './modules/vulnerabilities/mutation_types'; +} from '../modules/vulnerabilities/mutation_types'; /** * Vuex store plugin to sync some Group Security Dashboard view settings with the URL. diff --git a/ee/spec/frontend/security_dashboard/components/app_spec.js b/ee/spec/frontend/security_dashboard/components/app_spec.js index 98d8e323496c18..c0870204d20369 100644 --- a/ee/spec/frontend/security_dashboard/components/app_spec.js +++ b/ee/spec/frontend/security_dashboard/components/app_spec.js @@ -15,7 +15,6 @@ import createStore from 'ee/security_dashboard/store'; const localVue = createLocalVue(); const pipelineId = 123; -const projectsEndpoint = `${TEST_HOST}/projects`; const vulnerabilitiesEndpoint = `${TEST_HOST}/vulnerabilities`; const vulnerabilitiesCountEndpoint = `${TEST_HOST}/vulnerabilities_summary`; const vulnerabilitiesHistoryEndpoint = `${TEST_HOST}/vulnerabilities_history`; @@ -27,14 +26,12 @@ jest.mock('~/lib/utils/url_utility', () => ({ describe('Security Dashboard app', () => { let wrapper; let mock; - let fetchProjectsSpy; let lockFilterSpy; let setPipelineIdSpy; let store; const setup = () => { mock = new MockAdapter(axios); - fetchProjectsSpy = jest.fn(); lockFilterSpy = jest.fn(); setPipelineIdSpy = jest.fn(); }; @@ -47,13 +44,11 @@ describe('Security Dashboard app', () => { sync: false, methods: { lockFilter: lockFilterSpy, - fetchProjects: fetchProjectsSpy, setPipelineId: setPipelineIdSpy, }, propsData: { dashboardDocumentation: '', emptyStateSvgPath: '', - projectsEndpoint, vulnerabilitiesEndpoint, vulnerabilitiesCountEndpoint, vulnerabilitiesHistoryEndpoint, @@ -95,10 +90,6 @@ describe('Security Dashboard app', () => { expect(wrapper.vm.isLockedToProject).toBe(false); }); - it('fetches projects', () => { - expect(fetchProjectsSpy).toHaveBeenCalled(); - }); - it('does not lock project filters', () => { expect(lockFilterSpy).not.toHaveBeenCalled(); }); @@ -139,10 +130,6 @@ describe('Security Dashboard app', () => { expect(wrapper.vm.isLockedToProject).toBe(true); }); - it('fetches projects', () => { - expect(fetchProjectsSpy).toHaveBeenCalled(); - }); - it('locks the filters to a given project', () => { expect(lockFilterSpy).toHaveBeenCalledWith({ filterId: 'project_id', diff --git a/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js new file mode 100644 index 00000000000000..a44b7f1fc91018 --- /dev/null +++ b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js @@ -0,0 +1,84 @@ +import Vuex from 'vuex'; +import { shallowMount, createLocalVue } from '@vue/test-utils'; +import GroupSecurityDashboard from 'ee/security_dashboard/components/group_security_dashboard.vue'; +import SecurityDashboard from 'ee/security_dashboard/components/app.vue'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +const dashboardDocumentation = '/help/docs'; +const emptyStateSvgPath = '/svgs/empty/svg'; +const projectsEndpoint = '/projects'; +const vulnerabilitiesEndpoint = '/vulnerabilities'; +const vulnerabilitiesCountEndpoint = '/vulnerabilities_summary'; +const vulnerabilitiesHistoryEndpoint = '/vulnerabilities_history'; +const vulnerabilityFeedbackHelpPath = '/vulnerabilities_feedback_help'; + +describe('Security Dashboard app', () => { + let store; + let wrapper; + let fetchProjectsSpy; + let setProjectsEndpointSpy; + + const factory = () => { + store = new Vuex.Store({ + modules: { + projects: { + namespaced: true, + actions: { + fetchProjects() {}, + setProjectsEndpoint() {}, + }, + }, + }, + }); + jest.spyOn(store, 'dispatch').mockImplementation(); + + wrapper = shallowMount(GroupSecurityDashboard, { + localVue, + store, + sync: false, + propsData: { + dashboardDocumentation, + emptyStateSvgPath, + projectsEndpoint, + vulnerabilitiesEndpoint, + vulnerabilitiesCountEndpoint, + vulnerabilitiesHistoryEndpoint, + vulnerabilityFeedbackHelpPath, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + describe('on creation', () => { + beforeEach(() => { + factory(); + }); + + it('dispatches the expected actions', () => { + expect(store.dispatch.mock.calls).toEqual([ + ['projects/setProjectsEndpoint', projectsEndpoint], + ['projects/fetchProjects', undefined], + ]); + }); + + it('renders the security dashboard', () => { + const dashboard = wrapper.find(SecurityDashboard); + expect(dashboard.exists()).toBe(true); + expect(dashboard.props()).toEqual( + expect.objectContaining({ + dashboardDocumentation, + emptyStateSvgPath, + vulnerabilitiesEndpoint, + vulnerabilitiesCountEndpoint, + vulnerabilitiesHistoryEndpoint, + vulnerabilityFeedbackHelpPath, + }), + ); + }); + }); +}); diff --git a/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js b/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js new file mode 100644 index 00000000000000..52358eeff96d2f --- /dev/null +++ b/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js @@ -0,0 +1,37 @@ +import Vuex from 'vuex'; +import createStore from 'ee/security_dashboard/store'; +import projectsModule from 'ee/security_dashboard/store/modules/projects'; +import projectsPlugin from 'ee/security_dashboard/store/plugins/projects'; +import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types'; +import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants'; + +describe('projects plugin', () => { + let store; + + beforeEach(() => { + jest.spyOn(Vuex.Store.prototype, 'registerModule'); + store = createStore({ plugins: [projectsPlugin] }); + }); + + it('registers the projects module on the store', () => { + expect(Vuex.Store.prototype.registerModule).toHaveBeenCalledTimes(1); + expect(Vuex.Store.prototype.registerModule).toHaveBeenCalledWith('projects', projectsModule); + }); + + it('sets project filter options after projects have been received', () => { + jest.spyOn(store, 'dispatch').mockImplementation(); + + store.commit(`projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`, { + projects: [{ name: 'foo', id: 1, otherProp: 'foobar' }], + }); + + expect(store.dispatch).toHaveBeenCalledTimes(1); + expect(store.dispatch).toHaveBeenCalledWith( + 'filters/setFilterOptions', + Object({ + filterId: 'project_id', + options: [BASE_FILTERS.project_id, { name: 'foo', id: '1' }], + }), + ); + }); +}); diff --git a/ee/spec/javascripts/security_dashboard/store/moderator_spec.js b/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js similarity index 81% rename from ee/spec/javascripts/security_dashboard/store/moderator_spec.js rename to ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js index 261a8bdd34e734..d83030b374e296 100644 --- a/ee/spec/javascripts/security_dashboard/store/moderator_spec.js +++ b/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js @@ -3,30 +3,13 @@ import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/proj import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filters/mutation_types'; import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants'; -describe('moderator', () => { +describe('mediator', () => { let store; beforeEach(() => { store = createStore(); }); - it('sets project filter options after projects have been received', () => { - spyOn(store, 'dispatch'); - - store.commit(`projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`, { - projects: [{ name: 'foo', id: 1, otherProp: 'foobar' }], - }); - - expect(store.dispatch).toHaveBeenCalledTimes(1); - expect(store.dispatch).toHaveBeenCalledWith( - 'filters/setFilterOptions', - Object({ - filterId: 'project_id', - options: [BASE_FILTERS.project_id, { name: 'foo', id: '1' }], - }), - ); - }); - it('triggers fetching vulnerabilities after one filter changes', () => { spyOn(store, 'dispatch'); -- GitLab From 05c1eb9bbe5b6144e8b6f8b1c566ae1c36b62444 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 14:38:09 +0100 Subject: [PATCH 2/9] Fix describe block description --- .../components/group_security_dashboard_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js index a44b7f1fc91018..afefa85a6e5f4d 100644 --- a/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js +++ b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js @@ -14,7 +14,7 @@ const vulnerabilitiesCountEndpoint = '/vulnerabilities_summary'; const vulnerabilitiesHistoryEndpoint = '/vulnerabilities_history'; const vulnerabilityFeedbackHelpPath = '/vulnerabilities_feedback_help'; -describe('Security Dashboard app', () => { +describe('Group Security Dashboard component', () => { let store; let wrapper; let fetchProjectsSpy; -- GitLab From 7eb76ccde8022fed31fefbb16b45c13e2dd1eb17 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 14:40:31 +0100 Subject: [PATCH 3/9] Fix eslint errors --- .../javascripts/security_dashboard/store/plugins/mediator.js | 2 +- .../components/group_security_dashboard_spec.js | 2 -- .../security_dashboard/store/plugins/mediator_spec.js | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js index f2c874dc978e21..ac80854a1fdf99 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js @@ -1,7 +1,7 @@ import * as filtersMutationTypes from '../modules/filters/mutation_types'; export default function configureModerator(store) { - store.subscribe(({ type, payload }) => { + store.subscribe(({ type }) => { switch (type) { case `filters/${filtersMutationTypes.SET_ALL_FILTERS}`: case `filters/${filtersMutationTypes.SET_FILTER}`: diff --git a/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js index afefa85a6e5f4d..a6f9dba9c40bbe 100644 --- a/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js +++ b/ee/spec/frontend/security_dashboard/components/group_security_dashboard_spec.js @@ -17,8 +17,6 @@ const vulnerabilityFeedbackHelpPath = '/vulnerabilities_feedback_help'; describe('Group Security Dashboard component', () => { let store; let wrapper; - let fetchProjectsSpy; - let setProjectsEndpointSpy; const factory = () => { store = new Vuex.Store({ diff --git a/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js b/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js index d83030b374e296..98ae5c21136480 100644 --- a/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js +++ b/ee/spec/javascripts/security_dashboard/store/plugins/mediator_spec.js @@ -1,7 +1,5 @@ import createStore from 'ee/security_dashboard/store/index'; -import * as projectsMutationTypes from 'ee/security_dashboard/store/modules/projects/mutation_types'; import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filters/mutation_types'; -import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants'; describe('mediator', () => { let store; -- GitLab From 3bd9a7f1021a1ba6834b6999f25dc5907a981def Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 14:47:18 +0100 Subject: [PATCH 4/9] Use consistent naming for default export --- .../javascripts/security_dashboard/store/plugins/projects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js index a0b613f033bccf..5892d630d41827 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js @@ -1,9 +1,9 @@ -import projects from '../modules/projects'; +import projectsModule from '../modules/projects'; import * as projectsMutationTypes from '../modules/projects/mutation_types'; import { BASE_FILTERS } from '../modules/filters/constants'; export default store => { - store.registerModule('projects', projects); + store.registerModule('projects', projectsModule); store.subscribe(({ type, payload }) => { if (type === `projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`) { -- GitLab From 41e76d5219cceaf45dda41c5a003614129f68815 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 14:56:43 +0100 Subject: [PATCH 5/9] Remove one more instance of 'moderator' --- .../javascripts/security_dashboard/store/plugins/mediator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js index ac80854a1fdf99..5871e351e5f55a 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/mediator.js @@ -1,6 +1,6 @@ import * as filtersMutationTypes from '../modules/filters/mutation_types'; -export default function configureModerator(store) { +export default store => { store.subscribe(({ type }) => { switch (type) { case `filters/${filtersMutationTypes.SET_ALL_FILTERS}`: @@ -15,4 +15,4 @@ export default function configureModerator(store) { default: } }); -} +}; -- GitLab From 7a063b0b8cf5ff3379cc92e6c9cde2208614bd95 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 14:57:16 +0100 Subject: [PATCH 6/9] Move sync_with_router_spec to plugins directory So that agrees with the path of the implementation. --- .../store/{ => plugins}/sync_with_router_spec.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ee/spec/frontend/security_dashboard/store/{ => plugins}/sync_with_router_spec.js (100%) diff --git a/ee/spec/frontend/security_dashboard/store/sync_with_router_spec.js b/ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js similarity index 100% rename from ee/spec/frontend/security_dashboard/store/sync_with_router_spec.js rename to ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js -- GitLab From bd599771fd2dfa21165244f85a563b91713f6858 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Thu, 19 Sep 2019 15:00:08 +0100 Subject: [PATCH 7/9] Remove one more instance of 'moderator' --- .../security_dashboard/store/plugins/sync_with_router_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js b/ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js index ed87c00ee49551..6395ca282659aa 100644 --- a/ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js +++ b/ee/spec/frontend/security_dashboard/store/plugins/sync_with_router_spec.js @@ -32,7 +32,7 @@ describe('syncWithRouter', () => { ); }); - it("doesn't update the store if the URL update originated from the moderator", () => { + it("doesn't update the store if the URL update originated from the mediator", () => { const query = { example: ['test'] }; jest.spyOn(store, 'commit').mockImplementation(noop); -- GitLab From 5d8364838cf8e691b45e2e23c0a4bf8ea9acf2d7 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Mon, 23 Sep 2019 16:39:28 +0100 Subject: [PATCH 8/9] Extract expected value constant --- .../security_dashboard/store/plugins/projects_spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js b/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js index 52358eeff96d2f..0467a35b56409c 100644 --- a/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js +++ b/ee/spec/frontend/security_dashboard/store/plugins/projects_spec.js @@ -20,9 +20,10 @@ describe('projects plugin', () => { it('sets project filter options after projects have been received', () => { jest.spyOn(store, 'dispatch').mockImplementation(); + const projectOption = { name: 'foo', id: '1' }; store.commit(`projects/${projectsMutationTypes.RECEIVE_PROJECTS_SUCCESS}`, { - projects: [{ name: 'foo', id: 1, otherProp: 'foobar' }], + projects: [{ ...projectOption, irrelevantProperty: 'foobar' }], }); expect(store.dispatch).toHaveBeenCalledTimes(1); @@ -30,7 +31,7 @@ describe('projects plugin', () => { 'filters/setFilterOptions', Object({ filterId: 'project_id', - options: [BASE_FILTERS.project_id, { name: 'foo', id: '1' }], + options: [BASE_FILTERS.project_id, projectOption], }), ); }); -- GitLab From 9397af758e6d0e6552d6283ed82c3bb7749fa250 Mon Sep 17 00:00:00 2001 From: Mark Florian Date: Mon, 23 Sep 2019 16:46:00 +0100 Subject: [PATCH 9/9] Destructure iteratee parameter --- .../security_dashboard/store/plugins/projects.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js index 5892d630d41827..ff3a2943974185 100644 --- a/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js +++ b/ee/app/assets/javascripts/security_dashboard/store/plugins/projects.js @@ -11,9 +11,9 @@ export default store => { filterId: 'project_id', options: [ BASE_FILTERS.project_id, - ...payload.projects.map(project => ({ - name: project.name, - id: project.id.toString(), + ...payload.projects.map(({ name, id }) => ({ + name, + id: id.toString(), })), ], }); -- GitLab