Commit 2dd31493 authored by Siddharth Asthana's avatar Siddharth Asthana

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

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