= ({
isV2Ui,
currentConnectionId,
currentDb,
queryCapableConnections,
dbList,
maxRows,
sqlEditorCommitMode,
sqlEditorAutoCommitDelayMs,
pendingTransactionToolbar,
runQueryShortcutBinding,
saveQueryShortcutBinding,
formatSqlShortcutBinding,
triggerSqlAiCompletionShortcutBinding,
toggleQueryResultsPanelShortcutBinding,
activeShortcutPlatform,
isResultPanelVisible,
loading,
saveMoreMenuItems,
formatSettingsMenu,
onConnectionChange,
onDatabaseChange,
onMaxRowsChange,
onCommitModeChange,
onAutoCommitDelayMsChange,
onCaptureEditorCursorPosition,
onRun,
onCancel,
onQuickSave,
onFindInEditor,
onFormat,
onTriggerSqlAiCompletion,
onToggleResultPanelVisibility,
onAIAction,
}) => {
const i18n = useOptionalI18n();
const t = i18n?.t ?? defaultTranslate;
const baseMoreMenuItems = saveMoreMenuItems ?? [];
const connectionSelectOptions: FullNameSelectOption[] =
queryCapableConnections.map((connection) => ({
label: connection.name,
value: connection.id,
title: "",
fullName: connection.name,
}));
const databaseSelectOptions: FullNameSelectOption[] = dbList.map((db) => ({
label: db,
value: db,
title: "",
fullName: db,
}));
const toggleResultPanelShortcutLabel =
toggleQueryResultsPanelShortcutBinding.enabled &&
toggleQueryResultsPanelShortcutBinding.combo
? getShortcutDisplayLabel(
toggleQueryResultsPanelShortcutBinding.combo,
activeShortcutPlatform,
)
: "";
const toggleResultPanelTitle =
toggleQueryResultsPanelShortcutBinding.enabled &&
toggleQueryResultsPanelShortcutBinding.combo
? t(
isResultPanelVisible
? "query_editor.action.hide_results_panel_with_shortcut"
: "query_editor.action.show_results_panel_with_shortcut",
{ shortcut: toggleResultPanelShortcutLabel },
)
: isResultPanelVisible
? t("query_editor.action.hide_results_panel")
: t("query_editor.action.show_results_panel");
const formatSqlTitle =
formatSqlShortcutBinding.enabled && formatSqlShortcutBinding.combo
? t("query_editor.action.format_sql_with_shortcut", {
shortcut: getShortcutDisplayLabel(
formatSqlShortcutBinding.combo,
activeShortcutPlatform,
),
})
: t("query_editor.action.format_sql");
const findInEditorShortcutCombo =
activeShortcutPlatform === "mac" ? "Meta+F" : "Ctrl+F";
const findInEditorTitle = t(
"query_editor.action.find_in_editor_with_shortcut",
{
shortcut: getShortcutDisplayLabel(
findInEditorShortcutCombo,
activeShortcutPlatform,
),
},
);
const triggerSqlAiCompletionLabel =
triggerSqlAiCompletionShortcutBinding.enabled &&
triggerSqlAiCompletionShortcutBinding.combo
? `${t("app.shortcuts.action.triggerSqlAiCompletion.label")} ยท ${getShortcutDisplayLabel(
triggerSqlAiCompletionShortcutBinding.combo,
activeShortcutPlatform,
)}`
: t("app.shortcuts.action.triggerSqlAiCompletion.label");
const aiMenuItems: MenuProps["items"] = [
{
key: "ai-inline-completion",
label: triggerSqlAiCompletionLabel,
icon: ,
onClick: onTriggerSqlAiCompletion,
},
{ type: "divider" as const },
{
key: "ai-generate",
label: t("query_editor.action.ai_text_to_sql_menu"),
icon: ,
onClick: () => onAIAction("generate"),
},
{
key: "ai-explain",
label: t("query_editor.action.ai_explain_sql_menu"),
icon: ,
onClick: () => onAIAction("explain"),
},
{
key: "ai-optimize",
label: t("query_editor.action.ai_optimize_sql_menu"),
icon: ,
onClick: () => onAIAction("optimize"),
},
{ type: "divider" as const },
{
key: "ai-schema",
label: t("query_editor.action.ai_schema_analysis"),
icon: ,
onClick: () => onAIAction("schema"),
},
];
const moreMenuItems: MenuProps["items"] = isV2Ui
? [
...baseMoreMenuItems,
...(baseMoreMenuItems.length > 0 ? [{ type: "divider" as const }] : []),
{
key: "toggle-result-panel",
label: toggleResultPanelTitle,
icon: isResultPanelVisible ? (
) : (
),
onClick: onToggleResultPanelVisibility,
},
]
: baseMoreMenuItems;
const selects = (
);
const actions = (
}
onMouseDown={onCaptureEditorCursorPosition}
onClick={onRun}
loading={loading}
>
{t("query_editor.action.run")}
{loading && (
}
onClick={onCancel}
>
{t("query_editor.action.stop")}
)}
{isV2Ui && pendingTransactionToolbar}
} onClick={onQuickSave}>
{t("query_editor.action.save")}
}
style={{ color: "#818cf8" }}
onMouseDown={onCaptureEditorCursorPosition}
onClick={onTriggerSqlAiCompletion}
>
AI
}
aria-label="AI more actions"
/>
} onClick={onFindInEditor}>
{t("query_editor.action.find_in_editor")}
} onClick={onFormat}>
{t("query_editor.action.format")}
}
/>
{!isV2Ui && (
:
}
onClick={onToggleResultPanelVisibility}
>
{t("query_editor.action.results")}
)}
);
if (!isV2Ui) {
return (
{selects}
{actions}
);
}
return (
);
};
export default QueryEditorToolbar;