feat(home): import messages open with a full-restoration or partial-recovery headline; BDR-040 recorded
This commit is contained in:
1 parent
de2bd0437e
commit
62b8a43e09
7 files changed
+106
-23
No files matched your search
@@ -18,11 +18,11 @@ import { useT } from '@/i18n/useT'
|
||||
type Translate = ReturnType<typeof useT>
|
||||
|
||||
/**
|
||||
* The lines of the one alert shown after a successful import (STEP6 §16):
|
||||
* a lossy v2 migration, the archive kept, the snapshot dropped with its
|
||||
* The detail lines of the import alert (STEP6 §16), in a fixed order: a
|
||||
* lossy v2 migration, the archive kept, the snapshot dropped with its
|
||||
* reason, the rebase onto the current sheet. Empty when nothing applies.
|
||||
*/
|
||||
function importMessages(
|
||||
function importDetailLines(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
t: Translate,
|
||||
@@ -48,6 +48,42 @@ function importMessages(
|
||||
return lines
|
||||
}
|
||||
|
||||
/**
|
||||
* Degraded recovery: something the practitioner must check. A rejected
|
||||
* snapshot, a migration or a rebase that lost items. A rebase that resolved
|
||||
* everything is a complete restoration on a different sheet.
|
||||
*/
|
||||
function isDegradedImport(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
): boolean {
|
||||
const lost = outcome.unresolvedFindings + outcome.unresolvedZones
|
||||
const rebaseLost = rebase.unresolvedZones + rebase.unresolvedFindings
|
||||
return (
|
||||
outcome.snapshotRejected !== undefined ||
|
||||
(outcome.migrated && lost > 0) ||
|
||||
(rebase.rebased && rebaseLost > 0)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The one alert shown after a successful import: a headline that says
|
||||
* whether the restoration is complete or partial, then the detail lines.
|
||||
* Empty (no alert) when there is nothing to say: a bare v3 on the same sheet.
|
||||
*/
|
||||
function importMessages(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
t: Translate,
|
||||
): string[] {
|
||||
const details = importDetailLines(outcome, rebase, t)
|
||||
if (details.length === 0) return []
|
||||
const headline = isDegradedImport(outcome, rebase)
|
||||
? t('home.import.degraded')
|
||||
: t('home.import.complete')
|
||||
return [headline, ...details]
|
||||
}
|
||||
|
||||
/** The error line under the import button, by ImportError kind. */
|
||||
function importErrorMessage(err: unknown, t: Translate): string {
|
||||
if (!(err instanceof ImportError)) return t('home.import.error_generic')
|
||||
|
||||
Reference in new issue
Block a user