Skip to content

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

chore: update requesting for matched database/table list (#6396)

boojackd49425ef7565
diff --git a/frontend/src/bbkit/BBLoader.vue b/frontend/src/bbkit/BBLoader.vue
new file mode 100644
index 0000000000..bbf889e8a1
--- /dev/null
+++ b/frontend/src/bbkit/BBLoader.vue
@@ -0,0 +1,26 @@
+<template>
+ <div class="flex flex-row items-center text-control text-sm">
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ class="animate-spin h-5 w-5"
+ v-bind="$attrs"
+ >
+ <line x1="12" x2="12" y1="2" y2="6"></line>
+ <line x1="12" x2="12" y1="18" y2="22"></line>
+ <line x1="4.93" x2="7.76" y1="4.93" y2="7.76"></line>
+ <line x1="16.24" x2="19.07" y1="16.24" y2="19.07"></line>
+ <line x1="2" x2="6" y1="12" y2="12"></line>
+ <line x1="18" x2="22" y1="12" y2="12"></line>
+ <line x1="4.93" x2="7.76" y1="19.07" y2="16.24"></line>
+ <line x1="16.24" x2="19.07" y1="7.76" y2="4.93"></line>
+ </svg>
+ </div>
+</template>
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index 1d65856912..c6094f6dfe 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -39,6 +39,7 @@
<DatabaseGroupSelect
:disabled="!isCreating"
:project-id="project.name"
+ :environment-id="state.environmentId || ''"
:selected-id="state.selectedDatabaseGroupId"
@select-database-group-id="
(id) => {
@@ -69,7 +70,7 @@
v-if="resourceType === 'SCHEMA_GROUP'"
:project="project"
:schema-group="databaseGroup as SchemaGroup"
- :database-group-name="state.selectedDatabaseGroupId || ''"
+ :database-group-name="selectedDatabaseGroupName || ''"
:expr="state.expr"
/>
</div>
@@ -127,6 +128,12 @@ const state = reactive<LocalState>({
expr: wrapAsGroup(resolveCELExpr(CELExpr.fromJSON({}))),
});
const resourceIdInput = ref<InstanceType<typeof ResourceIdInput>>();
+const selectedDatabaseGroupName = computed(() => {
+ const [, databaseGroupName] = getProjectNameAndDatabaseGroupName(
+ state.selectedDatabaseGroupId || ""
+ );
+ return databaseGroupName;
+});
const isCreating = computed(() => props.databaseGroup === undefined);
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupSelect.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupSelect.vue
index 6a653e063e..12817c8a7c 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupSelect.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupSelect.vue
@@ -17,14 +17,16 @@
import { computed, reactive, watch } from "vue";
import { useDBGroupStore } from "@/store";
import { DatabaseGroup } from "@/types/proto/v1/project_service";
+import { ComposedDatabaseGroup } from "@/types";
interface LocalState {
- selectedDatabaseGroup?: DatabaseGroup;
+ selectedDatabaseGroup?: ComposedDatabaseGroup;
}
const props = defineProps<{
- selectedId?: string;
projectId: string;
+ selectedId?: string;
+ environmentId?: string;
disabled?: boolean;
}>();
@@ -39,7 +41,13 @@ const state = reactive<LocalState>({
const dbGroupStore = useDBGroupStore();
const dbGroupList = computed(() => {
- return dbGroupStore.getDBGroupListByProjectName(props.projectId);
+ return dbGroupStore
+ .getDBGroupListByProjectName(props.projectId)
+ .filter((dbGroup) =>
+ props.environmentId
+ ? dbGroup.environment.uid === props.environmentId
+ : true
+ );
});
const getDatabaseGroupTitle = (databaseGroupName: string): string => {
@@ -59,13 +67,13 @@ const invalidateSelectionIfNeeded = () => {
};
watch(
- () => props.selectedId,
- (selectedId) => {
+ () => props,
+ () => {
invalidateSelectionIfNeeded();
state.selectedDatabaseGroup = dbGroupList.value.find(
- (item) => item.name === selectedId
+ (item) => item.name === props.selectedId
);
},
- { immediate: true }
+ { immediate: true, deep: true }
);
</script>
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
index 8599729f8a..c62746ed4e 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
@@ -12,7 +12,7 @@
{{ item.databaseGroupName }}
</div>
<div class="bb-grid-cell">{{ item.environment.title }}</div>
- <div v-if="props.showEdit" class="bb-grid-cell gap-x-2">
+ <div v-if="props.showEdit" class="bb-grid-cell gap-x-2 justify-end">
<NButton size="small" @click.stop="$emit('edit', item)"
>Configure</NButton
>
diff --git a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
index 48304bcfae..848500f0d9 100644
--- a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
@@ -1,8 +1,14 @@
<template>
- <p class="text-lg mb-2">Databases</p>
- <div class="w-full border min-h-[20rem] max-h-[24rem] overflow-y-auto">
+ <div class="mb-2 flex flex-row items-center">
+ <span class="text-lg mr-2">Databases</span>
+ <BBLoader v-show="state.isRequesting" class="opacity-60" />
+ </div>
+ <div
+ class="w-full border rounded min-h-[20rem] max-h-[24rem] overflow-y-auto"
+ >
<div
- class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
+ class="sticky top-0 z-[1] w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b cursor-pointer"
+ @click="state.showMatchedDatabaseList = !state.showMatchedDatabaseList"
>
<div>
<span>Matched database</span>
@@ -10,9 +16,7 @@
>({{ matchedDatabaseList.length }})</span
>
</div>
- <button
- @click="state.showMatchedDatabaseList = !state.showMatchedDatabaseList"
- >
+ <button class="opacity-60">
<heroicons-outline:chevron-right
v-if="!state.showMatchedDatabaseList"
class="w-5 h-auto"
@@ -29,15 +33,19 @@
<span class="text-sm">{{ database.databaseName }}</span>
<div class="flex flex-row justify-end items-center">
<InstanceV1EngineIcon :instance="database.instanceEntity" />
- <span class="ml-1 text-sm text-gray-400">{{
- database.instanceEntity.title
- }}</span>
+ <span class="ml-1 text-sm text-gray-400"
+ >{{ database.instanceEntity.title }} ({{
+ database.instanceEntity.environmentEntity.title
+ }})</span
+ >
</div>
</div>
</div>
<div
- class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
- :class="[state.showMatchedDatabaseList && 'border-t']"
+ class="sticky top-8 z-[1] w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-y cursor-pointer"
+ @click="
+ state.showUnmatchedDatabaseList = !state.showUnmatchedDatabaseList
+ "
>
<div>
<span>Unmatched database</span>
@@ -45,11 +53,7 @@
>({{ unmatchedDatabaseList.length }})</span
>
</div>
- <button
- @click="
- state.showUnmatchedDatabaseList = !state.showUnmatchedDatabaseList
- "
- >
+ <button class="opacity-60">
<heroicons-outline:chevron-right
v-if="!state.showUnmatchedDatabaseList"
class="w-5 h-auto"
@@ -66,9 +70,11 @@
<span class="text-sm">{{ database.databaseName }}</span>
<div class="flex flex-row justify-end items-center">
<InstanceV1EngineIcon :instance="database.instanceEntity" />
- <span class="ml-1 text-sm text-gray-400">{{
- database.instanceEntity.title
- }}</span>
+ <span class="ml-1 text-sm text-gray-400"
+ >{{ database.instanceEntity.title }} ({{
+ database.instanceEntity.environmentEntity.title
+ }})</span
+ >
</div>
</div>
</div>
@@ -89,8 +95,10 @@ import { projectServiceClient } from "@/grpcweb";
import { stringifyDatabaseGroupExpr } from "@/utils/databaseGroup/cel";
import { Expr } from "@/types/proto/google/type/expr";
import { useDebounceFn } from "@vueuse/core";
+import BBLoader from "@/bbkit/BBLoader.vue";
interface LocalState {
+ isRequesting: boolean;
showMatchedDatabaseList: boolean;
showUnmatchedDatabaseList: boolean;
}
@@ -105,6 +113,7 @@ const props = defineProps<{
const environmentStore = useEnvironmentV1Store();
const databaseStore = useDatabaseV1Store();
const state = reactive<LocalState>({
+ isRequesting: false,
showMatchedDatabaseList: true,
showUnmatchedDatabaseList: false,
});
@@ -114,6 +123,7 @@ const unmatchedDatabaseList = ref<ComposedDatabase[]>([]);
const isCreating = computed(() => props.databaseGroup === undefined);
const updateMatchingState = useDebounceFn(async () => {
+ state.isRequesting = true;
const matchedDatabaseNameList: string[] = [];
const unmatchedDatabaseNameList: string[] = [];
@@ -171,6 +181,7 @@ const updateMatchingState = useDebounceFn(async () => {
unmatchedDatabaseList.value.push(database);
}
}
+ state.isRequesting = false;
}, 500);
watch(() => props, updateMatchingState, {
diff --git a/frontend/src/components/DatabaseGroup/MatchedTableView.vue b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
index 799410237d..1fb03854d3 100644
--- a/frontend/src/components/DatabaseGroup/MatchedTableView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
@@ -1,14 +1,20 @@
<template>
- <p class="text-lg mb-2">Tables</p>
- <div class="w-full border min-h-[20rem] max-h-[24rem] overflow-y-auto">
+ <div class="mb-2 flex flex-row items-center">
+ <span class="text-lg mr-2">Tables</span>
+ <BBLoader v-show="state.isRequesting" class="opacity-60" />
+ </div>
+ <div
+ class="w-full border rounded min-h-[20rem] max-h-[24rem] overflow-y-auto"
+ >
<div
- class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
+ class="sticky top-0 z-[1] w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b cursor-pointer"
+ @click="state.showMatchedTableList = !state.showMatchedTableList"
>
<div>
<span>Matched table</span>
<span class="ml-1 text-gray-400">({{ matchedTableList.length }})</span>
</div>
- <button @click="state.showMatchedTableList = !state.showMatchedTableList">
+ <button class="opacity-60">
<heroicons-outline:chevron-right
v-if="!state.showMatchedTableList"
class="w-5 h-auto"
@@ -29,8 +35,8 @@
</div>
</div>
<div
- class="w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-b"
- :class="[state.showMatchedTableList && 'border-t']"
+ class="sticky top-8 z-[1] w-full flex flex-row justify-between items-center px-2 py-1 bg-gray-100 border-y cursor-pointer"
+ @click="state.showUnmatchedTableList = !state.showUnmatchedTableList"
>
<div>
<span>Unmatched table</span>
@@ -38,9 +44,7 @@
>({{ unmatchedTableList.length }})</span
>
</div>
- <button
- @click="state.showUnmatchedTableList = !state.showUnmatchedTableList"
- >
+ <button class="opacity-60">
<heroicons-outline:chevron-right
v-if="!state.showUnmatchedTableList"
class="w-5 h-auto"
@@ -64,21 +68,25 @@
</template>
<script lang="ts" setup>
-import { computed, ref, watch, reactive } from "vue";
+import { ref, watch, reactive } from "vue";
import { ConditionGroupExpr, convertToCELString } from "@/plugins/cel";
import { ComposedProject } from "@/types";
import { DatabaseView } from "../v2";
import {
SchemaGroup,
- SchemaGroupView,
SchemaGroup_Table,
} from "@/types/proto/v1/project_service";
import { projectServiceClient } from "@/grpcweb";
import { Expr } from "@/types/proto/google/type/expr";
import { useDebounceFn } from "@vueuse/core";
-import { schemaGroupNamePrefix } from "@/store/modules/v1/common";
+import {
+ databaseGroupNamePrefix,
+ schemaGroupNamePrefix,
+} from "@/store/modules/v1/common";
+import BBLoader from "@/bbkit/BBLoader.vue";
interface LocalState {
+ isRequesting: boolean;
showMatchedTableList: boolean;
showUnmatchedTableList: boolean;
}
@@ -91,25 +99,23 @@ const props = defineProps<{
}>();
const state = reactive<LocalState>({
+ isRequesting: false,
showMatchedTableList: true,
showUnmatchedTableList: false,
});
const matchedTableList = ref<SchemaGroup_Table[]>([]);
const unmatchedTableList = ref<SchemaGroup_Table[]>([]);
-const isCreating = computed(() => props.schemaGroup === undefined);
-
const updateMatchingState = useDebounceFn(async () => {
- const tempMatchedTableList: SchemaGroup_Table[] = [];
- const tempUnmatchedTableList: SchemaGroup_Table[] = [];
-
- if (isCreating.value) {
+ state.isRequesting = true;
+ try {
const celString = convertToCELString(props.expr);
const validateOnlyResourceId = "creating-schema-group";
+ const databaseGroupName = `${props.project.name}/${databaseGroupNamePrefix}${props.databaseGroupName}`;
const result = await projectServiceClient.createSchemaGroup({
- parent: props.databaseGroupName,
+ parent: databaseGroupName,
schemaGroup: {
- name: `${props.databaseGroupName}/${schemaGroupNamePrefix}/${validateOnlyResourceId}`,
+ name: `${databaseGroupName}/${schemaGroupNamePrefix}${validateOnlyResourceId}`,
tablePlaceholder: validateOnlyResourceId,
tableExpr: Expr.fromJSON({
expression: celString,
@@ -118,18 +124,13 @@ const updateMatchingState = useDebounceFn(async () => {
schemaGroupId: validateOnlyResourceId,
validateOnly: true,
});
- tempMatchedTableList.push(...result.matchedTables);
- tempUnmatchedTableList.push(...result.unmatchedTables);
- } else {
- const result = await projectServiceClient.getSchemaGroup({
- name: props.schemaGroup!.name,
- view: SchemaGroupView.SCHEMA_GROUP_VIEW_FULL,
- });
- tempMatchedTableList.push(...result.matchedTables);
- tempUnmatchedTableList.push(...result.unmatchedTables);
+ matchedTableList.value = result.matchedTables;
+ unmatchedTableList.value = result.unmatchedTables;
+ } catch (error) {
+ console.error(error);
+ // do nothing else.
}
- matchedTableList.value = tempMatchedTableList;
- unmatchedTableList.value = tempUnmatchedTableList;
+ state.isRequesting = false;
}, 500);
watch(() => props, updateMatchingState, {
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 91cd598bef..3dd8e351aa 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -3,7 +3,6 @@
<div class="w-full flex flex-row justify-between items-center">
<span>Database groups</span>
<div class="flex flex-row gap-x-2">
- <NButton @click="handleCreateSchemaGroup">New table group</NButton>
<NButton @click="handleCreateDatabaseGroup">New database group</NButton>
</div>
</div>
@@ -69,10 +68,4 @@ const handleConfigureDatabaseGroup = (databaseGroup: DatabaseGroup) => {
state.editingDatabaseGroup = cloneDeep(databaseGroup);
state.showDatabaseGroupPanel = true;
};
-
-const handleCreateSchemaGroup = () => {
- state.resourceType = "SCHEMA_GROUP";
- state.editingDatabaseGroup = undefined;
- state.showDatabaseGroupPanel = true;
-};
</script>
diff --git a/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue b/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue
index 94f7a69c9f..455eadf565 100644
--- a/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue
+++ b/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue
@@ -11,7 +11,7 @@
<div class="bb-grid-cell">
{{ item.resourceId }}
</div>
- <div class="bb-grid-cell gap-x-2">
+ <div class="bb-grid-cell gap-x-2 justify-end">
<NButton size="small" @click.stop="$emit('edit', item.schemaGroup)"
>Configure</NButton
>
diff --git a/frontend/src/components/v2/Form/ResourceIdField.vue b/frontend/src/components/v2/Form/ResourceIdField.vue
index 22f95f0a38..74ed8ea1e6 100644
--- a/frontend/src/components/v2/Form/ResourceIdField.vue
+++ b/frontend/src/components/v2/Form/ResourceIdField.vue
@@ -186,7 +186,9 @@ const handleResourceIdChange = async (newValue: string) => {
// custom validation for resource id. (e.g. check if the resource id is already used)
if (props.validate) {
const messages = await props.validate(state.resourceId);
- state.validatedMessages.push(...messages);
+ if (Array.isArray(messages)) {
+ state.validatedMessages.push(...messages);
+ }
}
};
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index 0d334ac63b..234f09c9e1 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -99,13 +99,9 @@
<div class="w-full flex flex-row justify-between items-center">
<p class="my-4">Table group</p>
<div>
- <button
- type="button"
- class="btn-normal"
- @click.prevent="handleCreateSchemaGroup"
- >
+ <NButton @click.prevent="handleCreateSchemaGroup">
New table group
- </button>
+ </NButton>
</div>
</div>
<SchemaGroupTable
@@ -148,6 +144,7 @@ import { ResourceType } from "@/components/DatabaseGroup/common/ExprEditor/conte
import { useRouter } from "vue-router";
import { ComposedDatabaseGroup } from "@/types";
import { generateIssueRoute } from "@/utils/databaseGroup/issue";
+import { NButton } from "naive-ui";
interface LocalState {
isLoaded: boolean;
diff --git a/frontend/src/views/SchemaGroupDetail.vue b/frontend/src/views/SchemaGroupDetail.vue
index 9beb4d49b9..68276ea5b6 100644
--- a/frontend/src/views/SchemaGroupDetail.vue
+++ b/frontend/src/views/SchemaGroupDetail.vue
@@ -75,7 +75,6 @@
/>
</div>
<div class="col-span-2">
- <p class="text-lg mb-2">Databases</p>
<MatchedTableView
:project="project"
:database-group-name="databaseGroupName"