Skip to content

Commit

Permalink
My changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kwarnerredhat committed Jan 11, 2024
1 parent 980bb45 commit 44d8e9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Pages/ContentListTable/ContentListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
FilterData,
IntrospectRepositoryRequestItem,
ContentOrigin,
triggerSnapshot,
} from '../../services/Content/ContentApi';
import { SkeletonTable } from '@patternfly/react-component-groups';

Expand Down Expand Up @@ -168,6 +167,10 @@ const ContentListTable = () => {
const introspectRepoForUuid = (uuid: string): Promise<void> =>
introspectRepository({ uuid: uuid, reset_count: true } as IntrospectRepositoryRequestItem);

const triggerSnapshot = async (uuid: string): Promise<void> => {
console.log(`Triggering snapshot for uuid: ${uuid}`);
};

const { mutateAsync: deleteItems, isLoading: isDeletingItems } = useBulkDeleteContentItemMutate(
queryClient,
checkedRepositories,
Expand Down
25 changes: 25 additions & 0 deletions src/services/Content/ContentQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
SnapshotListResponse,
ContentOrigin,
getRepoConfigFile,
triggerSnapshot,
} from './ContentApi';
import { ADMIN_TASK_LIST_KEY } from '../AdminTasks/AdminTaskQueries';
import useErrorNotification from '../../Hooks/useErrorNotification';
Expand Down Expand Up @@ -514,6 +515,30 @@ export const useGetPackagesQuery = (
},
);
};
export const useTriggerSnapshot = (queryClient: QueryClient, uuid: string, itemId: string) => {
const snapshotKeyArray = [CONTENT_LIST_KEY, itemId];
const errorNotifier = useErrorNotification();
const { notify } = useNotification();

return useMutation(triggerSnapshot, {
onSuccess: () => {
notify({
variant: AlertVariant.success,
title: 'Snapshot triggered successfully',
});
queryClient.invalidateQueries(CONTENT_LIST_KEY);
},
onError: (err, _newData, context) => {
if (context) {
const { previousData } = context as {
previousData: SnapshotListResponse;
};
queryClient.setQueryData(snapshotKeyArray, previousData);
}
errorNotifier('Error triggering snapshot', 'An error occurred', err);
},
});
};

export const useIntrospectRepositoryMutate = (
queryClient: QueryClient,
Expand Down

0 comments on commit 44d8e9f

Please sign in to comment.