feat(desktop): add create actions to tree groups
This commit is contained in:
1 parent
0d89ee3fe9
commit
90c618dac6
5 files changed
+32
-1
No files matched your search
@@ -1436,7 +1436,7 @@ const supportsTruncate = computed(() => {
|
||||
const canCreateTable = computed(() => {
|
||||
const config = props.node.connectionId ? connectionStore.getConfig(props.node.connectionId) : undefined;
|
||||
return (
|
||||
(props.node.type === "database" || props.node.type === "schema") &&
|
||||
(props.node.type === "database" || props.node.type === "schema" || props.node.type === "group-tables") &&
|
||||
!!props.node.database &&
|
||||
supportsTableStructureEditing(config?.db_type)
|
||||
);
|
||||
@@ -1798,6 +1798,21 @@ function createTable() {
|
||||
queryStore.openTableStructure(node.connectionId, node.database, node.schema, "");
|
||||
}
|
||||
|
||||
function createView() {
|
||||
const node = props.node;
|
||||
if (!node.connectionId || !node.database) return;
|
||||
connectionStore.activeConnectionId = node.connectionId;
|
||||
const viewName = node.schema ? `${node.schema}.new_view` : "new_view";
|
||||
const tabId = queryStore.createTab(
|
||||
node.connectionId,
|
||||
node.database,
|
||||
t("contextMenu.createView"),
|
||||
"query",
|
||||
node.schema,
|
||||
);
|
||||
queryStore.updateSql(tabId, `CREATE VIEW ${viewName} AS\nSELECT\n *\nFROM table_name;\n`);
|
||||
}
|
||||
|
||||
async function saveFileContent(content: string, defaultFileName: string, filterName: string, filterExt: string) {
|
||||
if (isTauriRuntime()) {
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
@@ -3054,6 +3069,18 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
});
|
||||
items.push({ label: "", separator: true });
|
||||
}
|
||||
const hasGroupCreateAction =
|
||||
(node.type === "group-tables" && canCreateTable.value) ||
|
||||
(node.type === "group-views" && !!node.connectionId && !!node.database);
|
||||
if (node.type === "group-tables" && canCreateTable.value) {
|
||||
items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });
|
||||
}
|
||||
if (node.type === "group-views" && node.connectionId && node.database) {
|
||||
items.push({ label: t("contextMenu.createView"), action: createView, icon: Plus });
|
||||
}
|
||||
if (hasGroupCreateAction) {
|
||||
items.push({ label: "", separator: true });
|
||||
}
|
||||
if (node.type !== "saved-sql-root" && node.type !== "saved-sql-folder" && node.type !== "group-partitions") {
|
||||
items.push({
|
||||
label: t("contextMenu.refreshChildren"),
|
||||
|
||||
Reference in new issue
Block a user