From 7f378ccfd553f2f0cdc03748cb053c4392dd37fc Mon Sep 17 00:00:00 2001 From: Francisco Madeira Date: Fri, 20 Sep 2024 15:47:15 +0100 Subject: [PATCH] fix: remove group to display all the components --- web/dashboard/src/data/projects/actions.ts | 54 ++-------------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/web/dashboard/src/data/projects/actions.ts b/web/dashboard/src/data/projects/actions.ts index 7188d0ab..9cb7220e 100644 --- a/web/dashboard/src/data/projects/actions.ts +++ b/web/dashboard/src/data/projects/actions.ts @@ -129,7 +129,7 @@ export async function getEnvironmentsById( ...getTableColumns(environments), components: sql`COALESCE( jsonb_agg( - jsonb_build_object( + DISTINCT jsonb_build_object( 'id', ${components.id}, 'name', ${components.name}, 'title', ${components.title}, @@ -155,11 +155,7 @@ export async function getEnvironmentsById( eq(componentVersions.id, projectComponentConfig.component_version) ) .groupBy( - environments.id, - components.id, - componentVersions.version, - projectComponentConfig.id, - projectComponentConfig.is_active + environments.id ) .where( and( @@ -167,12 +163,7 @@ export async function getEnvironmentsById( await userIsMember(userId, environments.project_id) ) ) - .orderBy( - sql`${projectComponentConfig.is_active} DESC NULLS LAST`, - sql`${componentVersions.version} NULLS LAST`, - components.name - ); - + const safe = environmentWithComponentsSchema.safeParse(select[0]); if (!safe.success) { return actionZodError( @@ -188,45 +179,6 @@ export async function getEnvironmentsById( } } -export async function getProjectsWithComponents( - userId: string | undefined | null -): ActionResponse { - if (!userId) { - return actionError('No user provided.'); - } - - try { - const select = await db.query.projects.findMany({ - where: userIsMember(userId), - with: { - components: { - columns: { - is_active: true, - component_version: true - }, - with: { - component: true, - version: true - } - } - } - }); - - const safe = z.array(projectWithComponentSchema).safeParse(select); - if (!safe.success) { - return actionZodError( - 'There\'s an issue with the project records.', - safe.error - ); - } - - return actionSuccess(safe.data); - } catch (error) { - console.error(error); - return actionError('Failed to fetch project from database.'); - } -} - export async function getEnvironmentComponents( id: string | undefined | null, userId: string | undefined | null