MCPcopy Create free account
hub / github.com/bytebase/bytebase / useWorksheetAndTab

Function useWorksheetAndTab

frontend/src/react/hooks/useWorksheetAndTab.ts:25–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23 * and in-place edits re-render.
24 */
25export const useWorksheetAndTab = (): WorksheetAndTab => {
26 const currentTab = useCurrentSQLEditorTab();
27 const worksheetName = currentTab?.worksheet;
28 const me = useCurrentUser();
29
30 const currentSheet = useAppStore((s) =>
31 worksheetName ? s.getWorksheetByName(worksheetName) : undefined
32 );
33
34 const isCreator = currentSheet
35 ? extractUserEmail(currentSheet.creator) === me.email
36 : false;
37
38 let isReadOnly = false;
39 if (currentSheet) {
40 // Incomplete sheets are read-only (e.g. a 100MB sheet from an issue
41 // task whose content wasn't fully loaded).
42 const statement = getSheetStatement(currentSheet);
43 if (getStatementSize(statement) !== currentSheet.contentSize) {
44 isReadOnly = true;
45 } else {
46 isReadOnly = !isWorksheetWritableV1(currentSheet);
47 }
48 }
49
50 return { currentSheet, isCreator, isReadOnly };
51};

Callers 2

EditorActionFunction · 0.90
SQLEditorFunction · 0.90

Calls 7

useCurrentSQLEditorTabFunction · 0.90
useCurrentUserFunction · 0.90
extractUserEmailFunction · 0.90
getSheetStatementFunction · 0.90
getStatementSizeFunction · 0.90
isWorksheetWritableV1Function · 0.90
useAppStoreFunction · 0.50

Tested by

no test coverage detected