diff --git a/web/dashboard/src/components/projects/component-selection-table/components-dialog.tsx b/web/dashboard/src/components/projects/component-selection-table/components-dialog.tsx index 70c996bf..23111fda 100644 --- a/web/dashboard/src/components/projects/component-selection-table/components-dialog.tsx +++ b/web/dashboard/src/components/projects/component-selection-table/components-dialog.tsx @@ -66,7 +66,7 @@ export function ComponentsDialog({ components, environment, project, environment function handleEnvironment(environmentId: string | null) { return () => { - const params = new URLSearchParams(searchParams); + const params = new URLSearchParams(searchParams.toString()); if (environmentId) { params.set('env', environmentId); } @@ -78,7 +78,7 @@ export function ComponentsDialog({ components, environment, project, environment function handleLaunch(environmentId: string | null) { return () => { - const params = new URLSearchParams(searchParams); + const params = new URLSearchParams(searchParams.toString()); if (environmentId) { params.set('env', environmentId); } 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