1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-03-18 00:19:49 +01:00

feat: filter out archived projects from the main project list (#7803)

This commit is contained in:
Mateusz Kwasniewski 2024-08-08 13:22:44 +02:00 committed by GitHub
parent 3fe385e127
commit fffed5d8dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 14 deletions

View File

@ -79,7 +79,10 @@ beforeAll(async () => {
email: 'test@example.com',
});
await stores.accessStore.addUserToRole(opsUser.id, 1, '');
const config = createTestConfig({ getLogger });
const config = createTestConfig({
getLogger,
experimental: { flags: { archiveProjects: true } },
});
eventService = new EventService(stores, config);
accessService = createAccessService(db.rawDatabase, config);
@ -299,6 +302,10 @@ test('should archive project', async () => {
type: 'project-archived',
createdBy: TEST_AUDIT_USER.username,
});
const projects = await projectService.getProjects();
expect(projects.find((p) => p.id === project.id)).toBeUndefined();
expect(projects.length).not.toBe(0);
});
test('should not be able to archive project with flags', async () => {

View File

@ -140,6 +140,9 @@ class ProjectStore implements IProjectStore {
)
.leftJoin('project_stats', 'project_stats.project', 'projects.id')
.orderBy('projects.name', 'asc');
if (this.flagResolver.isEnabled('archiveProjects')) {
projects = projects.where('projects.archived_at', null);
}
if (query) {
projects = projects.where(query);

View File

@ -19,8 +19,10 @@ import type {
ProjectEnvironment,
} from '../../lib/features/project/project-store-type';
type ArchivableProject = IProject & { archivedAt: null | Date };
export default class FakeProjectStore implements IProjectStore {
projects: IProject[] = [];
projects: ArchivableProject[] = [];
projectEnvironment: Map<string, Set<string>> = new Map();
@ -47,25 +49,28 @@ export default class FakeProjectStore implements IProjectStore {
}
async getProjectsWithCounts(): Promise<IProjectWithCount[]> {
return this.projects.map((project) => {
return {
...project,
memberCount: 0,
featureCount: 0,
staleFeatureCount: 0,
potentiallyStaleFeatureCount: 0,
avgTimeToProduction: 0,
};
});
return this.projects
.filter((project) => project.archivedAt !== null)
.map((project) => {
return {
...project,
memberCount: 0,
featureCount: 0,
staleFeatureCount: 0,
potentiallyStaleFeatureCount: 0,
avgTimeToProduction: 0,
};
});
}
private createInternal(project: IProjectInsert): IProject {
const newProj: IProject = {
const newProj: ArchivableProject = {
...project,
health: 100,
createdAt: new Date(),
mode: 'open',
defaultStickiness: 'default',
archivedAt: null,
};
this.projects.push(newProj);
return newProj;
@ -215,5 +220,11 @@ export default class FakeProjectStore implements IProjectStore {
throw new Error('Method not implemented.');
}
async archive(id: string): Promise<void> {}
async archive(id: string): Promise<void> {
this.projects = this.projects.map((project) =>
project.id === id
? { ...project, archivedAt: new Date() }
: project,
);
}
}