From 3fde1742e3575ae50d28f88e9896f7792c7bb73b Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Wed, 30 Oct 2024 13:29:31 +0100 Subject: [PATCH] fix(poke): use correct endpoint to retrieve features (#8331) Co-authored-by: Henry Fontanier --- front/components/poke/features/table.tsx | 3 ++- front/lib/swr/poke.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/front/components/poke/features/table.tsx b/front/components/poke/features/table.tsx index 74ed76432120..319ce10ce433 100644 --- a/front/components/poke/features/table.tsx +++ b/front/components/poke/features/table.tsx @@ -4,6 +4,7 @@ import { useRouter } from "next/router"; import { makeColumnsForFeatureFlags } from "@app/components/poke/features/columns"; import { PokeDataTable } from "@app/components/poke/shadcn/ui/data_table"; +import { usePokeFeatureFlags } from "@app/lib/swr/poke"; import { useFeatureFlags } from "@app/lib/swr/workspaces"; interface FeatureFlagsDataTableProps { @@ -30,7 +31,7 @@ export function FeatureFlagsDataTable({ whitelistableFeatures, }: FeatureFlagsDataTableProps) { const router = useRouter(); - const { featureFlags } = useFeatureFlags({ workspaceId: owner.sId }); + const { featureFlags } = usePokeFeatureFlags({ workspaceId: owner.sId }); const sendNotification = useSendNotification(); return ( diff --git a/front/lib/swr/poke.ts b/front/lib/swr/poke.ts index 9074459d32e0..36f55eba5bf7 100644 --- a/front/lib/swr/poke.ts +++ b/front/lib/swr/poke.ts @@ -9,6 +9,7 @@ import type { Fetcher } from "swr"; import { fetcher, useSWRWithDefaults } from "@app/lib/swr/swr"; import type { GetPokePlansResponseBody } from "@app/pages/api/poke/plans"; import type { GetPokeWorkspacesResponseBody } from "@app/pages/api/poke/workspaces"; +import type { GetPokeFeaturesResponseBody } from "@app/pages/api/poke/workspaces/[wId]/features"; import type { GetDataSourcePermissionsResponseBody } from "@app/pages/api/w/[wId]/data_sources/[dsId]/managed/permissions"; export function usePokeConnectorPermissions({ @@ -96,3 +97,18 @@ export function usePokePlans() { isPlansError: error, }; } + +export function usePokeFeatureFlags({ workspaceId }: { workspaceId: string }) { + const featureFlagsFetcher: Fetcher = fetcher; + + const { data, error } = useSWRWithDefaults( + `/api/poke/workspaces/${workspaceId}/features`, + featureFlagsFetcher + ); + + return { + featureFlags: useMemo(() => (data ? data.features : []), [data]), + isFeatureFlagsLoading: !error && !data, + isFeatureFlagsError: error, + }; +}