Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/library-authoring/create-library/CreateLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ export const CreateLibrary = ({

{(restoreTaskId || isError || restoreMutation.isError) && (
<div className="mb-4">
{restoreStatus?.state === LibraryRestoreStatus.Pending && (
{(restoreStatus?.state === LibraryRestoreStatus.Pending
|| restoreStatus?.state === LibraryRestoreStatus.InProgress) && (
<Alert variant="info">
{intl.formatMessage(messages.restoreInProgress)}
</Alert>
Expand Down
28 changes: 28 additions & 0 deletions src/library-authoring/create-library/data/apiHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ describe('create library apiHooks', () => {
expect(axiosMock.history.get[0].url).toEqual(`http://localhost:18010/api/libraries/v2/restore/?task_id=${taskId}`);
});

it('should handle in-progress status with refetch interval', async () => {
const taskId = 'in-progress-task-id';
const inProgressResult = {
state: LibraryRestoreStatus.InProgress,
result: null,
error: null,
error_log: null,
};

const expectedResult = {
state: LibraryRestoreStatus.InProgress,
result: null,
error: null,
errorLog: null,
};

axiosMock.onGet(`http://localhost:18010/api/libraries/v2/restore/?task_id=${taskId}`).reply(200, inProgressResult);

const { result } = renderHook(() => useGetLibraryRestoreStatus(taskId), { wrapper });

await waitFor(() => {
expect(result.current.isLoading).toBeFalsy();
});

expect(result.current.data).toEqual(expectedResult);
expect(axiosMock.history.get[0].url).toEqual(`http://localhost:18010/api/libraries/v2/restore/?task_id=${taskId}`);
});

it('should handle failed status', async () => {
const taskId = 'failed-task-id';
const failedResult = {
Expand Down
5 changes: 4 additions & 1 deletion src/library-authoring/create-library/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const useGetLibraryRestoreStatus = (taskId: string) => useQuery<GetLibrar
queryKey: libraryRestoreQueryKeys.restoreStatus(taskId),
queryFn: () => getLibraryRestoreStatus(taskId),
enabled: !!taskId, // Only run the query if taskId is provided
refetchInterval: (query) => (query.state.data?.state === LibraryRestoreStatus.Pending ? 2000 : false),
refetchInterval: (query) => (
(query.state.data?.state === LibraryRestoreStatus.Pending
|| query.state.data?.state === LibraryRestoreStatus.InProgress
) ? 2000 : false),
});

export const useCreateLibraryRestore = () => useMutation<CreateLibraryRestoreResponse, Error, File>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface GetLibraryRestoreStatusResponse {

export enum LibraryRestoreStatus {
Pending = 'Pending',
InProgress = 'In Progress',
Succeeded = 'Succeeded',
Failed = 'Failed',
}
Expand Down