Pass project path via provide/inject

Drop projectFullPath props instead of a provide/inject approach.
parent a6a80cd2
...@@ -9,7 +9,6 @@ import SecurityDashboardLayout from './security_dashboard_layout.vue'; ...@@ -9,7 +9,6 @@ import SecurityDashboardLayout from './security_dashboard_layout.vue';
import VulnerabilitiesCountList from './vulnerability_count_list.vue'; import VulnerabilitiesCountList from './vulnerability_count_list.vue';
import Filters from './first_class_vulnerability_filters.vue'; import Filters from './first_class_vulnerability_filters.vue';
import CsvExportButton from './csv_export_button.vue'; import CsvExportButton from './csv_export_button.vue';
import projectAutoFixMrsCountQuery from '../graphql/project_auto_fix_mrs_count.query.graphql';
export const BANNER_COOKIE_KEY = 'hide_vulnerabilities_introduction_banner'; export const BANNER_COOKIE_KEY = 'hide_vulnerabilities_introduction_banner';
...@@ -25,22 +24,6 @@ export default { ...@@ -25,22 +24,6 @@ export default {
Filters, Filters,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
apollo: {
autoFixMrsCount: {
query: projectAutoFixMrsCountQuery,
variables() {
return {
fullPath: this.projectFullPath,
};
},
update(data) {
return data?.project?.mergeRequests?.count || 0;
},
skip() {
return !this.glFeatures.securityAutoFix;
},
},
},
props: { props: {
securityDashboardHelpPath: { securityDashboardHelpPath: {
type: String, type: String,
...@@ -51,11 +34,6 @@ export default { ...@@ -51,11 +34,6 @@ export default {
required: false, required: false,
default: () => ({}), default: () => ({}),
}, },
projectFullPath: {
type: String,
required: false,
default: '',
},
hasVulnerabilities: { hasVulnerabilities: {
type: Boolean, type: Boolean,
required: false, required: false,
...@@ -102,15 +80,14 @@ export default { ...@@ -102,15 +80,14 @@ export default {
<h4 class="flex-grow mt-0 mb-0">{{ __('Vulnerabilities') }}</h4> <h4 class="flex-grow mt-0 mb-0">{{ __('Vulnerabilities') }}</h4>
<csv-export-button :vulnerabilities-export-endpoint="vulnerabilitiesExportEndpoint" /> <csv-export-button :vulnerabilities-export-endpoint="vulnerabilitiesExportEndpoint" />
</div> </div>
<project-pipeline-status :pipeline="pipeline" :auto-fix-mrs-count="autoFixMrsCount" /> <project-pipeline-status :pipeline="pipeline" />
<vulnerabilities-count-list :project-full-path="projectFullPath" :filters="filters" /> <vulnerabilities-count-list :filters="filters" />
</template> </template>
<template #sticky> <template #sticky>
<filters @filterChange="handleFilterChange" /> <filters @filterChange="handleFilterChange" />
</template> </template>
<project-vulnerabilities-app <project-vulnerabilities-app
:dashboard-documentation="dashboardDocumentation" :dashboard-documentation="dashboardDocumentation"
:project-full-path="projectFullPath"
:filters="filters" :filters="filters"
/> />
</security-dashboard-layout> </security-dashboard-layout>
......
...@@ -3,6 +3,7 @@ import { GlLink } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlLink } from '@gitlab/ui';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import PipelineStatusBadge from './pipeline_status_badge.vue'; import PipelineStatusBadge from './pipeline_status_badge.vue';
import projectAutoFixMrsCountQuery from '../graphql/project_auto_fix_mrs_count.query.graphql';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
export default { export default {
...@@ -12,15 +13,26 @@ export default { ...@@ -12,15 +13,26 @@ export default {
PipelineStatusBadge, PipelineStatusBadge,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
inject: ['autoFixMrsPath'], inject: ['projectFullPath', 'autoFixMrsPath'],
props: { apollo: {
pipeline: { type: Object, required: true },
autoFixMrsCount: { autoFixMrsCount: {
type: Number, query: projectAutoFixMrsCountQuery,
required: false, variables() {
default: 0, return {
fullPath: this.projectFullPath,
};
},
update(data) {
return data?.project?.mergeRequests?.count || 0;
},
skip() {
return !this.glFeatures.securityAutoFix;
},
}, },
}, },
props: {
pipeline: { type: Object, required: true },
},
computed: { computed: {
shouldShowPipelineStatus() { shouldShowPipelineStatus() {
return this.pipeline.createdAt && this.pipeline.id && this.pipeline.path; return this.pipeline.createdAt && this.pipeline.id && this.pipeline.path;
......
...@@ -16,11 +16,8 @@ export default { ...@@ -16,11 +16,8 @@ export default {
GlIntersectionObserver, GlIntersectionObserver,
VulnerabilityList, VulnerabilityList,
}, },
inject: ['projectFullPath'],
props: { props: {
projectFullPath: {
type: String,
required: true,
},
filters: { filters: {
type: Object, type: Object,
required: false, required: false,
......
...@@ -6,11 +6,8 @@ export default { ...@@ -6,11 +6,8 @@ export default {
components: { components: {
VulnerabilityCountListLayout, VulnerabilityCountListLayout,
}, },
inject: ['projectFullPath'],
props: { props: {
projectFullPath: {
type: String,
required: true,
},
filters: { filters: {
type: Object, type: Object,
required: false, required: false,
......
...@@ -55,7 +55,7 @@ export default (el, dashboardType) => { ...@@ -55,7 +55,7 @@ export default (el, dashboardType) => {
securityBuildsFailedCount: Number(securityBuildsFailedCount), securityBuildsFailedCount: Number(securityBuildsFailedCount),
securityBuildsFailedPath, securityBuildsFailedPath,
}; };
props.projectFullPath = el.dataset.projectFullPath; provide.projectFullPath = el.dataset.projectFullPath;
provide.autoFixDocumentation = el.dataset.autoFixDocumentation; provide.autoFixDocumentation = el.dataset.autoFixDocumentation;
provide.autoFixMrsPath = el.dataset.autoFixMrsPath; provide.autoFixMrsPath = el.dataset.autoFixMrsPath;
} else if (dashboardType === DASHBOARD_TYPES.GROUP) { } else if (dashboardType === DASHBOARD_TYPES.GROUP) {
......
...@@ -19,12 +19,12 @@ const props = { ...@@ -19,12 +19,12 @@ const props = {
id: '214', id: '214',
path: '/mixed-vulnerabilities/dependency-list-test-01/-/pipelines/214', path: '/mixed-vulnerabilities/dependency-list-test-01/-/pipelines/214',
}, },
projectFullPath: '/group/project',
securityDashboardHelpPath: '/security/dashboard/help-path', securityDashboardHelpPath: '/security/dashboard/help-path',
vulnerabilitiesExportEndpoint: '/vulnerabilities/exports', vulnerabilitiesExportEndpoint: '/vulnerabilities/exports',
}; };
const provide = { const provide = {
projectFullPath: '/group/project',
dashboardDocumentation: '/help/docs', dashboardDocumentation: '/help/docs',
autoFixDocumentation: '/auto/fix/documentation', autoFixDocumentation: '/auto/fix/documentation',
emptyStateSvgPath: '/svgs/empty/svg', emptyStateSvgPath: '/svgs/empty/svg',
...@@ -46,7 +46,7 @@ describe('First class Project Security Dashboard component', () => { ...@@ -46,7 +46,7 @@ describe('First class Project Security Dashboard component', () => {
const findCsvExportButton = () => wrapper.find(CsvExportButton); const findCsvExportButton = () => wrapper.find(CsvExportButton);
const findAutoFixUserCallout = () => wrapper.find(AutoFixUserCallout); const findAutoFixUserCallout = () => wrapper.find(AutoFixUserCallout);
const createComponent = (options, data = {}) => { const createComponent = options => {
wrapper = shallowMount(FirstClassProjectSecurityDashboard, { wrapper = shallowMount(FirstClassProjectSecurityDashboard, {
propsData: { propsData: {
...props, ...props,
...@@ -54,12 +54,6 @@ describe('First class Project Security Dashboard component', () => { ...@@ -54,12 +54,6 @@ describe('First class Project Security Dashboard component', () => {
}, },
provide, provide,
stubs: { SecurityDashboardLayout, GlBanner }, stubs: { SecurityDashboardLayout, GlBanner },
data() {
return {
autoFixMrsCount: 0,
...data,
};
},
...options, ...options,
}); });
}; };
...@@ -71,12 +65,10 @@ describe('First class Project Security Dashboard component', () => { ...@@ -71,12 +65,10 @@ describe('First class Project Security Dashboard component', () => {
describe('on render when there are vulnerabilities', () => { describe('on render when there are vulnerabilities', () => {
beforeEach(() => { beforeEach(() => {
createComponent( createComponent({
{ props: { hasVulnerabilities: true },
props: { hasVulnerabilities: true }, data: () => ({ filters }),
}, });
{ filters },
);
}); });
it('should render the vulnerabilities', () => { it('should render the vulnerabilities', () => {
...@@ -173,14 +165,14 @@ describe('First class Project Security Dashboard component', () => { ...@@ -173,14 +165,14 @@ describe('First class Project Security Dashboard component', () => {
describe('with filter data', () => { describe('with filter data', () => {
beforeEach(() => { beforeEach(() => {
createComponent( createComponent({
{ props: {
props: { hasVulnerabilities: true,
hasVulnerabilities: true,
},
}, },
{ filters }, data() {
); return { filters };
},
});
}); });
it('should pass the filter data down to the vulnerabilities', () => { it('should pass the filter data down to the vulnerabilities', () => {
......
...@@ -31,9 +31,13 @@ describe('Project Pipeline Status Component', () => { ...@@ -31,9 +31,13 @@ describe('Project Pipeline Status Component', () => {
{ {
propsData: DEFAULT_PROPS, propsData: DEFAULT_PROPS,
provide: { provide: {
projectFullPath: '/group/project',
glFeatures: { securityAutoFix: true }, glFeatures: { securityAutoFix: true },
autoFixMrsPath: '/merge_requests?label_name=GitLab-auto-fix', autoFixMrsPath: '/merge_requests?label_name=GitLab-auto-fix',
}, },
data() {
return { autoFixMrsCount: 0 };
},
}, },
options, options,
), ),
...@@ -85,8 +89,8 @@ describe('Project Pipeline Status Component', () => { ...@@ -85,8 +89,8 @@ describe('Project Pipeline Status Component', () => {
describe('when there are auto-fix MRs', () => { describe('when there are auto-fix MRs', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createWrapper({ wrapper = createWrapper({
propsData: { data() {
autoFixMrsCount: 12, return { autoFixMrsCount: 12 };
}, },
}); });
}); });
...@@ -103,11 +107,7 @@ describe('Project Pipeline Status Component', () => { ...@@ -103,11 +107,7 @@ describe('Project Pipeline Status Component', () => {
}); });
it('does not render the link if there are no open auto-fix MRs', () => { it('does not render the link if there are no open auto-fix MRs', () => {
wrapper = createWrapper({ wrapper = createWrapper();
propsData: {
autoFixMrsCount: 0,
},
});
expect(findAutoFixMrsLink().exists()).toBe(false); expect(findAutoFixMrsLink().exists()).toBe(false);
}); });
......
...@@ -12,10 +12,12 @@ describe('Vulnerabilities app component', () => { ...@@ -12,10 +12,12 @@ describe('Vulnerabilities app component', () => {
const createWrapper = ({ props = {}, $apollo = apolloMock } = {}, options = {}) => { const createWrapper = ({ props = {}, $apollo = apolloMock } = {}, options = {}) => {
wrapper = shallowMount(ProjectVulnerabilitiesApp, { wrapper = shallowMount(ProjectVulnerabilitiesApp, {
provide: {
projectFullPath: '#',
},
propsData: { propsData: {
dashboardDocumentation: '#', dashboardDocumentation: '#',
emptyStateSvgPath: '#', emptyStateSvgPath: '#',
projectFullPath: '#',
...props, ...props,
}, },
mocks: { mocks: {
......
...@@ -9,7 +9,7 @@ describe('Vulnerabilities count list component', () => { ...@@ -9,7 +9,7 @@ describe('Vulnerabilities count list component', () => {
const createWrapper = ({ query } = {}) => { const createWrapper = ({ query } = {}) => {
return shallowMount(VulnerabilityCountList, { return shallowMount(VulnerabilityCountList, {
propsData: { provide: {
projectFullPath: '/root/security-project', projectFullPath: '/root/security-project',
}, },
mocks: { mocks: {
......
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