mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: list projects with all archived toggles (#3020)
## About the changes While trying to count only features that are not archived to display the amount of features of a project, accidentally we filtered out projects with all features archived (they should show up in the list but with count of features zero)
This commit is contained in:
parent
b0ef6920e8
commit
812604902b
@ -89,14 +89,13 @@ class ProjectStore implements IProjectStore {
|
|||||||
const projectTimer = this.timer('getProjectsWithCount');
|
const projectTimer = this.timer('getProjectsWithCount');
|
||||||
let projects = this.db(TABLE)
|
let projects = this.db(TABLE)
|
||||||
.leftJoin('features', 'features.project', 'projects.id')
|
.leftJoin('features', 'features.project', 'projects.id')
|
||||||
.where('features.archived_at', null)
|
|
||||||
.orderBy('projects.name', 'asc');
|
.orderBy('projects.name', 'asc');
|
||||||
if (query) {
|
if (query) {
|
||||||
projects = projects.where(query);
|
projects = projects.where(query);
|
||||||
}
|
}
|
||||||
let selectColumns = [
|
let selectColumns = [
|
||||||
this.db.raw(
|
this.db.raw(
|
||||||
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) AS number_of_features',
|
'projects.id, projects.name, projects.description, projects.health, projects.updated_at, count(features.name) FILTER (WHERE features.archived_at is null) AS number_of_features',
|
||||||
),
|
),
|
||||||
] as (string | Raw<any>)[];
|
] as (string | Raw<any>)[];
|
||||||
|
|
||||||
|
@ -1057,6 +1057,28 @@ test('should only count active feature toggles for project', async () => {
|
|||||||
expect(theProject?.featureCount).toBe(1);
|
expect(theProject?.featureCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should list projects with all features archived', async () => {
|
||||||
|
const project = {
|
||||||
|
id: 'only-archived',
|
||||||
|
name: 'Listed project',
|
||||||
|
description: 'Blah',
|
||||||
|
};
|
||||||
|
|
||||||
|
await projectService.createProject(project, user);
|
||||||
|
|
||||||
|
await stores.featureToggleStore.create(project.id, {
|
||||||
|
name: 'archived-toggle',
|
||||||
|
project: project.id,
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await featureToggleService.archiveToggle('archived-toggle', 'me');
|
||||||
|
|
||||||
|
const projects = await projectService.getProjects();
|
||||||
|
const theProject = projects.find((p) => p.id === project.id);
|
||||||
|
expect(theProject?.featureCount).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
const updateEventCreatedAt = async (date: Date, featureName: string) => {
|
const updateEventCreatedAt = async (date: Date, featureName: string) => {
|
||||||
return db.rawDatabase
|
return db.rawDatabase
|
||||||
.table('events')
|
.table('events')
|
||||||
|
Loading…
Reference in New Issue
Block a user