Commit 2b299cf2 authored by Mark Florian's avatar Mark Florian

Merge branch '328232-use-context-instead-of-props' into 'master'

Use injection over prop injection

See merge request gitlab-org/gitlab!59964
parents 962a8a82 5711ad70
...@@ -8,13 +8,8 @@ export default { ...@@ -8,13 +8,8 @@ export default {
components: { components: {
VulnerabilityCountListLayout, VulnerabilityCountListLayout,
}, },
inject: ['dashboardType'], inject: ['dashboardType', 'groupFullPath', 'projectFullPath'],
props: { props: {
fullPath: {
type: String,
required: false,
default: '',
},
filters: { filters: {
type: Object, type: Object,
required: false, required: false,
...@@ -31,6 +26,9 @@ export default { ...@@ -31,6 +26,9 @@ export default {
isLoading() { isLoading() {
return this.$apollo.queries.vulnerabilitiesCount.loading; return this.$apollo.queries.vulnerabilitiesCount.loading;
}, },
fullPath() {
return this.groupFullPath || this.projectFullPath;
},
}, },
created() { created() {
eventHub.$on('vulnerabilities-updated', () => eventHub.$on('vulnerabilities-updated', () =>
......
...@@ -40,11 +40,9 @@ export default { ...@@ -40,11 +40,9 @@ export default {
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
inject: [ inject: [
'groupFullPath', 'groupFullPath',
'projectFullPath',
'dashboardType', 'dashboardType',
'dashboardDocumentation', 'dashboardDocumentation',
'autoFixDocumentation', 'autoFixDocumentation',
'projectFullPath',
'pipeline', 'pipeline',
], ],
queries: { queries: {
...@@ -85,9 +83,6 @@ export default { ...@@ -85,9 +83,6 @@ export default {
projectsWereFetched() { projectsWereFetched() {
return !this.$apollo.queries.projects?.loading; return !this.$apollo.queries.projects?.loading;
}, },
fullPath() {
return this.groupFullPath || this.projectFullPath;
},
isGroup() { isGroup() {
return this.dashboardType === DASHBOARD_TYPES.GROUP; return this.dashboardType === DASHBOARD_TYPES.GROUP;
}, },
...@@ -144,7 +139,7 @@ export default { ...@@ -144,7 +139,7 @@ export default {
<csv-export-button /> <csv-export-button />
</header> </header>
<project-pipeline-status v-if="isProject" class="gl-mb-6" :pipeline="pipeline" /> <project-pipeline-status v-if="isProject" class="gl-mb-6" :pipeline="pipeline" />
<vulnerabilities-count-list :full-path="fullPath" :filters="filters" /> <vulnerabilities-count-list :filters="filters" />
</template> </template>
<template #sticky> <template #sticky>
<filters :projects="projects" @filterChange="handleFilterChange" /> <filters :projects="projects" @filterChange="handleFilterChange" />
......
...@@ -21,7 +21,12 @@ describe('Vulnerabilities count list component', () => { ...@@ -21,7 +21,12 @@ describe('Vulnerabilities count list component', () => {
refetchSpy = jest.fn(); refetchSpy = jest.fn();
return shallowMount(VulnerabilityCountList, { return shallowMount(VulnerabilityCountList, {
provide: { dashboardType: DASHBOARD_TYPES.PROJECT, ...provide }, provide: {
dashboardType: DASHBOARD_TYPES.PROJECT,
projectFullPath: 'path-to-project',
groupFullPath: undefined,
...provide,
},
data: () => data, data: () => data,
mocks: { mocks: {
$apollo: { queries: { vulnerabilitiesCount: { ...query, refetch: refetchSpy } } }, $apollo: { queries: { vulnerabilitiesCount: { ...query, refetch: refetchSpy } } },
...@@ -33,7 +38,7 @@ describe('Vulnerabilities count list component', () => { ...@@ -33,7 +38,7 @@ describe('Vulnerabilities count list component', () => {
wrapper = shallowMount(VulnerabilityCountList, { wrapper = shallowMount(VulnerabilityCountList, {
localVue, localVue,
apolloProvider: createMockApollo([[countQuery, query]]), apolloProvider: createMockApollo([[countQuery, query]]),
provide, provide: { projectFullPath: undefined, groupFullPath: undefined, ...provide },
propsData, propsData,
stubs, stubs,
}); });
...@@ -87,21 +92,21 @@ describe('Vulnerabilities count list component', () => { ...@@ -87,21 +92,21 @@ describe('Vulnerabilities count list component', () => {
}); });
describe.each` describe.each`
dashboardType | fullPath | expectedContainedQueryVariables dashboardType | provide | expectedContainedQueryVariables
${DASHBOARD_TYPES.INSTANCE} | ${undefined} | ${{ isInstance: true, isGroup: false, isProject: false }} ${DASHBOARD_TYPES.INSTANCE} | ${undefined} | ${{ isInstance: true, isGroup: false, isProject: false }}
${DASHBOARD_TYPES.GROUP} | ${'group/path'} | ${{ isInstance: false, isGroup: true, isProject: false }} ${DASHBOARD_TYPES.GROUP} | ${{ groupFullPath: 'group/path' }} | ${{ isInstance: false, isGroup: true, isProject: false }}
${DASHBOARD_TYPES.PROJECT} | ${'project/path'} | ${{ isInstance: false, isGroup: false, isProject: true }} ${DASHBOARD_TYPES.PROJECT} | ${{ projectFullPath: 'project/path' }} | ${{ isInstance: false, isGroup: false, isProject: true }}
`( `(
'when the dashboard type is $dashboardType', 'when the dashboard type is $dashboardType',
({ dashboardType, fullPath, expectedContainedQueryVariables }) => { ({ dashboardType, provide, expectedContainedQueryVariables }) => {
beforeEach(() => { beforeEach(() => {
const mockResponse = jest const mockResponse = jest
.fn() .fn()
.mockResolvedValue(mockVulnerabilitySeveritiesGraphQLResponse({ dashboardType })); .mockResolvedValue(mockVulnerabilitySeveritiesGraphQLResponse({ dashboardType }));
createWrapperWithApollo({ createWrapperWithApollo({
provide: { dashboardType }, provide: { dashboardType, ...provide },
propsData: { fullPath, filters: { someFilter: 1 } }, propsData: { filters: { someFilter: 1 } },
query: mockResponse, query: mockResponse,
stubs: { VulnerabilityCountListLayout }, stubs: { VulnerabilityCountListLayout },
}); });
......
...@@ -165,7 +165,6 @@ describe('Vulnerability Report', () => { ...@@ -165,7 +165,6 @@ describe('Vulnerability Report', () => {
it('displays the vulnerability count list with the correct data', () => { it('displays the vulnerability count list with the correct data', () => {
expect(findVulnerabilitiesCountList().props()).toEqual({ expect(findVulnerabilitiesCountList().props()).toEqual({
fullPath: 'gitlab-org',
filters: wrapper.vm.filters, filters: wrapper.vm.filters,
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment