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

Merge branch '284381-group-code-coverage-query' into 'master'

Update group code coverage projects query

See merge request gitlab-org/gitlab!56124
parents c82217d8 11533405
...@@ -22,23 +22,29 @@ export default { ...@@ -22,23 +22,29 @@ export default {
TimeAgoTooltip, TimeAgoTooltip,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
inject: {
groupFullPath: {
default: '',
},
},
apollo: { apollo: {
projects: { projects: {
query: getProjectsTestCoverage, query: getProjectsTestCoverage,
debounce: 500, debounce: 500,
variables() { variables() {
return { return {
projectIds: this.selectedProjectIds, groupFullPath: this.groupFullPath,
projectIds: this.projectIdsToFetch,
}; };
}, },
result({ data }) { result({ data }) {
const projects = data.group.projects.nodes;
// Keep data from all queries so that we don't // Keep data from all queries so that we don't
// fetch the same data more than once // fetch the same data more than once
this.allCoverageData = [ this.allCoverageData = [
...this.allCoverageData, ...this.allCoverageData,
// Remove the projects that don't have any code coverage ...projects
...data.projects.nodes .filter(({ id }) => !this.allCoverageData.some((project) => project.id === id))
.filter(({ codeCoverageSummary }) => Boolean(codeCoverageSummary))
.map((project) => ({ .map((project) => ({
...project, ...project,
codeCoveragePath: joinPaths( codeCoveragePath: joinPaths(
...@@ -48,6 +54,9 @@ export default { ...@@ -48,6 +54,9 @@ export default {
})), })),
]; ];
}, },
update(data) {
return data.group.projects.nodes;
},
error() { error() {
this.handleError(); this.handleError();
}, },
...@@ -62,10 +71,11 @@ export default { ...@@ -62,10 +71,11 @@ export default {
data() { data() {
return { return {
allProjectsSelected: false, allProjectsSelected: false,
allCoverageData: [], allCoverageData: [], // All data we have ever received whether selected or not
hasError: false, hasError: false,
isLoading: false, isLoading: false,
projectIds: {}, selectedProjectIds: {},
projects: {},
}; };
}, },
computed: { computed: {
...@@ -74,16 +84,28 @@ export default { ...@@ -74,16 +84,28 @@ export default {
}, },
skipQuery() { skipQuery() {
// Skip if we haven't selected any projects yet // Skip if we haven't selected any projects yet
return !this.selectedProjectIds.length; return !this.allProjectsSelected && !this.projectIdsToFetch.length;
}, },
selectedProjectIds() { /**
* projectIdsToFetch is a subset of selectedProjectIds
* The difference is that it only returns the projects
* that we have selected but haven't requested yet
*/
projectIdsToFetch() {
if (this.allProjectsSelected) {
return null;
}
// Get the IDs of the projects that we haven't requested yet // Get the IDs of the projects that we haven't requested yet
return Object.keys(this.projectIds).filter( return Object.keys(this.selectedProjectIds).filter(
(id) => !this.allCoverageData.some((project) => project.id === id), (id) => !this.allCoverageData.some((project) => project.id === id),
); );
}, },
selectedCoverageData() { selectedCoverageData() {
return this.allCoverageData.filter(({ id }) => this.projectIds[id]); if (this.allProjectsSelected) {
return this.allCoverageData;
}
return this.allCoverageData.filter(({ id }) => this.selectedProjectIds[id]);
}, },
sortedCoverageData() { sortedCoverageData() {
// Sort the table by most recently updated coverage report // Sort the table by most recently updated coverage report
...@@ -106,25 +128,24 @@ export default { ...@@ -106,25 +128,24 @@ export default {
api.trackRedisHllUserEvent(this.$options.usagePingProjectEvent); api.trackRedisHllUserEvent(this.$options.usagePingProjectEvent);
} }
}, },
selectAllProjects(allProjects) { selectAllProjects() {
this.projectIds = Object.fromEntries(allProjects.map(({ id }) => [id, true]));
this.allProjectsSelected = true; this.allProjectsSelected = true;
}, },
toggleProject({ id }) { toggleProject({ id }) {
if (this.allProjectsSelected) { if (this.allProjectsSelected) {
// Reset all project selections to false // Reset all project selections to false
this.allProjectsSelected = false; this.allProjectsSelected = false;
this.projectIds = Object.fromEntries( this.selectedProjectIds = Object.fromEntries(
Object.entries(this.projectIds).map(([key]) => [key, false]), Object.entries(this.selectedProjectIds).map(([key]) => [key, false]),
); );
} }
if (Object.prototype.hasOwnProperty.call(this.projectIds, id)) { if (Object.prototype.hasOwnProperty.call(this.selectedProjectIds, id)) {
Vue.set(this.projectIds, id, !this.projectIds[id]); Vue.set(this.selectedProjectIds, id, !this.selectedProjectIds[id]);
return; return;
} }
Vue.set(this.projectIds, id, true); Vue.set(this.selectedProjectIds, id, true);
}, },
}, },
tableFields: [ tableFields: [
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
query getGroupProjects($groupFullPath: ID!, $after: String) { query getGroupProjects($groupFullPath: ID!, $after: String) {
group(fullPath: $groupFullPath) { group(fullPath: $groupFullPath) {
projects(after: $after, first: 100) { projects(hasCodeCoverage: true, after: $after, first: 100) {
nodes { nodes {
name name
id id
......
query getProjectsTestCoverage($projectIds: [ID!]) { query getProjectsTestCoverage($groupFullPath: ID!, $projectIds: [ID!]) {
projects(ids: $projectIds) { group(fullPath: $groupFullPath) {
nodes { projects(hasCodeCoverage: true, ids: $projectIds) {
fullPath nodes {
id fullPath
name id
repository { name
rootRef repository {
} rootRef
codeCoverageSummary { }
averageCoverage codeCoverageSummary {
coverageCount averageCoverage
lastUpdatedOn 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