From df938270025a1e6f5e84fc6d59be0e3f87518172 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 28 Feb 2024 16:26:53 +0200 Subject: [PATCH] feat: remove applications from project list that do not exist (#6377) --- .../project/ProjectApplications/SdkCell.tsx | 9 ++++++-- .../project/project-applications.e2e.test.ts | 23 +++++++++++++++++++ src/lib/features/project/project-store.ts | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/project/ProjectApplications/SdkCell.tsx b/frontend/src/component/project/ProjectApplications/SdkCell.tsx index 8993c9e22d..6b9fc7f83f 100644 --- a/frontend/src/component/project/ProjectApplications/SdkCell.tsx +++ b/frontend/src/component/project/ProjectApplications/SdkCell.tsx @@ -10,6 +10,11 @@ const StyledTag = styled('div')(({ theme }) => ({ fontSize: theme.fontSizes.smallerBody, })); +const StyledList = styled('ul')(({ theme }) => ({ + padding: theme.spacing(0, 0, 0.5, 2), + margin: theme.spacing(0), +})); + interface ISdkCellProps { row: { original: ProjectApplicationSchema; @@ -42,7 +47,7 @@ export const SdkCell: VFC = ({ row }) => { {sdk.name} - + ))} diff --git a/src/lib/features/project/project-applications.e2e.test.ts b/src/lib/features/project/project-applications.e2e.test.ts index 7633a31d59..889e6ab01d 100644 --- a/src/lib/features/project/project-applications.e2e.test.ts +++ b/src/lib/features/project/project-applications.e2e.test.ts @@ -56,6 +56,7 @@ beforeAll(async () => { afterEach(async () => { await db.stores.clientMetricsStoreV2.deleteAll(); await db.stores.clientInstanceStore.deleteAll(); + await db.stores.clientApplicationsStore.deleteAll(); await db.stores.featureToggleStore.deleteAll(); }); @@ -388,3 +389,25 @@ test('should show correct number of total', async () => { total: 2, }); }); + +test('should not show if metrics exist, but application does not', async () => { + await app.createFeature('toggle-name-1'); + + await app.request + .post('/api/client/metrics') + .set('Authorization', defaultToken.secret) + .send(metrics) + .expect(202); + + await app.services.clientMetricsServiceV2.bulkAdd(); + + const { body } = await app.request + .get('/api/admin/projects/default/applications?sortOrder=desc&limit=1') + .expect('Content-Type', /json/) + .expect(200); + + expect(body).toMatchObject({ + applications: [], + total: 0, + }); +}); diff --git a/src/lib/features/project/project-store.ts b/src/lib/features/project/project-store.ts index ac4b5a5a5a..acdc03cebb 100644 --- a/src/lib/features/project/project-store.ts +++ b/src/lib/features/project/project-store.ts @@ -614,6 +614,11 @@ class ProjectStore implements IProjectStore { ), ) .from('applications as a') + .innerJoin( + 'client_applications as ca', + 'a.app_name', + 'ca.app_name', + ) .leftJoin('client_instances as ci', function () { this.on('ci.app_name', '=', 'a.app_name').andOn( 'ci.environment',