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

Function EditorAction

frontend/src/react/components/sql-editor/EditorAction.tsx:44–252  ·  view source on GitHub ↗
({ onExecute }: Props)

Source from the content-addressed store, hash-verified

42 * ADMIN mode where the Run button is not rendered.
43 */
44export function EditorAction({ onExecute }: Props) {
45 const { t } = useTranslation();
46 const { currentSheet: currentWorksheet } = useWorksheetAndTab();
47 const { instance } = useConnectionOfCurrentSQLEditorTab();
48
49 const [shareOpen, setShareOpen] = useState(false);
50
51 // Zustand selectors read fields directly off the active tab, so
52 // in-place mutations (statement / status / connection.* via immer
53 // produce) emit fresh slices and propagate through React without a
54 // per-field workaround.
55 const currentTab = useCurrentSQLEditorTab();
56 const tabStatement = useSQLEditorTabState(
57 (s) => s.tabsById.get(s.currentTabId)?.statement ?? ""
58 );
59 const tabStatus = useSQLEditorTabState(
60 (s) => s.tabsById.get(s.currentTabId)?.status
61 );
62 const tabMode = useSQLEditorTabState(
63 (s) => s.tabsById.get(s.currentTabId)?.mode
64 );
65 const tabWorksheet = useSQLEditorTabState(
66 (s) => s.tabsById.get(s.currentTabId)?.worksheet ?? ""
67 );
68 const tabConnectionTable = useSQLEditorTabState(
69 (s) => s.tabsById.get(s.currentTabId)?.connection.table ?? ""
70 );
71 const isDisconnected = useIsDisconnected();
72 const resultRowsLimit = useSQLEditorEditorState((s) => s.resultRowsLimit);
73
74 const isAdminMode = tabMode === "ADMIN";
75 const showSheetsFeature = tabMode === "WORKSHEET";
76 const isEmptyStatement = !currentTab || tabStatement === "";
77
78 const queryTip =
79 instance.engine === Engine.COSMOSDB && !tabConnectionTable
80 ? t("database.table.select-tip")
81 : "";
82
83 const allowQuery = (() => {
84 if (isDisconnected) return false;
85 if (isEmptyStatement) return false;
86 if (instance.engine === Engine.COSMOSDB) {
87 return !!tabConnectionTable;
88 }
89 return true;
90 })();
91
92 const canWriteSheet = (() => {
93 if (!tabWorksheet) return false;
94 const sheet = useAppStore.getState().getWorksheetByName(tabWorksheet);
95 return sheet ? isWorksheetWritableV1(sheet) : false;
96 })();
97
98 const allowSave = (() => {
99 if (!showSheetsFeature || !currentTab) return false;
100 if (tabWorksheet) {
101 if (!canWriteSheet) return false;

Callers

nothing calls this directly

Calls 12

useWorksheetAndTabFunction · 0.90
useCurrentSQLEditorTabFunction · 0.90
useSQLEditorTabStateFunction · 0.90
useIsDisconnectedFunction · 0.90
useSQLEditorEditorStateFunction · 0.90
isWorksheetWritableV1Function · 0.90
cnFunction · 0.90
keyboardShortcutStrFunction · 0.90
exitAdminModeFunction · 0.85
tFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected