Commit 5d5cec6d authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '284471-rename-queries-and-error-message' into 'master'

Improve vulnerability project GraphQL queries and error message

See merge request gitlab-org/gitlab!58471
parents 32949cb9 602b3e44
...@@ -4,7 +4,7 @@ import GroupSecurityVulnerabilities from 'ee/security_dashboard/components/first ...@@ -4,7 +4,7 @@ import GroupSecurityVulnerabilities from 'ee/security_dashboard/components/first
import Filters from 'ee/security_dashboard/components/first_class_vulnerability_filters.vue'; import Filters from 'ee/security_dashboard/components/first_class_vulnerability_filters.vue';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import { vulnerabilitiesSeverityCountScopes } from '../constants'; import { vulnerabilitiesSeverityCountScopes } from '../constants';
import vulnerableProjectsQuery from '../graphql/queries/vulnerable_projects.query.graphql'; import groupProjectsQuery from '../graphql/queries/group_projects.query.graphql';
import CsvExportButton from './csv_export_button.vue'; import CsvExportButton from './csv_export_button.vue';
import DashboardNotConfigured from './empty_states/group_dashboard_not_configured.vue'; import DashboardNotConfigured from './empty_states/group_dashboard_not_configured.vue';
import VulnerabilitiesCountList from './vulnerability_count_list.vue'; import VulnerabilitiesCountList from './vulnerability_count_list.vue';
...@@ -22,7 +22,7 @@ export default { ...@@ -22,7 +22,7 @@ export default {
inject: ['groupFullPath'], inject: ['groupFullPath'],
apollo: { apollo: {
projects: { projects: {
query: vulnerableProjectsQuery, query: groupProjectsQuery,
variables() { variables() {
return { fullPath: this.groupFullPath }; return { fullPath: this.groupFullPath };
}, },
......
<script> <script>
import Filters from 'ee/security_dashboard/components/first_class_vulnerability_filters.vue'; import Filters from 'ee/security_dashboard/components/first_class_vulnerability_filters.vue';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import projectsQuery from 'ee/security_dashboard/graphql/queries/get_instance_security_dashboard_projects.query.graphql'; import instanceProjectsQuery from 'ee/security_dashboard/graphql/queries/instance_projects.query.graphql';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { vulnerabilitiesSeverityCountScopes } from '../constants'; import { vulnerabilitiesSeverityCountScopes } from '../constants';
import { createProjectLoadingError } from '../helpers'; import { PROJECT_LOADING_ERROR_MESSAGE } from '../helpers';
import CsvExportButton from './csv_export_button.vue'; import CsvExportButton from './csv_export_button.vue';
import DashboardNotConfigured from './empty_states/instance_dashboard_not_configured.vue'; import DashboardNotConfigured from './empty_states/instance_dashboard_not_configured.vue';
import InstanceSecurityVulnerabilities from './first_class_instance_security_dashboard_vulnerabilities.vue'; import InstanceSecurityVulnerabilities from './first_class_instance_security_dashboard_vulnerabilities.vue';
...@@ -21,12 +21,12 @@ export default { ...@@ -21,12 +21,12 @@ export default {
}, },
apollo: { apollo: {
projects: { projects: {
query: projectsQuery, query: instanceProjectsQuery,
update(data) { update(data) {
return data.instanceSecurityDashboard.projects.nodes; return data.instanceSecurityDashboard.projects.nodes;
}, },
error() { error() {
createFlash({ message: createProjectLoadingError() }); createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE });
}, },
}, },
}, },
......
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import projectsQuery from 'ee/security_dashboard/graphql/queries/get_instance_security_dashboard_projects.query.graphql'; import instanceProjectsQuery from 'ee/security_dashboard/graphql/queries/instance_projects.query.graphql';
import { createProjectLoadingError } from '../helpers'; import { PROJECT_LOADING_ERROR_MESSAGE } from '../helpers';
import ProjectManager from './first_class_project_manager/project_manager.vue'; import ProjectManager from './first_class_project_manager/project_manager.vue';
export default { export default {
...@@ -13,7 +13,7 @@ export default { ...@@ -13,7 +13,7 @@ export default {
}, },
apollo: { apollo: {
projects: { projects: {
query: projectsQuery, query: instanceProjectsQuery,
update(data) { update(data) {
return data.instanceSecurityDashboard.projects.nodes; return data.instanceSecurityDashboard.projects.nodes;
}, },
...@@ -28,18 +28,14 @@ export default { ...@@ -28,18 +28,14 @@ export default {
hasError: false, hasError: false,
}; };
}, },
computed: { PROJECT_LOADING_ERROR_MESSAGE,
errorMessage() {
return createProjectLoadingError();
},
},
}; };
</script> </script>
<template> <template>
<security-dashboard-layout> <security-dashboard-layout>
<gl-alert v-if="hasError" variant="danger"> <gl-alert v-if="hasError" variant="danger">
{{ errorMessage }} {{ $options.PROJECT_LOADING_ERROR_MESSAGE }}
</gl-alert> </gl-alert>
<div v-else class="gl-display-flex gl-justify-content-center"> <div v-else class="gl-display-flex gl-justify-content-center">
<project-manager :projects="projects" /> <project-manager :projects="projects" />
......
...@@ -3,8 +3,8 @@ import { GlButton } from '@gitlab/ui'; ...@@ -3,8 +3,8 @@ import { GlButton } from '@gitlab/ui';
import produce from 'immer'; import produce from 'immer';
import addProjectToSecurityDashboard from 'ee/security_dashboard/graphql/mutations/add_project_to_security_dashboard.mutation.graphql'; import addProjectToSecurityDashboard from 'ee/security_dashboard/graphql/mutations/add_project_to_security_dashboard.mutation.graphql';
import deleteProjectFromSecurityDashboard from 'ee/security_dashboard/graphql/mutations/delete_project_from_security_dashboard.mutation.graphql'; import deleteProjectFromSecurityDashboard from 'ee/security_dashboard/graphql/mutations/delete_project_from_security_dashboard.mutation.graphql';
import projectsQuery from 'ee/security_dashboard/graphql/queries/get_instance_security_dashboard_projects.query.graphql';
import getProjects from 'ee/security_dashboard/graphql/queries/get_projects.query.graphql'; import getProjects from 'ee/security_dashboard/graphql/queries/get_projects.query.graphql';
import instanceProjectsQuery from 'ee/security_dashboard/graphql/queries/instance_projects.query.graphql';
import { createInvalidProjectMessage } from 'ee/security_dashboard/utils/first_class_project_manager_utils'; import { createInvalidProjectMessage } from 'ee/security_dashboard/utils/first_class_project_manager_utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
...@@ -78,7 +78,7 @@ export default { ...@@ -78,7 +78,7 @@ export default {
return; return;
} }
const sourceData = store.readQuery({ query: projectsQuery }); const sourceData = store.readQuery({ query: instanceProjectsQuery });
const newProject = results.addProjectToSecurityDashboard.project; const newProject = results.addProjectToSecurityDashboard.project;
const data = produce(sourceData, (draftData) => { const data = produce(sourceData, (draftData) => {
...@@ -91,7 +91,7 @@ export default { ...@@ -91,7 +91,7 @@ export default {
]; ];
}); });
store.writeQuery({ query: projectsQuery, data }); store.writeQuery({ query: instanceProjectsQuery, data });
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
...@@ -155,7 +155,7 @@ export default { ...@@ -155,7 +155,7 @@ export default {
mutation: deleteProjectFromSecurityDashboard, mutation: deleteProjectFromSecurityDashboard,
variables: { id }, variables: { id },
update(store) { update(store) {
const sourceData = store.readQuery({ query: projectsQuery }); const sourceData = store.readQuery({ query: instanceProjectsQuery });
const data = produce(sourceData, (draftData) => { const data = produce(sourceData, (draftData) => {
draftData.instanceSecurityDashboard.projects.nodes = draftData.instanceSecurityDashboard.projects.nodes.filter( draftData.instanceSecurityDashboard.projects.nodes = draftData.instanceSecurityDashboard.projects.nodes.filter(
...@@ -163,7 +163,7 @@ export default { ...@@ -163,7 +163,7 @@ export default {
); );
}); });
store.writeQuery({ query: projectsQuery, data }); store.writeQuery({ query: instanceProjectsQuery, data });
}, },
}) })
.then(() => { .then(() => {
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import groupProjectsQuery from '../graphql/queries/group_projects.query.graphql';
import vulnerabilityGradesQuery from '../graphql/queries/group_vulnerability_grades.query.graphql'; import vulnerabilityGradesQuery from '../graphql/queries/group_vulnerability_grades.query.graphql';
import vulnerabilityHistoryQuery from '../graphql/queries/group_vulnerability_history.query.graphql'; import vulnerabilityHistoryQuery from '../graphql/queries/group_vulnerability_history.query.graphql';
import vulnerableProjectsQuery from '../graphql/queries/vulnerable_projects.query.graphql'; import { PROJECT_LOADING_ERROR_MESSAGE } from '../helpers';
import { createProjectLoadingError } from '../helpers';
import DashboardNotConfigured from './empty_states/group_dashboard_not_configured.vue'; import DashboardNotConfigured from './empty_states/group_dashboard_not_configured.vue';
import VulnerabilityChart from './first_class_vulnerability_chart.vue'; import VulnerabilityChart from './first_class_vulnerability_chart.vue';
import VulnerabilitySeverities from './first_class_vulnerability_severities.vue'; import VulnerabilitySeverities from './first_class_vulnerability_severities.vue';
...@@ -21,7 +21,7 @@ export default { ...@@ -21,7 +21,7 @@ export default {
inject: ['groupFullPath'], inject: ['groupFullPath'],
apollo: { apollo: {
projects: { projects: {
query: vulnerableProjectsQuery, query: groupProjectsQuery,
variables() { variables() {
return { fullPath: this.groupFullPath }; return { fullPath: this.groupFullPath };
}, },
...@@ -29,7 +29,7 @@ export default { ...@@ -29,7 +29,7 @@ export default {
return data?.group?.projects?.nodes ?? []; return data?.group?.projects?.nodes ?? [];
}, },
error() { error() {
createFlash({ message: createProjectLoadingError() }); createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE });
}, },
}, },
}, },
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import createFlash from '~/flash'; import createFlash from '~/flash';
import projectsQuery from '../graphql/queries/get_instance_security_dashboard_projects.query.graphql'; import instanceProjectsQuery from '../graphql/queries/instance_projects.query.graphql';
import vulnerabilityGradesQuery from '../graphql/queries/instance_vulnerability_grades.query.graphql'; import vulnerabilityGradesQuery from '../graphql/queries/instance_vulnerability_grades.query.graphql';
import vulnerabilityHistoryQuery from '../graphql/queries/instance_vulnerability_history.query.graphql'; import vulnerabilityHistoryQuery from '../graphql/queries/instance_vulnerability_history.query.graphql';
import { createProjectLoadingError } from '../helpers'; import { PROJECT_LOADING_ERROR_MESSAGE } from '../helpers';
import DashboardNotConfigured from './empty_states/instance_dashboard_not_configured.vue'; import DashboardNotConfigured from './empty_states/instance_dashboard_not_configured.vue';
import VulnerabilityChart from './first_class_vulnerability_chart.vue'; import VulnerabilityChart from './first_class_vulnerability_chart.vue';
import VulnerabilitySeverities from './first_class_vulnerability_severities.vue'; import VulnerabilitySeverities from './first_class_vulnerability_severities.vue';
...@@ -20,12 +20,12 @@ export default { ...@@ -20,12 +20,12 @@ export default {
}, },
apollo: { apollo: {
projects: { projects: {
query: projectsQuery, query: instanceProjectsQuery,
update(data) { update(data) {
return data?.instanceSecurityDashboard?.projects?.nodes ?? []; return data?.instanceSecurityDashboard?.projects?.nodes ?? [];
}, },
error() { error() {
createFlash({ message: createProjectLoadingError() }); createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE });
}, },
}, },
}, },
......
...@@ -6,7 +6,7 @@ import { formatDate, getDateInPast } from '~/lib/utils/datetime_utility'; ...@@ -6,7 +6,7 @@ import { formatDate, getDateInPast } from '~/lib/utils/datetime_utility';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils'; import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import projectsHistoryQuery from '../graphql/queries/project_vulnerabilities_by_day_and_count.query.graphql'; import projectsHistoryQuery from '../graphql/queries/project_vulnerabilities_by_day_and_count.query.graphql';
import { createProjectLoadingError } from '../helpers'; import { PROJECT_LOADING_ERROR_MESSAGE } from '../helpers';
import DashboardNotConfigured from './empty_states/reports_not_configured.vue'; import DashboardNotConfigured from './empty_states/reports_not_configured.vue';
import SecurityChartsLayout from './security_charts_layout.vue'; import SecurityChartsLayout from './security_charts_layout.vue';
...@@ -59,7 +59,7 @@ export default { ...@@ -59,7 +59,7 @@ export default {
return data?.project?.vulnerabilitiesCountByDay?.nodes ?? []; return data?.project?.vulnerabilitiesCountByDay?.nodes ?? [];
}, },
error() { error() {
createFlash({ message: createProjectLoadingError() }); createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE });
}, },
skip() { skip() {
return !this.hasVulnerabilities; return !this.hasVulnerabilities;
......
#import "ee/security_dashboard/graphql/fragments/project.fragment.graphql"
#import "ee/security_dashboard/graphql/fragments/project_vulnerability_severities_count.fragment.graphql"
query projectsQuery {
instanceSecurityDashboard {
projects {
nodes {
...Project
...ProjectVulnerabilitySeveritiesCount
}
}
}
}
#import "../fragments/project.fragment.graphql" query groupProjects($fullPath: ID!) {
query group($fullPath: ID!) {
group(fullPath: $fullPath) { group(fullPath: $fullPath) {
projects(includeSubgroups: true) { projects(includeSubgroups: true) {
nodes { nodes {
...Project id
name
} }
} }
} }
......
query instanceProjects {
instanceSecurityDashboard {
projects {
nodes {
id
name
nameWithNamespace
}
}
}
}
...@@ -134,6 +134,6 @@ export const preparePageInfo = (pageInfo) => { ...@@ -134,6 +134,6 @@ export const preparePageInfo = (pageInfo) => {
return { ...pageInfo, hasNextPage: Boolean(pageInfo?.endCursor) }; return { ...pageInfo, hasNextPage: Boolean(pageInfo?.endCursor) };
}; };
export const createProjectLoadingError = () => __('An error occurred while retrieving projects.'); export const PROJECT_LOADING_ERROR_MESSAGE = __('An error occurred while retrieving projects.');
export default () => ({}); export default () => ({});
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