Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(frontend): fixes for lx (#12452)

Liu Ji8dbf18563420
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index 7118228c09..dc56200638 100644
--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -1,6 +1,7 @@
import type { Ref, VNode } from "vue";
import { computed, h, unref } from "vue";
import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
import GitIcon from "@/components/GitIcon.vue";
import {
InstanceV1Name,
@@ -32,13 +33,34 @@ export const useCommonSearchScopeOptions = (
supportOptionIdList: MaybeRef<SearchScopeId[]>
) => {
const { t } = useI18n();
+ const route = useRoute();
const databaseV1Store = useDatabaseV1Store();
const environmentList = useEnvironmentV1List(false /* !showDeleted */);
const { projectList } = useProjectV1List();
- const { instanceList } = useInstanceV1List(false /* !showDeleted */);
- const { databaseList } = useSearchDatabaseV1List({
- filter: "instance = instances/-",
+
+ const project = computed(() => {
+ const { projectId } = route.params;
+ if (projectId && typeof projectId === "string") {
+ return `projects/${projectId}`;
+ }
+ return undefined;
});
+ const { instanceList } = useInstanceV1List(
+ /* !showDeleted */ false,
+ /* !forceUpdate */ false,
+ /* parent */ computed(() => project.value)
+ );
+ const { databaseList } = useSearchDatabaseV1List(
+ computed(() => {
+ const filters = ["instance = instances/-"];
+ if (project.value) {
+ filters.push(`project = ${project.value}`);
+ }
+ return {
+ filter: filters.join(" && "),
+ };
+ })
+ );
// fullScopeOptions provides full search scopes and options.
// we need this as the source of truth.
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index af17227995..73cddf21b7 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -465,9 +465,18 @@ watch(
const environmentList = useEnvironmentV1List(false /* !showDeleted */);
-const { ready } = useSearchDatabaseV1List({
- filter: "instance = instances/-",
-});
+const { ready } = useSearchDatabaseV1List(
+ computed(() => {
+ const filters = ["instance = instances/-"];
+ const project = selectedProject.value;
+ if (project) {
+ filters.push(`project = ${project.name}`);
+ }
+ return {
+ filter: filters.join(" && "),
+ };
+ })
+);
const prepareDatabaseGroupList = async () => {
if (selectedProject.value) {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
index 71a293edb5..83538e189f 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
@@ -103,7 +103,14 @@ const showDeleteButton = computed(() => {
});
onMounted(async () => {
- await dbGroupStore.fetchAllDatabaseGroupList();
+ const project = router.currentRoute.value.params.projectId as string;
+ if (project && typeof project === "string") {
+ await dbGroupStore.getOrFetchDBGroupListByProjectName(
+ `projects/${project}`
+ );
+ } else {
+ await dbGroupStore.fetchAllDatabaseGroupList();
+ }
});
const doDelete = () => {
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index b80c340de4..90095752b1 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -27,6 +27,14 @@ const isLoading = ref<boolean>(true);
const policyStore = usePolicyV1Store();
const databaseStore = useDatabaseV1Store();
+const fetchInstances = async (project: string) => {
+ const parent = project ? `${projectNamePrefix}${project}` : undefined;
+ await useInstanceV1Store().fetchInstanceList(
+ /* !showDeleted */ false,
+ parent
+ );
+};
+
const fetchDatabases = async (project: string) => {
const filters = [`instance = "instances/-"`];
// If `projectId` is provided in the route, filter the database list by the project.
@@ -37,6 +45,10 @@ const fetchDatabases = async (project: string) => {
filter: filters.join(" && "),
});
};
+const fetchInstancesAndDatabases = async (project: string) => {
+ await fetchInstances(project);
+ await fetchDatabases(project);
+};
onMounted(async () => {
await router.isReady();
@@ -55,16 +67,15 @@ onMounted(async () => {
useUserStore().fetchUserList(),
useUserGroupStore().fetchGroupList(),
useEnvironmentV1Store().fetchEnvironments(),
- useInstanceV1Store().fetchInstanceList(),
useProjectV1Store().fetchProjectList(true /* showDeleted */),
]);
await Promise.all([useUIStateStore().restoreState()]);
- await fetchDatabases(route.params.projectId as string);
+ await fetchInstancesAndDatabases(route.params.projectId as string);
watch(
() => route.params.projectId,
(project) => {
- fetchDatabases(project as string);
+ fetchInstancesAndDatabases(project as string);
},
{ immediate: false }
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 162ab5b312..0aefe17b05 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2336,7 +2336,8 @@
"rows": "rows"
},
"n-per-page": "{n} / page",
- "customize-tree-structure": "Customize tree structure"
+ "customize-tree-structure": "Customize tree structure",
+ "will-override-current-editing-statement": "Will override current editing statement."
},
"schema-editor": {
"self": "Schema Editor",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 29e1c1f518..101d9e17ed 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2336,7 +2336,8 @@
"rows": "filas"
},
"n-per-page": "{n} / página",
- "customize-tree-structure": "Personalizar la estructura del árbol"
+ "customize-tree-structure": "Personalizar la estructura del árbol",
+ "will-override-current-editing-statement": "Anulará la declaración de edición actual."
},
"schema-editor": {
"self": "Editor de esquema",
@@ -3552,4 +3553,4 @@
"self": "Última actualización"
}
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index c9a0df6489..682fd800c9 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2336,7 +2336,8 @@
"rows": "行"
},
"n-per-page": "{n} / ページ",
- "customize-tree-structure": "ツリー構造をカスタマイズする"
+ "customize-tree-structure": "ツリー構造をカスタマイズする",
+ "will-override-current-editing-statement": "現在の編集ステートメントをオーバーライドします。"
},
"schema-editor": {
"self": "スキーマエディタ",
@@ -3552,4 +3553,4 @@
"self": "最後の更新"
}
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 208fbe973f..4111d7d4e7 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2336,7 +2336,8 @@
"rows": "行"
},
"n-per-page": "{n} / 页",
- "customize-tree-structure": "自定义树结构"
+ "customize-tree-structure": "自定义树结构",
+ "will-override-current-editing-statement": "将会覆盖当前的编辑中语句。"
},
"schema-editor": {
"self": "Schema 编辑器",
diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.ts
index 6a8da25c59..962421cf10 100644
--- a/frontend/src/store/modules/v1/instance.ts
+++ b/frontend/src/store/modules/v1/instance.ts
@@ -58,14 +58,14 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
}
return composedInstances;
};
- const fetchInstanceList = async (showDeleted = false) => {
+ const fetchInstanceList = async (showDeleted = false, parent?: string) => {
const request = hasWorkspacePermissionV2(
currentUser.value,
"bb.instances.list"
)
? instanceServiceClient.listInstances
: instanceServiceClient.searchInstances;
- const { instances } = await request({ showDeleted });
+ const { instances } = await request({ showDeleted, parent });
const composed = await upsertInstances(instances);
return composed;
};
@@ -251,7 +251,8 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
export const useInstanceV1List = (
showDeleted: MaybeRef<boolean> = false,
- forceUpdate = false
+ forceUpdate = false,
+ parent: MaybeRef<string | undefined> = undefined
) => {
const store = useInstanceV1Store();
const ready = ref(false);
@@ -262,7 +263,7 @@ export const useInstanceV1List = (
}
ready.value = false;
- store.fetchInstanceList(unref(showDeleted)).then(() => {
+ store.fetchInstanceList(unref(showDeleted), unref(parent)).then(() => {
ready.value = true;
});
});
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
index ee79d5a9a3..8591c6239e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
@@ -66,7 +66,7 @@
<script setup lang="tsx">
import { computedAsync, useElementSize, useMounted } from "@vueuse/core";
-import { NDropdown, type TreeOption } from "naive-ui";
+import { NDropdown, useDialog, type TreeOption } from "naive-ui";
import { storeToRefs } from "pinia";
import { computed, nextTick, ref, watch } from "vue";
import { BBModal } from "@/bbkit";
@@ -109,6 +109,7 @@ const {
position: hoverPosition,
update: updateHoverState,
} = provideHoverStateContext();
+const $d = useDialog();
const {
show: showDropdown,
context: dropdownContext,
@@ -185,7 +186,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
},
ondblclick() {
if (node.meta.type === "table" || node.meta.type === "view") {
- selectAllFromTableOrView(node);
+ selectAllFromTableOrView($d, node);
}
},
onmouseenter(e: MouseEvent) {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
index bc7bdd96c2..49aeadeea5 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
@@ -5,7 +5,7 @@ import {
LinkIcon,
SquarePenIcon,
} from "lucide-vue-next";
-import type { DropdownOption } from "naive-ui";
+import { useDialog, type DropdownOption } from "naive-ui";
import { computed, nextTick, ref } from "vue";
import { useRouter } from "vue-router";
import TableIcon from "@/components/Icon/TableIcon.vue";
@@ -22,6 +22,7 @@ import {
} from "@/types";
import { Engine } from "@/types/proto/v1/common";
import {
+ defer,
extractInstanceResourceName,
extractProjectResourceName,
generateSimpleSelectAllStatement,
@@ -44,10 +45,39 @@ const VIEW_SCHEMA_ACTION_ENABLED_ENGINES = [
Engine.TIDB,
];
+const confirmOverrideStatement = async (
+ $d: ReturnType<typeof useDialog>,
+ statement: string
+) => {
+ const { currentTab } = useSQLEditorTabStore();
+ if (currentTab && currentTab.statement.trim().length > 0) {
+ const d = defer<boolean>();
+
+ $d.warning({
+ title: t("common.warning"),
+ content: t("sql-editor.will-override-current-editing-statement"),
+ contentClass: "whitespace-pre-wrap",
+ style: "z-index: 100000",
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ onNegativeClick: () => {
+ d.resolve(false);
+ },
+ onPositiveClick: () => {
+ d.resolve(true);
+ },
+ });
+ return d.promise;
+ }
+
+ return Promise.resolve(true);
+};
+
export const useDropdown = () => {
const router = useRouter();
const { events: editorEvents, schemaViewer } = useSQLEditorContext();
const pageMode = usePageMode();
+ const $d = useDialog();
const show = ref(false);
const position = ref<Position>({
@@ -191,13 +221,17 @@ export const useDropdown = () => {
key: "preview-table-data",
label: t("sql-editor.preview-table-data"),
icon: () => <TableIcon class="w-4 h-4" />,
- onSelect: () => {
+ onSelect: async () => {
const statement = generateSimpleSelectAllStatement(
engineForTarget(target),
schema,
tableOrView,
SELECT_ALL_LIMIT
);
+ const confirmed = await confirmOverrideStatement($d, statement);
+ if (!confirmed) {
+ return;
+ }
runQuery(
(target as NodeTarget<"database">).db,
schema,
@@ -319,7 +353,10 @@ const runQuery = async (
});
};
-export const selectAllFromTableOrView = async (node: TreeNode) => {
+export const selectAllFromTableOrView = async (
+ $d: ReturnType<typeof useDialog>,
+ node: TreeNode
+) => {
const { target } = (node as TreeNode<"table" | "view">).meta;
if (!targetSupportsSelectAll(target)) {
return;
@@ -340,5 +377,9 @@ export const selectAllFromTableOrView = async (node: TreeNode) => {
tableOrViewName,
SELECT_ALL_LIMIT
);
+ const confirmed = await confirmOverrideStatement($d, query);
+ if (!confirmed) {
+ return;
+ }
runQuery(db, schema, tableOrViewName, query);
};