mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-21 08:13:34 +00:00
feat(desktop): add create actions to tree groups
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -939,6 +939,7 @@ export default {
|
||||
saveStructure: "Save SQL",
|
||||
exportStructureCopied: "Structure copied",
|
||||
createTable: "Create Table",
|
||||
createView: "Create View",
|
||||
dropTable: "Drop Table",
|
||||
emptyTable: "Empty Table",
|
||||
truncateTable: "Truncate Table",
|
||||
|
||||
@@ -836,6 +836,7 @@ export default {
|
||||
saveStructure: "Guardar SQL",
|
||||
exportStructureCopied: "Estructura copiada",
|
||||
createTable: "Crear tabla",
|
||||
createView: "Crear vista",
|
||||
dropTable: "Eliminar tabla",
|
||||
emptyTable: "Vaciar tabla",
|
||||
truncateTable: "Truncar tabla",
|
||||
|
||||
@@ -920,6 +920,7 @@ export default {
|
||||
saveStructure: "保存 SQL",
|
||||
exportStructureCopied: "表结构已复制",
|
||||
createTable: "新建表",
|
||||
createView: "新建视图",
|
||||
dropTable: "删除表",
|
||||
emptyTable: "清空数据",
|
||||
truncateTable: "截断表",
|
||||
|
||||
@@ -920,6 +920,7 @@ export default {
|
||||
saveStructure: "儲存 SQL",
|
||||
exportStructureCopied: "資料表結構已複製",
|
||||
createTable: "建立資料表",
|
||||
createView: "建立檢視",
|
||||
dropTable: "刪除資料表",
|
||||
emptyTable: "清空資料",
|
||||
truncateTable: "截斷資料表",
|
||||
|
||||
Reference in New Issue
Block a user