fix(store): banner on a refused archive write, rescue download kept alive
This commit is contained in:
1 parent
a37c50b9ee
commit
c97b0e7c67
4 files changed
+29
-8
No files matched your search
@@ -18,12 +18,19 @@ export interface HeldSessionPanelProps {
|
||||
|
||||
type Pending = { action: 'discard'; text: SessionText } | { action: 'open' }
|
||||
|
||||
const REVOKE_DELAY_MS = 30_000
|
||||
|
||||
const FILE_STEM: Record<SessionText, string> = {
|
||||
draft: 'faunosteo-brouillon',
|
||||
archive: 'faunosteo-archive',
|
||||
}
|
||||
|
||||
/** Saves the stored text verbatim (it is JSON.stringify output: ASCII escapes, lossless). */
|
||||
/**
|
||||
* Saves the stored text verbatim. It is JSON.stringify output, whose lone surrogates are
|
||||
* `\uXXXX` escapes, so the UTF-8 Blob is lossless. This copy may be the last one before
|
||||
* a deletion: the anchor is attached while clicked and the URL revoked later, since some
|
||||
* engines (WebKit) cancel a download whose URL is revoked at once.
|
||||
*/
|
||||
function downloadCopy(text: SessionText): void {
|
||||
const raw = readSessionText(text)
|
||||
if (raw === null) return
|
||||
@@ -31,8 +38,10 @@ function downloadCopy(text: SessionText): void {
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `${FILE_STEM[text]}-${todayIso()}.json`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(url), REVOKE_DELAY_MS)
|
||||
}
|
||||
|
||||
function rowLabelKey(item: HeldText): string {
|
||||
|
||||
@@ -39,9 +39,11 @@ import {
|
||||
* The per-tab draft is mirrored through the persistence adapter and restored
|
||||
* once the sheet is known; the archive an import brought along is kept
|
||||
* beside the report and written only when the session starts or ends.
|
||||
* A session text this page has not read, or whose safety copy failed, is
|
||||
* never removed or overwritten implicitly: restore holds it, and a new
|
||||
* session (new report, import) is refused until the practitioner resolves it.
|
||||
* A session text whose safety copy failed is never removed or overwritten
|
||||
* implicitly: restore holds it, and a new session (new report, import) is
|
||||
* refused until the practitioner resolves it. A new session reads any draft
|
||||
* this page never opened first: an unreadable one is set aside, a readable
|
||||
* one is replaced as it always was.
|
||||
*/
|
||||
|
||||
export type { NewReportDraft }
|
||||
@@ -265,10 +267,13 @@ export function createReportStore(
|
||||
archives: ArchivePersistence,
|
||||
) {
|
||||
/** The archive mirror is explicit: these actions are the session's edges. */
|
||||
// The archive of this session could not be written: the tab's copy lacks it (banner).
|
||||
let archiveRefused = false
|
||||
const withArchive = (patch: Patch, archive: ReportArchiveEnvelope | null) => {
|
||||
// A refused write must not leave the replaced session's archive beside the new draft:
|
||||
// the next restore would pair them. That archive belongs to the session being replaced.
|
||||
if (!archives.save(archive)) archives.save(null)
|
||||
archiveRefused = !archives.save(archive)
|
||||
if (archiveRefused) archives.save(null)
|
||||
return { ...patch, archive }
|
||||
}
|
||||
|
||||
@@ -386,7 +391,7 @@ export function createReportStore(
|
||||
// The mirror follows the report only: an unrelated change never writes or removes the draft.
|
||||
store.subscribe((state, prev) => {
|
||||
if (state.report === prev.report) return
|
||||
const failed = !persistence.save(state.report)
|
||||
const failed = !persistence.save(state.report) || archiveRefused
|
||||
if (failed !== state.saveFailed) store.setState({ saveFailed: failed })
|
||||
})
|
||||
return store
|
||||
|
||||
@@ -309,6 +309,10 @@ describe('the draft mirror', () => {
|
||||
store().hydrateImport({ report: second, archive: archiveEnvelope(sheet, second) }, sheet)
|
||||
expect(sessionStorage.getItem(ARCHIVE_KEY)).toBeNull()
|
||||
expect(JSON.parse(sessionStorage.getItem(DRAFT_KEY)!).conclusion).toBe('second')
|
||||
// The tab's copy lacks the imported archive: the banner says so until a write succeeds.
|
||||
expect(store().saveFailed).toBe(true)
|
||||
store().setConclusion('edited')
|
||||
expect(store().saveFailed).toBe(true)
|
||||
})
|
||||
|
||||
it('a deletion request is ignored while a report is open', () => {
|
||||
|
||||
@@ -639,7 +639,10 @@ application itself builds.
|
||||
a refused write keeps the previous text and shows the `editor.save_failed`
|
||||
banner until a write succeeds; a refused archive write at a new session
|
||||
removes the replaced session's archive rather than leave it paired with
|
||||
the new draft.
|
||||
the new draft, and shows the same banner (the tab's copy lacks it). The
|
||||
rescue download keeps its object URL alive 30 s (WebKit cancels a
|
||||
download whose URL is revoked at once; the PDF export still does that,
|
||||
follow-up).
|
||||
4. A core that cannot load leaves the editor on the degraded notice
|
||||
(before R2 a failed sheet chunk left it on "loading").
|
||||
5. Home and `/new` no longer load the sheet into memory on mount.
|
||||
|
||||
Reference in new issue
Block a user