fix(editor): read-only undo, upload session check, restore and submit guards

This commit is contained in:
bchanot committed 2026-11-04 18:06:40 +01:00
1 parent 5979cd59ec
commit 05c9b3e10b
20 files changed
+102 -33

No files matched your search

@@ -106,7 +106,7 @@ function DraftEditor({
}, [versionId, userId])
useEffect(() => useEditorStore.getState().setCanEdit(canEdit), [canEdit])
useLeaveGuard(useEditorStore(leaveGuardArmed))
useUndoShortcuts(canEdit && recovery === 'none')
useUndoShortcuts(mode === 'edit' && recovery === 'none')
if (status === 'failed' && failure !== null) {
if (failure === 'denied') return <AccessDenied />
+3 -1
View File
@@ -147,10 +147,12 @@ export async function registerAndUpload(
export async function downloadAndHold(
assetId: string,
sha256: string,
live: () => boolean,
): Promise<Step<null>> {
const client = getSupabaseClient()
if (!client) return fail({ code: 'sheet', kind: 'unavailable' })
const fetched = await fetchDrawing(client, { asset_id: assetId, sha256 })
if (!live()) return fail({ code: 'stale' })
if (!fetched.ok) return fail({ code: 'catalogue', failure: fetched.failure })
const held = useEditorStore.getState().addDrawing(fetched.drawing)
if (held.ok) return done(null)
@@ -193,7 +195,7 @@ export async function uploadDrawing(
const stored = await registerAndUpload(sheetId, drawing)
if (!live()) return fail({ code: 'stale' })
if (!stored.ok) return stored
const held = await downloadAndHold(stored.value, drawing.sha256)
const held = await downloadAndHold(stored.value, drawing.sha256, live)
if (!live()) return fail({ code: 'stale' })
return held.ok ? attachToView(viewId, stored.value) : held
}
+1 -1
View File
@@ -31,7 +31,7 @@ function replacedPatch(
documentText: text,
previewState: next,
handleVersion: state.handleVersion + 1,
unsaved: !sameDocument(text, state.savedText),
unsaved: state.staleBase || !sameDocument(text, state.savedText),
undo: history.undo,
redo: history.redo,
}
+1 -1
View File
@@ -164,7 +164,7 @@ export async function submit(api: StoreApi, note?: string): Promise<SubmitOutcom
}
const reviewId = await submitSheetReview(requireClient(), args)
if (api.get().session !== state.session) return blocked('session_changed')
api.set({ submitting: false })
api.set({ submitting: false, canEdit: false })
return { ok: true, reviewId }
} catch (error) {
return failedSubmit(api, state.session, error)
+2 -2
View File
@@ -174,7 +174,7 @@ function restoredPatch(
next: PreviewState,
attached: Attached,
): Partial<EditorState> {
const text = copyText(copy)
const text = JSON.stringify(next.document)
return {
documentText: text,
previewState: next,
@@ -183,7 +183,7 @@ function restoredPatch(
drawingFailures: { ...now.drawingFailures, ...attached.failures },
savedRevision: copy.revision,
staleBase: copy.revision < now.savedRevision,
unsaved: !sameDocument(text, now.savedText),
unsaved: copy.revision < now.savedRevision || !sameDocument(text, now.savedText),
...emptyHistory(),
...NO_RECOVERY,
}
+4 -4
View File
@@ -1205,8 +1205,8 @@ export const en: Dict = {
'editor.draft.status.revision': 'Revision {revision}',
'editor.draft.status.unsaved': 'unsaved changes',
'editor.draft.status.saving': 'Saving…',
'editor.draft.status.copy_quota': "Temporary local copy impossible (this tab's storage is full)",
'editor.draft.status.copy_cap': "Temporary local copy impossible: two other drafts already have a copy in this tab",
'editor.draft.status.copy_quota': "Temporary local copy impossible (tab full): not saved on the server",
'editor.draft.status.copy_cap': "Temporary local copy impossible (two other copies in this tab): not saved on the server",
'editor.draft.copy_kept': "A temporary local copy, limited to this tab, is kept; it is not saved on the server.",
'editor.draft.copy_not_kept': "No temporary local copy could be written in this tab: these changes are saved nowhere, neither in the tab nor on the server.",
'editor.draft.mode.narrow': 'Editing requires a screen at least 1,024 px wide.',
@@ -1574,8 +1574,8 @@ export const en: Dict = {
'editor.verification.issue.annotation.no_findings': 'This annotation is linked to no findings zone: a click on it will offer nothing.',
'editor.verification.issue.annotation.geometry.missing': 'This annotation has no geometry.',
'editor.verification.issue.annotation.geometry.out_of_frame': 'This annotation is not entirely inside the frame of its view.',
'editor.verification.issue.annotation.geometry.too_small': 'This annotation shows too small on the phone preview.',
'editor.verification.issue.annotation.geometry.interior_too_small': 'The inside of this zone is too narrow to tap on the phone preview.',
'editor.verification.issue.annotation.geometry.too_small': 'A marker is too small to tap on a phone.',
'editor.verification.issue.annotation.geometry.interior_too_small': "A zone's interior is too narrow to tap on a phone.",
'editor.verification.issue.region.code.duplicate': 'Two vertebral regions have the same code.',
'editor.verification.issue.region.count_range.invalid': 'The usual count of this region is outside the stated variation.',
'editor.verification.issue.category.id.duplicate': 'Two annotation categories have the same id.',
+4 -4
View File
@@ -1236,8 +1236,8 @@ export const fr: Dict = {
'editor.draft.status.revision': 'Révision {revision}',
'editor.draft.status.unsaved': 'modifications non enregistrées',
'editor.draft.status.saving': 'Enregistrement…',
'editor.draft.status.copy_quota': "Copie locale temporaire impossible (stockage de l'onglet plein)",
'editor.draft.status.copy_cap': "Copie locale temporaire impossible : deux autres brouillons ont déjà une copie dans cet onglet",
'editor.draft.status.copy_quota': "Copie locale temporaire impossible (onglet plein) : non enregistré sur le serveur",
'editor.draft.status.copy_cap': "Copie locale temporaire impossible (deux autres copies dans cet onglet) : non enregistré sur le serveur",
'editor.draft.copy_kept': "Une copie locale temporaire, propre à cet onglet, est conservée ; elle n'est pas enregistrée sur le serveur.",
'editor.draft.copy_not_kept': "Aucune copie locale temporaire n'a pu être écrite dans cet onglet : ces modifications ne sont enregistrées nulle part, ni dans l'onglet ni sur le serveur.",
'editor.draft.mode.narrow': "L'édition nécessite une largeur d'écran d'au moins 1 024 px.",
@@ -1605,8 +1605,8 @@ export const fr: Dict = {
'editor.verification.issue.annotation.no_findings': "Cette annotation n'est liée à aucune zone de constats : un clic dessus ne proposera rien.",
'editor.verification.issue.annotation.geometry.missing': "Cette annotation n'a pas de géométrie.",
'editor.verification.issue.annotation.geometry.out_of_frame': "Cette annotation n'est pas entièrement dans le cadre de sa vue.",
'editor.verification.issue.annotation.geometry.too_small': "Cette annotation s'affiche trop petite sur l'aperçu téléphone.",
'editor.verification.issue.annotation.geometry.interior_too_small': "L'intérieur de cette zone est trop étroit pour être touché sur l'aperçu téléphone.",
'editor.verification.issue.annotation.geometry.too_small': "Un repère est trop petit pour être touché sur mobile.",
'editor.verification.issue.annotation.geometry.interior_too_small': "L'intérieur d'une zone est trop étroit pour être touché sur mobile.",
'editor.verification.issue.region.code.duplicate': 'Deux régions vertébrales ont le même code.',
'editor.verification.issue.region.count_range.invalid': "Le nombre habituel de cette région n'est pas dans la variation indiquée.",
'editor.verification.issue.category.id.duplicate': "Deux catégories d'annotation ont le même identifiant.",