From 2d16f5f258b630a2591e4aad5db389d6155dc9f6 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Wed, 12 Feb 2025 20:35:00 -0800 Subject: [PATCH 1/2] fix (temp): wrap integrations before load in try/catch, fix render banner guard --- .../permissions/ProjectPermissionCan.tsx | 8 +-- .../IntegrationsListPage.tsx | 5 +- .../IntegrationsListPage/route.tsx | 52 +++++++++++-------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/frontend/src/components/permissions/ProjectPermissionCan.tsx b/frontend/src/components/permissions/ProjectPermissionCan.tsx index d8f794bf9..f49709ff3 100644 --- a/frontend/src/components/permissions/ProjectPermissionCan.tsx +++ b/frontend/src/components/permissions/ProjectPermissionCan.tsx @@ -57,6 +57,10 @@ export const ProjectPermissionCan: FunctionComponent const finalChild = typeof children === "function" ? children(isAllowed, ability as any) : children; + if (!isAllowed && renderGuardBanner) { + return ; + } + if (!isAllowed && passThrough) { return {finalChild}; } @@ -65,10 +69,6 @@ export const ProjectPermissionCan: FunctionComponent return {finalChild}; } - if (!isAllowed && renderGuardBanner) { - return ; - } - if (!isAllowed) return null; return finalChild; diff --git a/frontend/src/pages/secret-manager/IntegrationsListPage/IntegrationsListPage.tsx b/frontend/src/pages/secret-manager/IntegrationsListPage/IntegrationsListPage.tsx index a96a4d595..ac53cb4d9 100644 --- a/frontend/src/pages/secret-manager/IntegrationsListPage/IntegrationsListPage.tsx +++ b/frontend/src/pages/secret-manager/IntegrationsListPage/IntegrationsListPage.tsx @@ -8,6 +8,7 @@ import { ProjectPermissionCan } from "@app/components/permissions"; import { Badge, PageHeader, Tab, TabList, TabPanel, Tabs } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context"; +import { ProjectPermissionSecretSyncActions } from "@app/context/ProjectPermissionContext/types"; import { IntegrationsListPageTabs } from "@app/types/integrations"; import { @@ -100,8 +101,7 @@ export const IntegrationsListPage = () => { @@ -110,7 +110,6 @@ export const IntegrationsListPage = () => { diff --git a/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx b/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx index 54142e2d9..f58022d8d 100644 --- a/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx +++ b/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx @@ -20,12 +20,37 @@ export const Route = createFileRoute( validateSearch: zodValidator(IntegrationsListPageQuerySchema), beforeLoad: async ({ context, search, params: { projectId } }) => { if (!search.selectedTab) { - const secretSyncs = await context.queryClient.ensureQueryData({ - queryKey: secretSyncKeys.list(projectId), - queryFn: () => fetchSecretSyncsByProjectId(projectId) - }); + try { + const secretSyncs = await context.queryClient.ensureQueryData({ + queryKey: secretSyncKeys.list(projectId), + queryFn: () => fetchSecretSyncsByProjectId(projectId) + }); + + if (secretSyncs.length) { + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } + }); + } + + const integrations = await context.queryClient.ensureQueryData({ + queryKey: workspaceKeys.getWorkspaceIntegrations(projectId), + queryFn: () => fetchWorkspaceIntegrations(projectId) + }); + + if (integrations.length) { + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } + }); + } - if (secretSyncs.length) { throw redirect({ to: "/secret-manager/$projectId/integrations", params: { @@ -33,14 +58,7 @@ export const Route = createFileRoute( }, search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } }); - } - - const integrations = await context.queryClient.ensureQueryData({ - queryKey: workspaceKeys.getWorkspaceIntegrations(projectId), - queryFn: () => fetchWorkspaceIntegrations(projectId) - }); - - if (integrations.length) { + } catch { throw redirect({ to: "/secret-manager/$projectId/integrations", params: { @@ -49,14 +67,6 @@ export const Route = createFileRoute( search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } }); } - - throw redirect({ - to: "/secret-manager/$projectId/integrations", - params: { - projectId - }, - search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } - }); } return { From ec12d578625c178678e19b9068e9c95afbb0e87e Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Wed, 12 Feb 2025 20:56:07 -0800 Subject: [PATCH 2/2] fix: refine try/catch --- .../IntegrationsListPage/route.tsx | 88 +++++++++++-------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx b/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx index f58022d8d..7a5f70622 100644 --- a/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx +++ b/frontend/src/pages/secret-manager/IntegrationsListPage/route.tsx @@ -3,7 +3,12 @@ import { zodValidator } from "@tanstack/zod-adapter"; import { z } from "zod"; import { workspaceKeys } from "@app/hooks/api"; -import { fetchSecretSyncsByProjectId, secretSyncKeys } from "@app/hooks/api/secretSyncs"; +import { TIntegration } from "@app/hooks/api/integrations/types"; +import { + fetchSecretSyncsByProjectId, + secretSyncKeys, + TSecretSync +} from "@app/hooks/api/secretSyncs"; import { fetchWorkspaceIntegrations } from "@app/hooks/api/workspace/queries"; import { IntegrationsListPageTabs } from "@app/types/integrations"; @@ -20,44 +25,13 @@ export const Route = createFileRoute( validateSearch: zodValidator(IntegrationsListPageQuerySchema), beforeLoad: async ({ context, search, params: { projectId } }) => { if (!search.selectedTab) { + let secretSyncs: TSecretSync[]; + try { - const secretSyncs = await context.queryClient.ensureQueryData({ + secretSyncs = await context.queryClient.ensureQueryData({ queryKey: secretSyncKeys.list(projectId), queryFn: () => fetchSecretSyncsByProjectId(projectId) }); - - if (secretSyncs.length) { - throw redirect({ - to: "/secret-manager/$projectId/integrations", - params: { - projectId - }, - search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } - }); - } - - const integrations = await context.queryClient.ensureQueryData({ - queryKey: workspaceKeys.getWorkspaceIntegrations(projectId), - queryFn: () => fetchWorkspaceIntegrations(projectId) - }); - - if (integrations.length) { - throw redirect({ - to: "/secret-manager/$projectId/integrations", - params: { - projectId - }, - search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } - }); - } - - throw redirect({ - to: "/secret-manager/$projectId/integrations", - params: { - projectId - }, - search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } - }); } catch { throw redirect({ to: "/secret-manager/$projectId/integrations", @@ -67,6 +41,50 @@ export const Route = createFileRoute( search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } }); } + + if (secretSyncs.length) { + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } + }); + } + + let integrations: TIntegration[]; + try { + integrations = await context.queryClient.ensureQueryData({ + queryKey: workspaceKeys.getWorkspaceIntegrations(projectId), + queryFn: () => fetchWorkspaceIntegrations(projectId) + }); + } catch { + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } + }); + } + + if (integrations.length) { + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } + }); + } + + throw redirect({ + to: "/secret-manager/$projectId/integrations", + params: { + projectId + }, + search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } + }); } return {