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 authored and lucasgarfield committed Jan 16, 2025
1 parent 79532e4 commit 3e69859
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;

1 comment on commit 3e69859

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have requested the builder permissions for the @osbuild/cockpit-image-builder-main Copr project.

Please confirm the request on the @osbuild/cockpit-image-builder-main Copr project permissions page and retrigger the build by clicking on a Re-run button or with a /packit build pull-request comment (for builds in pull-requests).

Please sign in to comment.