Skip to content

Commit

Permalink
store/backendApi: export the relevant store api
Browse files Browse the repository at this point in the history
Since the implementation of the cockpitApi and imageBuilderApi are different,
we should make sure to export the correct one depending on the environment
we are in.
  • Loading branch information
kingsleyzissou committed Jan 9, 2025
1 parent a6359ce commit 3fc7ddc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/Components/Blueprints/BlueprintsPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { Pagination, PaginationVariant } from '@patternfly/react-core';
import { OnSetPage } from '@patternfly/react-core/dist/esm/components/Pagination/Pagination';

import { useGetBlueprintsQuery } from '../../store/backendApi';
import {
selectBlueprintSearchInput,
selectLimit,
Expand All @@ -11,10 +12,7 @@ import {
setBlueprintsOffset,
} from '../../store/BlueprintSlice';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import {
useGetBlueprintsQuery,
GetBlueprintsApiArg,
} from '../../store/imageBuilderApi';
import { GetBlueprintsApiArg } from '../../store/imageBuilderApi';

const BlueprintsPagination = () => {
const blueprintSearchInput = useAppSelector(selectBlueprintSearchInput);
Expand Down
14 changes: 7 additions & 7 deletions src/Components/Blueprints/DeleteBlueprintModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import {
} from '@patternfly/react-core';

import { PAGINATION_LIMIT, PAGINATION_OFFSET } from '../../constants';
import {
backendApi,
useDeleteBlueprintMutation,
useGetBlueprintsQuery,
} from '../../store/backendApi';
import {
selectBlueprintSearchInput,
selectLimit,
selectOffset,
selectSelectedBlueprintId,
setBlueprintId,
} from '../../store/BlueprintSlice';
import { imageBuilderApi } from '../../store/enhancedImageBuilderApi';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import {
GetBlueprintsApiArg,
useDeleteBlueprintMutation,
useGetBlueprintsQuery,
} from '../../store/imageBuilderApi';
import { GetBlueprintsApiArg } from '../../store/imageBuilderApi';

interface DeleteBlueprintModalProps {
setShowDeleteModal: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down Expand Up @@ -62,7 +62,7 @@ export const DeleteBlueprintModal: React.FunctionComponent<
setShowDeleteModal(false);
await deleteBlueprint({ id: selectedBlueprintId });
dispatch(setBlueprintId(undefined));
dispatch(imageBuilderApi.util.invalidateTags([{ type: 'Blueprints' }]));
dispatch(backendApi.util.invalidateTags([{ type: 'Blueprints' }]));
}
};
const onDeleteClose = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ImagesTable/ImagesTableToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Title,
} from '@patternfly/react-core';

import { useGetBlueprintsQuery } from '../../store/backendApi';
import {
selectSelectedBlueprintId,
selectBlueprintSearchInput,
Expand All @@ -18,7 +19,6 @@ import {
import { useAppSelector } from '../../store/hooks';
import {
BlueprintItem,
useGetBlueprintsQuery,
useGetBlueprintComposesQuery,
Distributions,
GetBlueprintComposesApiArg,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ImagesTable/Instance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import {
MODAL_ANCHOR,
SEARCH_INPUT,
} from '../../constants';
import { useGetBlueprintsQuery } from '../../store/backendApi';
import {
selectSelectedBlueprintId,
selectBlueprintSearchInput,
} from '../../store/BlueprintSlice';
import { useAppSelector } from '../../store/hooks';
import {
BlueprintItem,
useGetBlueprintsQuery,
ComposesResponseItem,
ComposeStatus,
ImageTypes,
Expand Down
20 changes: 18 additions & 2 deletions src/store/backendApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { useGetBlueprintsQuery as useCockpitGetBlueprintsQuery } from './cockpitApi';
import { useGetBlueprintsQuery as useImageBuilderGetBlueprintsQuery } from './imageBuilderApi';
import {
useGetBlueprintsQuery as useCockpitGetBlueprintsQuery,
useDeleteBlueprintMutation as useCockpitDeleteMutation,
} from './cockpitApi';
import { cockpitApi } from './enhancedCockpitApi';
import { imageBuilderApi } from './enhancedImageBuilderApi';
import {
useGetBlueprintsQuery as useImageBuilderGetBlueprintsQuery,
useDeleteBlueprintMutation as useImageBuilderDeleteMutation,
} from './imageBuilderApi';

export const useGetBlueprintsQuery = process.env.IS_ON_PREMISE
? useCockpitGetBlueprintsQuery
: useImageBuilderGetBlueprintsQuery;

export const useDeleteBlueprintMutation = process.env.IS_ON_PREMISE
? useCockpitDeleteMutation
: useImageBuilderDeleteMutation;

export const backendApi = process.env.IS_ON_PREMISE
? cockpitApi
: imageBuilderApi;

0 comments on commit 3fc7ddc

Please sign in to comment.