Commit 461b9f5e authored by Scott Hampton's avatar Scott Hampton

Update group coverage query

Update the group test coverage query to
get the projects from a group so that we can
more easily fetch all projects.
parent de3c64af
......@@ -22,23 +22,29 @@ export default {
TimeAgoTooltip,
},
mixins: [glFeatureFlagsMixin()],
inject: {
groupFullPath: {
default: '',
},
},
apollo: {
projects: {
query: getProjectsTestCoverage,
debounce: 500,
variables() {
return {
groupFullPath: this.groupFullPath,
projectIds: this.selectedProjectIds,
};
},
result({ data }) {
const projects = data.group.projects.nodes;
// Keep data from all queries so that we don't
// fetch the same data more than once
this.allCoverageData = [
...this.allCoverageData,
// Remove the projects that don't have any code coverage
...data.projects.nodes
.filter(({ codeCoverageSummary }) => Boolean(codeCoverageSummary))
...projects
.filter(({ id }) => !this.allCoverageData.some((project) => project.id === id))
.map((project) => ({
...project,
codeCoveragePath: joinPaths(
......@@ -48,6 +54,9 @@ export default {
})),
];
},
update(data) {
return data.group.projects.nodes;
},
error() {
this.handleError();
},
......@@ -62,10 +71,11 @@ export default {
data() {
return {
allProjectsSelected: false,
allCoverageData: [],
allCoverageData: [], // All data we have ever received whether selected or not
hasError: false,
isLoading: false,
projectIds: {},
projectIds: {}, // Which project IDs have been selected
projects: {},
};
},
computed: {
......@@ -74,15 +84,27 @@ export default {
},
skipQuery() {
// Skip if we haven't selected any projects yet
return !this.selectedProjectIds.length;
return !this.allProjectsSelected && !this.selectedProjectIds.length;
},
/**
* selectedProjectIds is a subset of projectIds
* The difference is that it only returns the projects
* that we have selected but haven't requested yet
*/
selectedProjectIds() {
if (this.allProjectsSelected) {
return null;
}
// Get the IDs of the projects that we haven't requested yet
return Object.keys(this.projectIds).filter(
(id) => !this.allCoverageData.some((project) => project.id === id),
);
},
selectedCoverageData() {
if (this.allProjectsSelected) {
return this.allCoverageData;
}
return this.allCoverageData.filter(({ id }) => this.projectIds[id]);
},
sortedCoverageData() {
......@@ -106,8 +128,7 @@ export default {
api.trackRedisHllUserEvent(this.$options.usagePingProjectEvent);
}
},
selectAllProjects(allProjects) {
this.projectIds = Object.fromEntries(allProjects.map(({ id }) => [id, true]));
selectAllProjects() {
this.allProjectsSelected = true;
},
toggleProject({ id }) {
......
......@@ -2,7 +2,7 @@
query getGroupProjects($groupFullPath: ID!, $after: String) {
group(fullPath: $groupFullPath) {
projects(after: $after, first: 100) {
projects(hasCodeCoverage: true, after: $after, first: 100) {
nodes {
name
id
......
query getProjectsTestCoverage($projectIds: [ID!]) {
projects(ids: $projectIds) {
nodes {
fullPath
id
name
repository {
rootRef
}
codeCoverageSummary {
averageCoverage
coverageCount
lastUpdatedOn
query getProjectsTestCoverage($groupFullPath: ID!, $projectIds: [ID!]) {
group(fullPath: $groupFullPath) {
projects(hasCodeCoverage: true, ids: $projectIds) {
nodes {
fullPath
id
name
repository {
rootRef
}
codeCoverageSummary {
averageCoverage
coverageCount
lastUpdatedOn
}
}
}
}
......
---
title: Fix group code coverage table to show all projects correctly
merge_request: 56124
author:
type: fixed
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