Skip to content

Build your personal knowledge base with Trilium Notes

fix(spreadsheet): read-only not working

Elian Doran1a29db8607de
diff --git a/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx b/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx
index f6bb339a7e..034425279a 100644
--- a/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx
+++ b/apps/client/src/widgets/type_widgets/spreadsheet/Spreadsheet.tsx
@@ -41,7 +41,7 @@ function SpreadsheetEditor({ note, noteContext, readOnly }: TypeWidgetProps & {
useInitializeSpreadsheet(containerRef, apiRef, readOnly);
useDarkMode(apiRef);
- usePersistence(note, noteContext, apiRef, containerRef, readOnly);
+ usePersistence(note, noteContext, apiRef, containerRef);
useSearchIntegration(apiRef);
useFixRadixPortals();
@@ -127,6 +127,18 @@ function useInitializeSpreadsheet(containerRef: MutableRef<HTMLDivElement | null
UniverSheetsConditionalFormattingPreset()
]
});
+ if (readOnly) {
+ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {
+ if (stage === univerAPI.Enum.LifecycleStages.Rendered) {
+ const workbook = univerAPI.getActiveWorkbook();
+ if (!workbook) return;
+
+ workbook.disableSelection();
+ workbook.getWorkbookPermission().setReadOnly();
+ }
+ });
+ }
+
apiRef.current = univerAPI;
return () => univerAPI.dispose();
}, [ apiRef, containerRef, readOnly ]);
diff --git a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx
index b3717c9ace..ee7bad5d78 100644
--- a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx
+++ b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx
@@ -18,7 +18,7 @@ interface SpreadsheetViewState {
scrollCol?: number;
}
-export default function usePersistence(note: FNote, noteContext: NoteContext | null | undefined, apiRef: MutableRef<FUniver | undefined>, containerRef: MutableRef<HTMLDivElement | null>, readOnly: boolean) {
+export default function usePersistence(note: FNote, noteContext: NoteContext | null | undefined, apiRef: MutableRef<FUniver | undefined>, containerRef: MutableRef<HTMLDivElement | null>) {
const changeListener = useRef<IDisposable>(null);
const pendingContent = useRef<string | null>(null);
@@ -90,12 +90,6 @@ export default function usePersistence(note: FNote, noteContext: NoteContext | n
}
const workbook = univerAPI.createWorkbook(workbookData);
- if (readOnly) {
- workbook.disableSelection();
- const permission = workbook.getPermission();
- permission.setWorkbookEditPermission(workbook.getId(), false);
- permission.setPermissionDialogVisible(false);
- }
restoreViewState(workbook, viewState);