From 9b281ca5088ae456abf8638640e4199ce711e316 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Fri, 26 Jan 2024 12:04:43 +0100 Subject: [PATCH] feat: stale flags count per project (#6043) --- src/lib/db/project-store.ts | 8 +++++++- src/lib/openapi/spec/project-schema.ts | 11 +++++++++++ src/lib/types/model.ts | 2 ++ src/test/fixtures/fake-project-store.ts | 8 +++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index f62a5422ec93..250d409185ec 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -141,7 +141,10 @@ class ProjectStore implements IProjectStore { let selectColumns = [ this.db.raw( - 'projects.id, projects.name, projects.description, projects.health, projects.updated_at, projects.created_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features', + 'projects.id, projects.name, projects.description, projects.health, projects.updated_at, projects.created_at, ' + + 'count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features, ' + + 'count(features.name) FILTER (WHERE features.archived_at is null and features.stale IS TRUE) AS stale_feature_count, ' + + 'count(features.name) FILTER (WHERE features.archived_at is null and features.potentially_stale IS TRUE) AS potentially_stale_feature_count', ), 'project_settings.default_stickiness', 'project_settings.project_mode', @@ -203,6 +206,9 @@ class ProjectStore implements IProjectStore { health: row.health, favorite: row.favorite, featureCount: Number(row.number_of_features) || 0, + staleFeatureCount: Number(row.stale_feature_count) || 0, + potentiallyStaleFeatureCount: + Number(row.potentially_stale_feature_count) || 0, memberCount: Number(row.number_of_users) || 0, updatedAt: row.updated_at, createdAt: row.created_at, diff --git a/src/lib/openapi/spec/project-schema.ts b/src/lib/openapi/spec/project-schema.ts index 406b4466e96f..01b2282c147c 100644 --- a/src/lib/openapi/spec/project-schema.ts +++ b/src/lib/openapi/spec/project-schema.ts @@ -35,6 +35,17 @@ export const projectSchema = { example: 10, description: 'The number of features this project has', }, + staleFeatureCount: { + type: 'number', + example: 10, + description: 'The number of stale features this project has', + }, + potentiallyStaleFeatureCount: { + type: 'number', + example: 10, + description: + 'The number of potentially stale features this project has', + }, memberCount: { type: 'number', example: 4, diff --git a/src/lib/types/model.ts b/src/lib/types/model.ts index 75a74d36a852..9543a3ea8d6e 100644 --- a/src/lib/types/model.ts +++ b/src/lib/types/model.ts @@ -497,6 +497,8 @@ export interface ICustomRole extends IRole { export interface IProjectWithCount extends IProject { featureCount: number; + staleFeatureCount: number; + potentiallyStaleFeatureCount: number; memberCount: number; favorite?: boolean; } diff --git a/src/test/fixtures/fake-project-store.ts b/src/test/fixtures/fake-project-store.ts index cd58b558fa88..c69aaa8de98a 100644 --- a/src/test/fixtures/fake-project-store.ts +++ b/src/test/fixtures/fake-project-store.ts @@ -42,7 +42,13 @@ export default class FakeProjectStore implements IProjectStore { async getProjectsWithCounts(): Promise { return this.projects.map((project) => { - return { ...project, memberCount: 0, featureCount: 0 }; + return { + ...project, + memberCount: 0, + featureCount: 0, + staleFeatureCount: 0, + potentiallyStaleFeatureCount: 0, + }; }); }