Keep bulk migration open when aborting during execution
This commit is contained in:
@@ -44,6 +44,7 @@ export const DEFAULT_MIGRATION_STATE: MigrationState = {
|
||||
startedAt: null,
|
||||
lastUpdatedAt: null,
|
||||
groupExpandState: {},
|
||||
isAborted: false,
|
||||
};
|
||||
|
||||
export const ENTRY_STATUS_TRANSLATION: Record<MigrationEntryStatus, MessageDescriptor> = {
|
||||
|
||||
@@ -128,6 +128,7 @@ export interface MigrationState {
|
||||
startedAt: number | null;
|
||||
lastUpdatedAt: number | null;
|
||||
groupExpandState: Partial<Record<MigrationEntryStatus, boolean>>;
|
||||
isAborted: boolean;
|
||||
}
|
||||
|
||||
export interface SourceItem extends SourceIdInfo, SourceNameInfo, SourceLanguageInfo, SourceIconInfo, SourceMetaInfo {}
|
||||
|
||||
@@ -209,8 +209,9 @@ export class MigrationManager {
|
||||
);
|
||||
case MigrationPhase.MIGRATING:
|
||||
return (
|
||||
MigrationManager.getState().isAborted ||
|
||||
MigrationManager.getState().migrationProgress.completed ===
|
||||
MigrationManager.getState().migrationProgress.total
|
||||
MigrationManager.getState().migrationProgress.total
|
||||
);
|
||||
default:
|
||||
return false;
|
||||
@@ -470,13 +471,27 @@ export class MigrationManager {
|
||||
}
|
||||
}
|
||||
|
||||
static async abort(reason: unknown = 'abort'): Promise<boolean> {
|
||||
static async stop(reason: unknown = 'stopped'): Promise<boolean> {
|
||||
if (!(await MigrationManager.confirmAbort())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MigrationManager.abortAndResetAbortController(reason);
|
||||
|
||||
MigrationManager.updateState((draft) => {
|
||||
draft.isAborted = true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static async abort(reason: unknown = 'abort'): Promise<boolean> {
|
||||
if (!MigrationManager.getState().isAborted && !(await MigrationManager.confirmAbort())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MigrationManager.abortAndResetAbortController(reason);
|
||||
|
||||
MigrationManager.reset();
|
||||
|
||||
ReactRouter.navigate(AppRoutes.browse.path(BrowseTab.MIGRATE));
|
||||
|
||||
@@ -23,9 +23,21 @@ export const MigrationExecute = () => {
|
||||
const entries = MigrationManager.useEntries();
|
||||
const progress = MigrationManager.useMigrationProgress();
|
||||
|
||||
useAppTitleAndAction(MigrationManager.isPhaseComplete() ? t`Migration complete` : t`Migrating`, undefined, [
|
||||
MigrationManager.isPhaseComplete(),
|
||||
]);
|
||||
useAppTitleAndAction(
|
||||
(() => {
|
||||
if (MigrationManager.getState().isAborted) {
|
||||
return t`Aborted`;
|
||||
}
|
||||
|
||||
if (MigrationManager.isPhaseComplete()) {
|
||||
return t`Migration complete`;
|
||||
}
|
||||
|
||||
return t`Migrating`;
|
||||
})(),
|
||||
undefined,
|
||||
[MigrationManager.isPhaseComplete()],
|
||||
);
|
||||
|
||||
const entryList = useMemo(() => Object.values(entries), [entries]);
|
||||
const migratingEntries = useMemo(
|
||||
@@ -140,7 +152,7 @@ export const MigrationExecute = () => {
|
||||
<MigrationContinueButton
|
||||
title={MigrationManager.isPhaseComplete() ? t`Done` : t`Abort`}
|
||||
onClick={() =>
|
||||
MigrationManager.isPhaseComplete() ? MigrationManager.reset() : MigrationManager.abort()
|
||||
MigrationManager.isPhaseComplete() ? MigrationManager.reset() : MigrationManager.stop()
|
||||
}
|
||||
/>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user