Skip to content

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

chore: update list database group requests (#13222)

boojackf88997843554
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index fcbef6d942..8f9b3f0ccb 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -101,7 +101,6 @@ import {
} from "@/store/modules/v1/common";
import type {
ComposedDatabase,
- ComposedDatabaseGroup,
ComposedProject,
ResourceId,
ValidatedMessage,
@@ -117,7 +116,6 @@ import { FactorList } from "./utils";
const props = defineProps<{
project: ComposedProject;
databaseGroup?: DatabaseGroup;
- parentDatabaseGroup?: ComposedDatabaseGroup;
}>();
type LocalState = {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
index bd3467c52a..6f897304c0 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
@@ -13,7 +13,6 @@
ref="formRef"
:project="project"
:database-group="props.databaseGroup"
- :parent-database-group="props.parentDatabaseGroup"
/>
<template #footer>
<div class="w-full flex justify-between items-center">
@@ -45,7 +44,7 @@
import { head } from "lodash-es";
import { Trash2Icon } from "lucide-vue-next";
import { NButton, useDialog } from "naive-ui";
-import { computed, onMounted, ref } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { Drawer, DrawerContent } from "@/components/v2";
@@ -68,8 +67,7 @@ import DatabaseGroupForm from "./DatabaseGroupForm.vue";
const props = defineProps<{
show: boolean;
project: ComposedProject;
- databaseGroup?: DatabaseGroup;
- parentDatabaseGroup?: ComposedDatabaseGroup;
+ databaseGroup?: ComposedDatabaseGroup;
}>();
const emit = defineEmits<{
@@ -111,17 +109,6 @@ const showDeleteButton = computed(() => {
return !isCreating.value;
});
-onMounted(async () => {
- 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 = () => {
dialog.error({
title: "Confirm to delete",
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 76259a7f49..3353f9b602 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -35,14 +35,13 @@ import DatabaseGroupDataTable from "@/components/DatabaseGroup/DatabaseGroupData
import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
import { useDBGroupStore, hasFeature } from "@/store";
import type { ComposedDatabaseGroup, ComposedProject } from "@/types";
-import type { DatabaseGroup } from "@/types/proto/v1/database_group_service";
import { FeatureAttention, FeatureModal } from "../FeatureGuard";
import DatabaseGroupPanel from "./DatabaseGroupPanel.vue";
interface LocalState {
showDatabaseGroupPanel: boolean;
showFeatureModal: boolean;
- editingDatabaseGroup?: DatabaseGroup;
+ editingDatabaseGroup?: ComposedDatabaseGroup;
}
const props = defineProps<{
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index 6be7236b9d..54411c06ce 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -81,21 +81,6 @@ export const useDBGroupStore = defineStore("db-group", () => {
const dbGroupMapByName = ref<Map<string, ComposedDatabaseGroup>>(new Map());
const cachedProjectNameSet = ref<Set<string>>(new Set());
- const fetchAllDatabaseGroupList = async () => {
- const { databaseGroups } =
- await databaseGroupServiceClient.listDatabaseGroups({
- parent: `${projectNamePrefix}-`,
- });
- const composedList = [];
- const composeDatabaseGroups =
- await batchComposeDatabaseGroup(databaseGroups);
- for (const composedData of composeDatabaseGroups) {
- dbGroupMapByName.value.set(composedData.name, composedData);
- composedList.push(composedData);
- }
- return composedList;
- };
-
const getAllDatabaseGroupList = () => {
return Array.from(dbGroupMapByName.value.values());
};
@@ -303,7 +288,6 @@ export const useDBGroupStore = defineStore("db-group", () => {
};
return {
- fetchAllDatabaseGroupList,
getAllDatabaseGroupList,
getOrFetchDBGroupByName,
getOrFetchDBGroupListByProjectName,
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index 75f01b88b3..923c14e3ab 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -1,6 +1,6 @@
<template>
<div
- v-if="state.isLoaded"
+ v-if="databaseGroup"
class="flex-1 overflow-auto focus:outline-none"
tabindex="0"
v-bind="$attrs"
@@ -67,7 +67,7 @@
{{ $t("database-group.condition.self") }}
</p>
<ExprEditor
- :expr="state.expr!"
+ :expr="databaseGroup.simpleExpr"
:allow-admin="false"
:enable-raw-expression="true"
:factor-list="FactorList"
@@ -87,18 +87,16 @@
</div>
<DatabaseGroupPanel
- :show="editState.showConfigurePanel"
+ :show="state.showEditPanel"
:project="project"
- :database-group="editState.databaseGroup"
- :parent-database-group="editState.parentDatabaseGroup"
- @close="editState.showConfigurePanel = false"
+ :database-group="databaseGroup"
+ @close="state.showEditPanel = false"
/>
</template>
<script lang="ts" setup>
-import { useDebounceFn } from "@vueuse/core";
import { NButton, NDivider, NTag } from "naive-ui";
-import { onMounted, reactive, computed, watch, ref } from "vue";
+import { reactive, computed, watchEffect } from "vue";
import { useRouter } from "vue-router";
import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
@@ -110,7 +108,6 @@ import {
import ExprEditor from "@/components/ExprEditor";
import { FeatureAttentionForInstanceLicense } from "@/components/FeatureGuard";
import TenantIcon from "@/components/TenantIcon.vue";
-import type { ConditionGroupExpr } from "@/plugins/cel";
import {
useCurrentUserV1,
useDBGroupStore,
@@ -120,23 +117,12 @@ import {
} from "@/store";
import { databaseGroupNamePrefix } from "@/store/modules/v1/common";
import { projectNamePrefix } from "@/store/modules/v1/common";
-import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
-import {
- DatabaseGroupView,
- type DatabaseGroup,
-} from "@/types/proto/v1/database_group_service";
+import { DatabaseGroupView } from "@/types/proto/v1/database_group_service";
import { hasPermissionToCreateChangeDatabaseIssueInProject } from "@/utils";
import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
interface LocalState {
- isLoaded: boolean;
- expr?: ConditionGroupExpr;
-}
-
-interface EditDatabaseGroupState {
- showConfigurePanel: boolean;
- databaseGroup?: DatabaseGroup;
- parentDatabaseGroup?: ComposedDatabaseGroup;
+ showEditPanel: boolean;
}
const props = defineProps<{
@@ -146,104 +132,59 @@ const props = defineProps<{
}>();
const router = useRouter();
+const currentUser = useCurrentUserV1();
const projectStore = useProjectV1Store();
const dbGroupStore = useDBGroupStore();
const databaseStore = useDatabaseV1Store();
const subscriptionV1Store = useSubscriptionV1Store();
-const me = useCurrentUserV1();
-
const state = reactive<LocalState>({
- isLoaded: false,
-});
-const editState = reactive<EditDatabaseGroupState>({
- showConfigurePanel: false,
+ showEditPanel: false,
});
+
const project = computed(() => {
return projectStore.getProjectByName(
`${projectNamePrefix}${props.projectId}`
);
});
+
const databaseGroupResourceName = computed(() => {
return `${project.value.name}/${databaseGroupNamePrefix}${props.databaseGroupName}`;
});
+
const databaseGroup = computed(() => {
- return dbGroupStore.getDBGroupByName(
- databaseGroupResourceName.value
- ) as ComposedDatabaseGroup;
+ return dbGroupStore.getDBGroupByName(databaseGroupResourceName.value);
});
+
const hasPermissionToCreateIssue = computed(() => {
return hasPermissionToCreateChangeDatabaseIssueInProject(
project.value,
- me.value
+ currentUser.value
);
});
-onMounted(async () => {
+watchEffect(async () => {
await dbGroupStore.getOrFetchDBGroupByName(databaseGroupResourceName.value, {
skipCache: true,
view: DatabaseGroupView.DATABASE_GROUP_VIEW_FULL,
});
});
-const handleEditDatabaseGroup = () => {
- editState.databaseGroup = databaseGroup.value;
- editState.showConfigurePanel = true;
-};
-
-const previewDatabaseGroupIssue = (
- type: "bb.issue.database.schema.update" | "bb.issue.database.data.update"
-) => {
- const issueRoute = generateDatabaseGroupIssueRoute(type, databaseGroup.value);
- router.push(issueRoute);
-};
-
-watch(
- () => [databaseGroup.value],
- async () => {
- if (!databaseGroup.value) {
- return;
- }
- state.expr = databaseGroup.value.simpleExpr;
- state.isLoaded = true;
- },
- {
- immediate: true,
- }
+const matchedDatabaseList = computed(
+ () =>
+ databaseGroup.value?.matchedDatabases.map((db) =>
+ databaseStore.getDatabaseByName(db.name)
+ ) || []
);
-const matchedDatabaseList = ref<ComposedDatabase[]>([]);
-const unmatchedDatabaseList = ref<ComposedDatabase[]>([]);
-
-const updateDatabaseMatchingState = useDebounceFn(async () => {
- if (!state.isLoaded) {
- return;
- }
-
- const matched = await Promise.all(
- databaseGroup.value.matchedDatabases.map((db) =>
- databaseStore.getOrFetchDatabaseByName(db.name)
- )
- );
- const unmatched = await Promise.all(
- databaseGroup.value.unmatchedDatabases.map((db) =>
- databaseStore.getOrFetchDatabaseByName(db.name)
- )
- );
- matchedDatabaseList.value = matched;
- unmatchedDatabaseList.value = unmatched;
-}, 500);
-
-watch(
- [() => state.isLoaded, () => project.value, () => databaseGroup.value],
- updateDatabaseMatchingState,
- {
- immediate: true,
- deep: true,
- }
+const unmatchedDatabaseList = computed(
+ () =>
+ databaseGroup.value?.unmatchedDatabases.map((db) =>
+ databaseStore.getDatabaseByName(db.name)
+ ) || []
);
const existMatchedUnactivateInstance = computed(() => {
- return matchedDatabaseList.value.some(
+ return matchedDatabaseList.value?.some(
(database) =>
!subscriptionV1Store.hasInstanceFeature(
"bb.feature.database-grouping",
@@ -251,4 +192,18 @@ const existMatchedUnactivateInstance = computed(() => {
)
);
});
+
+const handleEditDatabaseGroup = () => {
+ state.showEditPanel = true;
+};
+
+const previewDatabaseGroupIssue = (
+ type: "bb.issue.database.schema.update" | "bb.issue.database.data.update"
+) => {
+ if (!databaseGroup.value) {
+ return;
+ }
+ const issueRoute = generateDatabaseGroupIssueRoute(type, databaseGroup.value);
+ router.push(issueRoute);
+};
</script>