Commit af6f4c80 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'issue_335942' into 'master'

Rename GraphQL query resource name from "instanceDashboard" to "instance"

See merge request gitlab-org/gitlab!67278
parents 38f04ab4 2dd31493
...@@ -22,7 +22,7 @@ export default { ...@@ -22,7 +22,7 @@ export default {
projects: { projects: {
query: instanceProjectsQuery, query: instanceProjectsQuery,
update(data) { update(data) {
return data?.instanceSecurityDashboard?.projects?.nodes ?? []; return data?.instance?.projects?.nodes ?? [];
}, },
error() { error() {
createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE }); createFlash({ message: PROJECT_LOADING_ERROR_MESSAGE });
......
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
projects: { projects: {
query: projectsQuery, query: projectsQuery,
update(data) { update(data) {
const projects = data?.instanceSecurityDashboard?.projects?.nodes; const projects = data?.instance?.projects?.nodes;
if (projects === undefined) { if (projects === undefined) {
this.showErrorFlash(); this.showErrorFlash();
......
...@@ -77,8 +77,8 @@ export default { ...@@ -77,8 +77,8 @@ export default {
const newProject = results.addProjectToSecurityDashboard.project; const newProject = results.addProjectToSecurityDashboard.project;
const data = produce(sourceData, (draftData) => { const data = produce(sourceData, (draftData) => {
draftData.instanceSecurityDashboard.projects.nodes = [ draftData.instance.projects.nodes = [
...draftData.instanceSecurityDashboard.projects.nodes, ...draftData.instance.projects.nodes,
{ {
...newProject, ...newProject,
vulnerabilitySeveritiesCount: newProject.vulnerabilitySeveritiesCount || null, vulnerabilitySeveritiesCount: newProject.vulnerabilitySeveritiesCount || null,
...@@ -153,7 +153,7 @@ export default { ...@@ -153,7 +153,7 @@ export default {
const sourceData = store.readQuery({ query: instanceProjectsQuery }); 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.instance.projects.nodes = draftData.instance.projects.nodes.filter(
(curr) => curr.id !== id, (curr) => curr.id !== id,
); );
}); });
......
...@@ -21,17 +21,6 @@ const SEARCH_TERM_MINIMUM_LENGTH = 3; ...@@ -21,17 +21,6 @@ const SEARCH_TERM_MINIMUM_LENGTH = 3;
const SELECTED_PROJECTS_MAX_COUNT = 100; const SELECTED_PROJECTS_MAX_COUNT = 100;
const PROJECT_ENTITY_NAME = 'Project'; const PROJECT_ENTITY_NAME = 'Project';
const QUERY_CONFIGS = {
[DASHBOARD_TYPES.GROUP]: {
query: groupProjectsQuery,
property: 'group',
},
[DASHBOARD_TYPES.INSTANCE]: {
query: instanceProjectsQuery,
property: 'instanceSecurityDashboard',
},
};
export default { export default {
components: { components: {
FilterBody, FilterBody,
...@@ -88,15 +77,17 @@ export default { ...@@ -88,15 +77,17 @@ export default {
const ids = this.querystringIds.includes(this.filter.allOption.id) ? [] : this.querystringIds; const ids = this.querystringIds.includes(this.filter.allOption.id) ? [] : this.querystringIds;
return ids.filter((id) => !has(this.projectsCache, id)); return ids.filter((id) => !has(this.projectsCache, id));
}, },
queryConfig() { query() {
return QUERY_CONFIGS[this.dashboardType]; return this.dashboardType === DASHBOARD_TYPES.GROUP
? groupProjectsQuery
: instanceProjectsQuery;
}, },
}, },
apollo: { apollo: {
// Gets the projects from the project IDs in the querystring and adds them to the cache. // Gets the projects from the project IDs in the querystring and adds them to the cache.
projectsById: { projectsById: {
query() { query() {
return this.queryConfig.query; return this.query;
}, },
manual: true, manual: true,
variables() { variables() {
...@@ -114,8 +105,7 @@ export default { ...@@ -114,8 +105,7 @@ export default {
this.$set(this.projectsCache, id, undefined); this.$set(this.projectsCache, id, undefined);
}); });
const property = data[this.queryConfig.property]; const projects = mapProjects(data[this.dashboardType].projects.nodes);
const projects = mapProjects(property.projects.nodes);
this.saveProjectsToCache(projects); this.saveProjectsToCache(projects);
// Now that we have the project for each uncached ID, set the selected options. // Now that we have the project for each uncached ID, set the selected options.
this.selectedOptions = this.querystringOptions; this.selectedOptions = this.querystringOptions;
...@@ -131,7 +121,7 @@ export default { ...@@ -131,7 +121,7 @@ export default {
// Gets the projects for the group with an optional search, to show as dropdown options. // Gets the projects for the group with an optional search, to show as dropdown options.
projects: { projects: {
query() { query() {
return this.queryConfig.query; return this.query;
}, },
variables() { variables() {
return { return {
...@@ -140,8 +130,7 @@ export default { ...@@ -140,8 +130,7 @@ export default {
}; };
}, },
update(data) { update(data) {
const property = data[this.queryConfig.property]; return mapProjects(data[this.dashboardType].projects.nodes);
return mapProjects(property.projects.nodes);
}, },
result() { result() {
this.saveProjectsToCache(this.projects); this.saveProjectsToCache(this.projects);
......
...@@ -53,25 +53,20 @@ export default { ...@@ -53,25 +53,20 @@ export default {
autoFixDocumentation: { default: undefined }, autoFixDocumentation: { default: undefined },
pipeline: { default: undefined }, pipeline: { default: undefined },
}, },
queries: {
[DASHBOARD_TYPES.GROUP]: groupProjectsQuery,
[DASHBOARD_TYPES.INSTANCE]: instanceProjectsQuery,
},
apollo: { apollo: {
projects: { projects: {
query() { query() {
return this.$options.queries[this.dashboardType]; return this.isGroup ? groupProjectsQuery : instanceProjectsQuery;
}, },
variables() { variables() {
return this.isGroup ? { fullPath: this.groupFullPath } : {}; return this.isGroup ? { fullPath: this.groupFullPath } : {};
}, },
update(data) { update(data) {
return this.isGroup return this.isGroup ? data.group.projects.nodes : data.instance.projects.nodes;
? data.group.projects.nodes
: data.instanceSecurityDashboard.projects.nodes;
}, },
skip() { skip() {
return !this.$options.queries[this.dashboardType]; // Only run this query on the group and instance-level dashboards.
return !(this.isGroup || this.isInstance);
}, },
}, },
}, },
......
query instanceProjects($search: String) { query instanceProjects($search: String) {
instanceSecurityDashboard { instance: instanceSecurityDashboard {
projects(search: $search) { projects(search: $search) {
nodes { nodes {
id id
......
...@@ -29,7 +29,7 @@ describe('Project List component', () => { ...@@ -29,7 +29,7 @@ describe('Project List component', () => {
const getMockData = (projects) => ({ const getMockData = (projects) => ({
data: { data: {
instanceSecurityDashboard: { instance: {
projects: { projects: {
nodes: projects, nodes: projects,
}, },
......
...@@ -196,7 +196,7 @@ export const mockProjectSecurityChartsWithData = () => ({ ...@@ -196,7 +196,7 @@ export const mockProjectSecurityChartsWithData = () => ({
export const mockVulnerableProjectsInstance = () => ({ export const mockVulnerableProjectsInstance = () => ({
data: { data: {
instanceSecurityDashboard: { instance: {
projects: { projects: {
nodes: [ nodes: [
{ {
......
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