From 5d8827e4aa35e8d8cce39a9087b09cb16556d1fb Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Wed, 12 Nov 2025 00:28:41 +0000 Subject: [PATCH] warnings --- .../tools/pdfJsonEditor/PdfJsonEditorView.tsx | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/frontend/src/proprietary/components/tools/pdfJsonEditor/PdfJsonEditorView.tsx b/frontend/src/proprietary/components/tools/pdfJsonEditor/PdfJsonEditorView.tsx index 80ca0e661..fc848b28c 100644 --- a/frontend/src/proprietary/components/tools/pdfJsonEditor/PdfJsonEditorView.tsx +++ b/frontend/src/proprietary/components/tools/pdfJsonEditor/PdfJsonEditorView.tsx @@ -10,6 +10,7 @@ import { Divider, FileButton, Group, + Modal, Pagination, Progress, ScrollArea, @@ -320,6 +321,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => { const [fontFamilies, setFontFamilies] = useState>(new Map()); const [autoScaleText, setAutoScaleText] = useState(true); const [textScales, setTextScales] = useState>(new Map()); + const [pendingModeChange, setPendingModeChange] = useState(null); const measurementKeyRef = useRef(''); const containerRef = useRef(null); const editorRefs = useRef>(new Map()); @@ -356,6 +358,27 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => { onGroupingModeChange, } = data; + const handleModeChangeRequest = useCallback((newMode: GroupingMode) => { + if (hasChanges && newMode !== externalGroupingMode) { + // Show confirmation dialog + setPendingModeChange(newMode); + } else { + // No changes, switch immediately + onGroupingModeChange(newMode); + } + }, [hasChanges, externalGroupingMode, onGroupingModeChange]); + + const handleConfirmModeChange = useCallback(() => { + if (pendingModeChange) { + onGroupingModeChange(pendingModeChange); + setPendingModeChange(null); + } + }, [pendingModeChange, onGroupingModeChange]); + + const handleCancelModeChange = useCallback(() => { + setPendingModeChange(null); + }, []); + const resolveFont = (fontId: string | null | undefined, pageIndex: number | null | undefined): PdfJsonFont | null => { if (!fontId || !pdfDocument?.fonts) { return null; @@ -1044,7 +1067,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => { {t('pdfJsonEditor.title', 'PDF JSON Editor')} - {hasChanges && {t('pdfJsonEditor.badges.unsaved', 'Edited')}} + {hasChanges && {t('pdfJsonEditor.badges.unsaved', 'Edited')}} @@ -1152,7 +1175,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => { onGroupingModeChange(value as GroupingMode)} + onChange={(value) => handleModeChangeRequest(value as GroupingMode)} data={[ { label: t('pdfJsonEditor.groupingMode.auto', 'Auto'), value: 'auto' }, { label: t('pdfJsonEditor.groupingMode.paragraph', 'Paragraph'), value: 'paragraph' }, @@ -1754,6 +1777,31 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => { )} + + {/* Mode Change Confirmation Modal */} + + + + {t( + 'pdfJsonEditor.modeChange.warning', + 'Changing the text grouping mode will reset all unsaved changes. Are you sure you want to continue?' + )} + + + + + + + ); };