From 41cdc7d553641abf607905677d75aaa62de39460 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Thu, 17 Oct 2024 18:57:29 +0100 Subject: [PATCH] ImageTable: use dynamic get blueprints hook Export a dynamic query hook depending on which backend is being used (service or on-prem). This means we can just import a query from the new `backendApi` and it will work for both on-prem and the service. --- src/Components/Blueprints/BlueprintsSideBar.tsx | 6 ++---- .../CreateImageWizard/steps/Review/ReviewStep.tsx | 1 + src/Components/ImagesTable/ImagesTable.tsx | 8 ++++++-- src/store/backendApi.ts | 6 ++++++ 4 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/store/backendApi.ts diff --git a/src/Components/Blueprints/BlueprintsSideBar.tsx b/src/Components/Blueprints/BlueprintsSideBar.tsx index 67c6e8c4..a05cf035 100644 --- a/src/Components/Blueprints/BlueprintsSideBar.tsx +++ b/src/Components/Blueprints/BlueprintsSideBar.tsx @@ -25,6 +25,7 @@ import BlueprintCard from './BlueprintCard'; import BlueprintsPagination from './BlueprintsPagination'; import { DEBOUNCED_SEARCH_WAIT_TIME } from '../../constants'; +import { useGetBlueprintsQuery } from '../../store/backendApi'; import { selectBlueprintSearchInput, selectLimit, @@ -36,10 +37,7 @@ import { } from '../../store/BlueprintSlice'; import { imageBuilderApi } from '../../store/enhancedImageBuilderApi'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; -import { - useGetBlueprintsQuery, - BlueprintItem, -} from '../../store/imageBuilderApi'; +import { BlueprintItem } from '../../store/imageBuilderApi'; import { resolveRelPath } from '../../Utilities/path'; type blueprintSearchProps = { diff --git a/src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx b/src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx index d3ad5032..7ea0819c 100644 --- a/src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx +++ b/src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx @@ -44,6 +44,7 @@ import { selectImageTypes, selectRegistrationType, } from '../../../../store/wizardSlice'; +import { useFlag } from '../../../../Utilities/useGetEnvironment'; const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => { const { goToStepById } = useWizardContext(); diff --git a/src/Components/ImagesTable/ImagesTable.tsx b/src/Components/ImagesTable/ImagesTable.tsx index 5ed8f36c..6cb99e8b 100644 --- a/src/Components/ImagesTable/ImagesTable.tsx +++ b/src/Components/ImagesTable/ImagesTable.tsx @@ -46,6 +46,7 @@ import { OCI_STORAGE_EXPIRATION_TIME_IN_DAYS, STATUS_POLLING_INTERVAL, } from '../../constants'; +import { useGetBlueprintsQuery } from '../../store/backendApi'; import { selectBlueprintSearchInput, selectBlueprintVersionFilter, @@ -61,7 +62,6 @@ import { ComposesResponseItem, ComposeStatus, useGetBlueprintComposesQuery, - useGetBlueprintsQuery, useGetComposesQuery, useGetComposeStatusQuery, } from '../../store/imageBuilderApi'; @@ -153,7 +153,11 @@ const ImagesTable = () => { ); } - if (!isSuccess) { + // TODO: the check for `IS_ON_PREMISE` should be removed when + // we create query functions for the other endpoints. We're skipping + // this check because the query request fails, since the `cockpitApi` + // still doesn't know how to query the composes endpoint + if (!process.env.IS_ON_PREMISE && !isSuccess) { if (isError) { return ( diff --git a/src/store/backendApi.ts b/src/store/backendApi.ts new file mode 100644 index 00000000..98292433 --- /dev/null +++ b/src/store/backendApi.ts @@ -0,0 +1,6 @@ +import { useGetBlueprintsQuery as useCockpitGetBlueprintsQuery } from './cockpitApi'; +import { useGetBlueprintsQuery as useImageBuilderGetBlueprintsQuery } from './imageBuilderApi'; + +export const useGetBlueprintsQuery = process.env.IS_ON_PREMISE + ? useCockpitGetBlueprintsQuery + : useImageBuilderGetBlueprintsQuery;