From 8017155a0d71cad37798fff4a2f8f1482e47c0e9 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Tue, 21 Oct 2025 22:26:44 -0500 Subject: [PATCH 1/2] feat: Add error messages for partial migration --- .../LegacyLibMigrationPage.test.tsx | 2 +- .../data/api.mocks.ts | 74 +++++++++++++++++++ src/legacy-libraries-migration/data/api.ts | 1 + src/legacy-libraries-migration/messages.ts | 12 ++- .../LibraryAuthoringPage.test.tsx | 28 ++++++- .../LibraryAuthoringPage.tsx | 15 +++- 6 files changed, 128 insertions(+), 4 deletions(-) diff --git a/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx b/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx index f019c16692..266ad3ceb7 100644 --- a/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx +++ b/src/legacy-libraries-migration/LegacyLibMigrationPage.test.tsx @@ -399,7 +399,7 @@ describe('', () => { expect(axiosMock.history.post[0].data).toBe( '{"sources":["library-v1:MBA+123","library-v1:UNIX+LG1","library-v1:MBA+1234"],"target":"lib:SampleTaxonomyOrg1:TL1","create_collections":true,"repeat_handling_strategy":"fork"}', ); - expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration failed.'); + expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration have failed'); }); it('should show help sidebar', async () => { diff --git a/src/legacy-libraries-migration/data/api.mocks.ts b/src/legacy-libraries-migration/data/api.mocks.ts index a4d2d583ff..2386fb474c 100644 --- a/src/legacy-libraries-migration/data/api.mocks.ts +++ b/src/legacy-libraries-migration/data/api.mocks.ts @@ -6,6 +6,10 @@ export async function mockGetMigrationStatus(migrationId: string): Promise', () => { }, }); - await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration failed.')); + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Legacy libraries migration have failed')); + }); + + it('Should show fail multiple legacy libraries in a migration', async () => { + render(, { + path, + routerProps: { + initialEntries: [ + `/library/${mockContentLibrary.libraryId}?migration_task=${mockGetMigrationStatus.migrationIdMultiple}`, + ], + }, + }); + + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('Multiple legacy libraries have failed')); + }); + + it('Should show fail one legacy library in a migration', async () => { + render(, { + path, + routerProps: { + initialEntries: [ + `/library/${mockContentLibrary.libraryId}?migration_task=${mockGetMigrationStatus.migrationIdOneLibrary}`, + ], + }, + }); + + await waitFor(() => expect(mockShowToast).toHaveBeenCalledWith('The legacy library with this key has failed: legacy-lib-1')); }); }); diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 90ee0040eb..c326445678 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -225,7 +225,20 @@ const LibraryAuthoringPage = ({ if (migrationId) { let deleteMigrationIdParam = false; if (migrationStatusData?.state === 'Succeeded') { - showToast(intl.formatMessage(migrationMessages.migrationSuccess)); + // Verify if there is some failed libraries + const failedMigrations = migrationStatusData.parameters.filter(item => item.isFailed); + if (failedMigrations.length > 1) { + showToast(intl.formatMessage(migrationMessages.migrationFailedMultiple)); + } else if (failedMigrations.length === 1) { + showToast(intl.formatMessage( + migrationMessages.migrationFailedOneLibrary, + { + key: failedMigrations[0].source, + }, + )); + } else { + showToast(intl.formatMessage(migrationMessages.migrationSuccess)); + } queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) }); deleteMigrationIdParam = true; } else if (migrationStatusData?.state === 'Failed') { From 39455f8ccb2b1c2c86e104ed01683a72302b19b8 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Wed, 22 Oct 2025 16:46:57 -0500 Subject: [PATCH 2/2] style: Coments added --- src/library-authoring/LibraryAuthoringPage.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index c326445678..63689635f6 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -225,7 +225,8 @@ const LibraryAuthoringPage = ({ if (migrationId) { let deleteMigrationIdParam = false; if (migrationStatusData?.state === 'Succeeded') { - // Verify if there is some failed libraries + // Check if any library migrations failed. + // A `Succeeded` state means that the bulk migration ended, but some libraries might have failed. const failedMigrations = migrationStatusData.parameters.filter(item => item.isFailed); if (failedMigrations.length > 1) { showToast(intl.formatMessage(migrationMessages.migrationFailedMultiple)); @@ -242,6 +243,7 @@ const LibraryAuthoringPage = ({ queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) }); deleteMigrationIdParam = true; } else if (migrationStatusData?.state === 'Failed') { + // A `Failed` state means that the entire bulk migration has failed. showToast(intl.formatMessage(migrationMessages.migrationFailed)); deleteMigrationIdParam = true; } else if (migrationStatusData?.state === 'Canceled') {