feat(editor): add View DDL action to query editor context menu (#280)
This commit is contained in:
parent
cebb39cb80
commit
ff1559f018
|
|
@ -11,6 +11,7 @@ import EditorToolbar from "@/components/layout/EditorToolbar.vue";
|
|||
import ContentArea from "@/components/layout/ContentArea.vue";
|
||||
import AppDialogs from "@/components/layout/AppDialogs.vue";
|
||||
import WelcomeScreen from "@/components/layout/WelcomeScreen.vue";
|
||||
import DdlViewDialog from "@/components/objects/DdlViewDialog.vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
|
|
@ -68,7 +69,7 @@ import { countAvailableAgentDriverUpdates, type AgentDriverUpdateBadgeState } fr
|
|||
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/safeStorage";
|
||||
import { rankSavedSqlHistory } from "@/lib/savedSqlHistory";
|
||||
import { isSchemaAware, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseFeatureSupport";
|
||||
import { connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection } from "@/lib/jdbcDialect";
|
||||
import { codeMirrorSqlDialect, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection } from "@/lib/jdbcDialect";
|
||||
import { detectDatabaseFileType } from "@/lib/databaseFileDetection";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
|
@ -110,6 +111,7 @@ const setupRequired = ref(false);
|
|||
const showConnectionDialog = ref(false);
|
||||
const connectionDialogPrefill = ref<ConnectionDeepLinkDraft | null>(null);
|
||||
const showSettingsDialog = ref(false);
|
||||
const showQueryEditorDdlDialog = ref(false);
|
||||
const showDriverStore = ref(false);
|
||||
const showQuickOpen = ref(false);
|
||||
const agentDriverUpdateCount = ref(0);
|
||||
|
|
@ -128,6 +130,7 @@ const cursorPos = ref(0);
|
|||
const formatSqlRequest = ref<{ id: number; tabId: string } | null>(null);
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const newQueryContextSource = ref<"tab" | "sidebar">("tab");
|
||||
const queryEditorDdlTarget = ref<{ connectionId: string; database: string; schema?: string; tableName: string } | null>(null);
|
||||
const showSaveSqlDialog = ref(false);
|
||||
const saveSqlName = ref("");
|
||||
const saveSqlFolderId = ref("");
|
||||
|
|
@ -232,6 +235,10 @@ const updateNotificationsEnabled = computed(() => settingsStore.editorSettings.u
|
|||
const toolbarAgentDriverUpdateCount = computed(() => (updateNotificationsEnabled.value ? agentDriverUpdateCount.value : 0));
|
||||
const toolbarHasUpdateAvailable = computed(() => updateNotificationsEnabled.value && hasUpdateAvailable.value);
|
||||
const hasSqlFileConnections = computed(() => connectionStore.connections.some((c) => supportsSqlFileExecution(c.db_type)));
|
||||
const queryEditorDdlDialect = computed(() => {
|
||||
if (!queryEditorDdlTarget.value?.connectionId) return "mysql";
|
||||
return codeMirrorSqlDialect(effectiveDatabaseTypeForConnection(connectionStore.getConfig(queryEditorDdlTarget.value.connectionId)));
|
||||
});
|
||||
const connectionStats = computed(() => ({
|
||||
total: connectionStore.connections.length,
|
||||
connected: connectionStore.connectedIds.size,
|
||||
|
|
@ -830,6 +837,13 @@ async function onViewTableData(tableName: string) {
|
|||
}
|
||||
}
|
||||
|
||||
function onViewTableDdl(tableName: string) {
|
||||
const target = tableTargetFromActiveTab(tableName);
|
||||
if (!target) return;
|
||||
queryEditorDdlTarget.value = target;
|
||||
showQueryEditorDdlDialog.value = true;
|
||||
}
|
||||
|
||||
async function changeActiveConnection(connectionId: string) {
|
||||
const tab = activeTab.value;
|
||||
if (!tab) return;
|
||||
|
|
@ -1423,6 +1437,7 @@ onUnmounted(() => {
|
|||
@execute-sql="onExecuteSql"
|
||||
@click-table="onClickTable"
|
||||
@view-table-data="onViewTableData"
|
||||
@view-table-ddl="onViewTableDdl"
|
||||
@open-object-table="
|
||||
(target) =>
|
||||
activeTab &&
|
||||
|
|
@ -1592,6 +1607,7 @@ onUnmounted(() => {
|
|||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<DdlViewDialog v-if="queryEditorDdlTarget" v-model:open="showQueryEditorDdlDialog" :connection-id="queryEditorDdlTarget.connectionId" :database="queryEditorDdlTarget.database" :schema="queryEditorDdlTarget.schema" :table-name="queryEditorDdlTarget.tableName" :dialect="queryEditorDdlDialect" />
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated, watch, shallowRef, computed, nextTick } from "vue";
|
||||
import { Play, Copy, Table2, TextSelect } from "@lucide/vue";
|
||||
import { FileCode, Play, Copy, Table2, TextSelect } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { CompletionContext } from "@codemirror/autocomplete";
|
||||
import type { EditorView as EditorViewType } from "@codemirror/view";
|
||||
|
|
@ -76,6 +76,7 @@ const emit = defineEmits<{
|
|||
save: [];
|
||||
clickTable: [tableName: string];
|
||||
viewTableData: [tableName: string];
|
||||
viewTableDdl: [tableName: string];
|
||||
clickColumn: [columns: Array<{ name: string; table: string; schema?: string }>, error?: string | undefined];
|
||||
closeColumnPanel: [];
|
||||
viewportChange: [viewport: { scrollTop: number; scrollLeft: number }];
|
||||
|
|
@ -483,6 +484,12 @@ function openTableFromContextMenu() {
|
|||
focusEditor();
|
||||
}
|
||||
|
||||
function openTableDdlFromContextMenu() {
|
||||
if (!contextTableName.value) return;
|
||||
emit("viewTableDdl", contextTableName.value);
|
||||
focusEditor();
|
||||
}
|
||||
|
||||
function selectSqlLineFromGutter(currentView: EditorViewType, line: { from: number; to: number }, event: Event): boolean {
|
||||
if (!(event instanceof MouseEvent) || event.button !== 0) return false;
|
||||
event.preventDefault();
|
||||
|
|
@ -508,6 +515,12 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => [
|
|||
disabled: !contextTableName.value,
|
||||
icon: Table2,
|
||||
},
|
||||
{
|
||||
label: t("contextMenu.viewDdl"),
|
||||
action: openTableDdlFromContextMenu,
|
||||
disabled: !contextTableName.value,
|
||||
icon: FileCode,
|
||||
},
|
||||
{ label: "", separator: true },
|
||||
{
|
||||
label: t("editor.contextMenu.copySelection"),
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ const emit = defineEmits<{
|
|||
executeSql: [sql: string];
|
||||
clickTable: [tableName: string];
|
||||
viewTableData: [tableName: string];
|
||||
viewTableDdl: [tableName: string];
|
||||
openObjectTable: [target: { tableName: string; schema?: string }];
|
||||
objectSchemaChange: [schema: string | undefined];
|
||||
structureEditorSaved: [commentChanged: boolean];
|
||||
|
|
@ -445,6 +446,10 @@ function onHandleViewTableData(tableName: string) {
|
|||
emit("viewTableData", tableName);
|
||||
}
|
||||
|
||||
function onHandleViewTableDdl(tableName: string) {
|
||||
emit("viewTableDdl", tableName);
|
||||
}
|
||||
|
||||
function onHandleCloseColumnPanel() {
|
||||
showColumnInfo.value = false;
|
||||
columnInfoColumns.value = [];
|
||||
|
|
@ -555,6 +560,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget, requestQueryEditorExe
|
|||
@save="emit('saveSql')"
|
||||
@click-table="onHandleClickTable"
|
||||
@view-table-data="onHandleViewTableData"
|
||||
@view-table-ddl="onHandleViewTableDdl"
|
||||
@click-column="onHandleClickColumn"
|
||||
@close-column-panel="onHandleCloseColumnPanel"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue