From 71ffed026d105eec8dc5ad0cc1567407a792e81d Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:52:22 +0200 Subject: [PATCH 1/5] FIx: Fetching workspaces with no environments --- backend/src/services/project/project-dal.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/src/services/project/project-dal.ts b/backend/src/services/project/project-dal.ts index 4f4225344..04107b919 100644 --- a/backend/src/services/project/project-dal.ts +++ b/backend/src/services/project/project-dal.ts @@ -126,13 +126,11 @@ export const projectDALFactory = (db: TDbClient) => { const findProjectById = async (id: string) => { try { - const workspaces = await db(TableName.ProjectMembership) + const workspaces = await db(TableName.Project) .where(`${TableName.Project}.id`, id) - .join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`) - .join(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`) + .leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`) .select( selectAllTableCols(TableName.Project), - db.ref("id").withSchema(TableName.Project).as("_id"), db.ref("id").withSchema(TableName.Environment).as("envId"), db.ref("slug").withSchema(TableName.Environment).as("envSlug"), db.ref("name").withSchema(TableName.Environment).as("envName") @@ -141,10 +139,11 @@ export const projectDALFactory = (db: TDbClient) => { { column: `${TableName.Project}.name`, order: "asc" }, { column: `${TableName.Environment}.position`, order: "asc" } ]); + const project = sqlNestRelationships({ data: workspaces, key: "id", - parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }), + parentMapper: ({ ...el }) => ({ _id: el.id, ...ProjectsSchema.parse(el) }), childrenMapper: [ { key: "envId", @@ -174,14 +173,12 @@ export const projectDALFactory = (db: TDbClient) => { throw new BadRequestError({ message: "Organization ID is required when querying with slugs" }); } - const projects = await db(TableName.ProjectMembership) + const projects = await db(TableName.Project) .where(`${TableName.Project}.slug`, slug) .where(`${TableName.Project}.orgId`, orgId) - .join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`) - .join(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`) + .leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`) .select( selectAllTableCols(TableName.Project), - db.ref("id").withSchema(TableName.Project).as("_id"), db.ref("id").withSchema(TableName.Environment).as("envId"), db.ref("slug").withSchema(TableName.Environment).as("envSlug"), db.ref("name").withSchema(TableName.Environment).as("envName") @@ -194,7 +191,7 @@ export const projectDALFactory = (db: TDbClient) => { const project = sqlNestRelationships({ data: projects, key: "id", - parentMapper: ({ _id, ...el }) => ({ _id, ...ProjectsSchema.parse(el) }), + parentMapper: ({ ...el }) => ({ _id: el.id, ...ProjectsSchema.parse(el) }), childrenMapper: [ { key: "envId", @@ -221,6 +218,7 @@ export const projectDALFactory = (db: TDbClient) => { const findProjectByFilter = async (filter: Filter) => { try { if (filter.type === ProjectFilterType.ID) { + console.log("filter.projectId", filter.projectId); return await findProjectById(filter.projectId); } if (filter.type === ProjectFilterType.SLUG) { From 5315a67d742667fbda692abca5ade4a64d420163 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 01:46:11 +0200 Subject: [PATCH 2/5] Feat: Disable integration creation when no environments are present on project --- .../integrations/NoEnvironmentsBanner.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 frontend/src/components/integrations/NoEnvironmentsBanner.tsx diff --git a/frontend/src/components/integrations/NoEnvironmentsBanner.tsx b/frontend/src/components/integrations/NoEnvironmentsBanner.tsx new file mode 100644 index 000000000..2dc931d8c --- /dev/null +++ b/frontend/src/components/integrations/NoEnvironmentsBanner.tsx @@ -0,0 +1,32 @@ +import { useRouter } from "next/router"; +import { faWarning } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +import { Button } from "../v2"; + +interface IProps { + projectId: string; +} + +export const NoEnvironmentsBanner = ({ projectId }: IProps) => { + const router = useRouter(); + + return ( +
+ +
+ + No environments in your project was found + +

+ In order to use integrations, you need to create at least one environment in your project. +

+
+
+ +
+
+ ); +}; From 3131ae7daebba15f74124181a7c4db2890fff6f2 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 01:46:19 +0200 Subject: [PATCH 3/5] Feat: Disable integration creation when no environments are present on project --- .../CloudIntegrationSection.tsx | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx index 5a0d85851..f81f8befe 100644 --- a/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx +++ b/frontend/src/views/IntegrationsPage/components/CloudIntegrationSection/CloudIntegrationSection.tsx @@ -1,10 +1,17 @@ +import { useMemo } from "react"; import { useTranslation } from "react-i18next"; import { faCheck, faXmark } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { NoEnvironmentsBanner } from "@app/components/integrations/NoEnvironmentsBanner"; import { createNotification } from "@app/components/notifications"; import { DeleteActionModal, Skeleton, Tooltip } from "@app/components/v2"; -import { ProjectPermissionActions, ProjectPermissionSub, useProjectPermission } from "@app/context"; +import { + ProjectPermissionActions, + ProjectPermissionSub, + useProjectPermission, + useWorkspace +} from "@app/context"; import { usePopUp } from "@app/hooks"; import { IntegrationAuth, TCloudIntegration } from "@app/hooks/api/types"; @@ -31,18 +38,32 @@ export const CloudIntegrationSection = ({ "deleteConfirmation" ] as const); const { permission } = useProjectPermission(); - + const { currentWorkspace } = useWorkspace(); const isEmpty = !isLoading && !cloudIntegrations?.length; - const sortedCloudIntegrations = cloudIntegrations.sort((a, b) => a.name.localeCompare(b.name)); + const sortedCloudIntegrations = useMemo(() => { + const sortedIntegrations = cloudIntegrations.sort((a, b) => a.name.localeCompare(b.name)); + + if (currentWorkspace?.environments.length === 0) { + return sortedIntegrations.map((integration) => ({ ...integration, isAvailable: false })); + } + + return sortedIntegrations; + }, [cloudIntegrations, currentWorkspace?.environments]); return (
+
+ {currentWorkspace?.environments.length === 0 && ( + + )} +

{t("integrations.cloud-integrations")}

{t("integrations.click-to-start")}

+
{isLoading && Array.from({ length: 12 }).map((_, index) => ( From 39c2c37cc0c5f9e57dbeefbabb28d4ce663557e5 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 01:49:28 +0200 Subject: [PATCH 4/5] Remove log --- backend/src/services/project/project-dal.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/services/project/project-dal.ts b/backend/src/services/project/project-dal.ts index 04107b919..fae3615eb 100644 --- a/backend/src/services/project/project-dal.ts +++ b/backend/src/services/project/project-dal.ts @@ -218,7 +218,6 @@ export const projectDALFactory = (db: TDbClient) => { const findProjectByFilter = async (filter: Filter) => { try { if (filter.type === ProjectFilterType.ID) { - console.log("filter.projectId", filter.projectId); return await findProjectById(filter.projectId); } if (filter.type === ProjectFilterType.SLUG) { From 8b56e20b420c46d7f4acf3baeb0822af0b441fe3 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 12 Apr 2024 01:49:59 +0200 Subject: [PATCH 5/5] Fix: Removed icon --- frontend/src/components/integrations/NoEnvironmentsBanner.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/components/integrations/NoEnvironmentsBanner.tsx b/frontend/src/components/integrations/NoEnvironmentsBanner.tsx index 2dc931d8c..fa900ff6d 100644 --- a/frontend/src/components/integrations/NoEnvironmentsBanner.tsx +++ b/frontend/src/components/integrations/NoEnvironmentsBanner.tsx @@ -1,6 +1,4 @@ import { useRouter } from "next/router"; -import { faWarning } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Button } from "../v2"; @@ -13,7 +11,6 @@ export const NoEnvironmentsBanner = ({ projectId }: IProps) => { return (
-
No environments in your project was found