Skip to content

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

feat: implement CRUD for database/schema groups in frontend (#6345)

boojackb885893a9cd2
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index aee642d96a..73e141fee6 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -140,6 +140,10 @@ export default defineComponent({
const sqlReviewPolicySlug = routeSlug.sqlReviewPolicySlug;
const ssoName = routeSlug.ssoName;
+ const projectName = routeSlug.projectName;
+ const databaseGroupName = routeSlug.databaseGroupName;
+ const schemaGroupName = routeSlug.schemaGroupName;
+
const list: Array<BreadcrumbItem> = [];
if (environmentSlug) {
list.push({
@@ -204,6 +208,21 @@ export default defineComponent({
path: "/setting/sso",
});
}
+ } else if (schemaGroupName) {
+ if (projectName && databaseGroupName) {
+ list.push(
+ {
+ name: "Databases",
+ },
+ {
+ name: databaseGroupName,
+ path: `/projects/${projectName}/database-groups/${databaseGroupName}`,
+ },
+ {
+ name: `Tables - ${schemaGroupName}`,
+ }
+ );
+ }
}
const {
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index 9a731679f2..a1f8788440 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -14,6 +14,7 @@
<div>
<p class="text-lg mb-2">Environment</p>
<EnvironmentSelect
+ :disabled="!isCreating"
:selected-id="state.environmentId"
@select-environment-id="
(environmentId) => {
@@ -36,6 +37,7 @@
<div v-if="resourceType === 'SCHEMA_GROUP'">
<p class="text-lg mb-2">Database group</p>
<DatabaseGroupSelect
+ :disabled="!isCreating"
:project-id="project.name"
:selected-id="state.selectedDatabaseGroupId"
@select-database-group-id="
@@ -92,6 +94,12 @@ import MatchedDatabaseView from "./MatchedDatabaseView.vue";
import MatchedTableView from "./MatchedTableView.vue";
import ResourceIdInput from "../v2/Form/ResourceIdInput.vue";
import DatabaseGroupSelect from "./DatabaseGroupSelect.vue";
+import {
+ databaseGroupNamePrefix,
+ getProjectNameAndDatabaseGroupName,
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName,
+} from "@/store/modules/v1/common";
+import { projectNamePrefix } from "@/store/modules/v1/common";
const props = defineProps<{
project: ComposedProject;
@@ -135,14 +143,21 @@ onMounted(async () => {
if (props.resourceType === "DATABASE_GROUP") {
expression =
(databaseGroup as DatabaseGroup).databaseExpr?.expression ?? "";
+ const [, databaseGroupName] = getProjectNameAndDatabaseGroupName(
+ databaseGroup.name
+ );
+ state.resourceId = databaseGroupName;
} else {
expression = (databaseGroup as SchemaGroup).tableExpr?.expression ?? "";
+ const [projectName, databaseGroupName, schemaGroupName] =
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName(databaseGroup.name);
+ state.resourceId = schemaGroupName;
+ state.selectedDatabaseGroupId = `${projectNamePrefix}${projectName}/${databaseGroupNamePrefix}${databaseGroupName}`;
}
const convertResult = await convertDatabaseGroupExprFromCEL(expression);
const environment = environmentStore.getEnvironmentByName(
convertResult.environmentId
);
- state.resourceId = databaseGroup.name.split("/").pop() || "";
state.environmentId = environment?.uid;
state.expr = convertResult.conditionGroupExpr;
});
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
index 5240902859..8359a72345 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupPanel.vue
@@ -19,14 +19,18 @@
<template #footer>
<div class="w-full flex justify-between items-center">
<div>
- <NButton type="error" @click="doDelete">{{
+ <NButton v-if="!isCreating" type="error" @click="doDelete">{{
$t("common.delete")
}}</NButton>
</div>
<div class="flex flex-row justify-end items-center gap-x-2">
<NButton @click="$emit('close')">{{ $t("common.cancel") }}</NButton>
- <NButton type="primary" @click="doConfirm">
- {{ $t("common.confirm") }}
+ <NButton
+ type="primary"
+ :disabled="!allowConfirm"
+ @click="doConfirm"
+ >
+ {{ isCreating ? $t("common.save") : $t("common.confirm") }}
</NButton>
</div>
</div>
@@ -75,6 +79,28 @@ const title = computed(() => {
}
});
+const allowConfirm = computed(() => {
+ if (!formRef.value) {
+ return true;
+ }
+
+ if (!isCreating.value) {
+ return true;
+ }
+
+ const formState = formRef.value.getFormState();
+ if (props.resourceType === "DATABASE_GROUP") {
+ return formState.resourceId && formState.environmentId;
+ } else if (props.resourceType === "SCHEMA_GROUP") {
+ return (
+ formState.resourceId &&
+ formState.environmentId &&
+ formState.selectedDatabaseGroupId
+ );
+ }
+ return false;
+});
+
const doDelete = () => {
dialog.error({
title: "Confirm to delete",
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
index ebbc675656..b452762489 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupTable.vue
@@ -5,6 +5,7 @@
:row-clickable="true"
row-key="name"
class="border"
+ @click-row="clickDatabaseGroup"
>
<template #item="{ item }: { item: FormatedDatabaseGroup }">
<div class="bb-grid-cell">
@@ -12,7 +13,7 @@
</div>
<div class="bb-grid-cell">{{ item.environment }}</div>
<div class="bb-grid-cell gap-x-2">
- <NButton size="small" @click="$emit('edit', item.databaseGroup)"
+ <NButton size="small" @click.stop="$emit('edit', item.databaseGroup)"
>Configure</NButton
>
</div>
@@ -21,16 +22,17 @@
</template>
<script lang="ts" setup>
+import { computed, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
import { BBGridColumn } from "@/bbkit";
import { useEnvironmentV1Store } from "@/store";
+import { getProjectNameAndDatabaseGroupName } from "@/store/modules/v1/common";
import { DatabaseGroup } from "@/types/proto/v1/project_service";
import { convertDatabaseGroupExprFromCEL } from "@/utils/databaseGroup/cel";
-import { computed, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
interface FormatedDatabaseGroup {
resourceId: string;
- databasePlaceholder: string;
environment: string;
databaseGroup: DatabaseGroup;
}
@@ -44,6 +46,7 @@ defineEmits<{
}>();
const { t } = useI18n();
+const router = useRouter();
const environmentStore = useEnvironmentV1Store();
const formatedDatabaseGroupList = ref<FormatedDatabaseGroup[]>([]);
@@ -63,6 +66,13 @@ const COLUMN_LIST = computed(() => {
return columns;
});
+const clickDatabaseGroup = ({ databaseGroup }: FormatedDatabaseGroup) => {
+ const [projectName, databaseGroupName] = getProjectNameAndDatabaseGroupName(
+ databaseGroup.name
+ );
+ router.push(`/projects/${projectName}/database-groups/${databaseGroupName}`);
+};
+
watch(
() => [props.databaseGroupList],
async () => {
@@ -76,7 +86,6 @@ watch(
);
list.push({
resourceId: databaseGroup.name.split("/").pop() || "",
- databasePlaceholder: databaseGroup.databasePlaceholder,
environment: environment?.title || "",
databaseGroup,
});
diff --git a/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue b/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue
new file mode 100644
index 0000000000..94f7a69c9f
--- /dev/null
+++ b/frontend/src/components/DatabaseGroup/SchemaGroupTable.vue
@@ -0,0 +1,84 @@
+<template>
+ <BBGrid
+ :column-list="COLUMN_LIST"
+ :data-source="formatedSchemaGroupList"
+ :row-clickable="true"
+ row-key="name"
+ class="border"
+ @click-row="clickSchemaGroup"
+ >
+ <template #item="{ item }: { item: FormatedSchemaGroup }">
+ <div class="bb-grid-cell">
+ {{ item.resourceId }}
+ </div>
+ <div class="bb-grid-cell gap-x-2">
+ <NButton size="small" @click.stop="$emit('edit', item.schemaGroup)"
+ >Configure</NButton
+ >
+ </div>
+ </template>
+ </BBGrid>
+</template>
+
+<script lang="ts" setup>
+import { computed, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { BBGridColumn } from "@/bbkit";
+import { SchemaGroup } from "@/types/proto/v1/project_service";
+import { useRouter } from "vue-router";
+import { getProjectNameAndDatabaseGroupNameAndSchemaGroupName } from "@/store/modules/v1/common";
+
+interface FormatedSchemaGroup {
+ resourceId: string;
+ schemaGroup: SchemaGroup;
+}
+
+const props = defineProps<{
+ schemaGroupList: SchemaGroup[];
+}>();
+
+defineEmits<{
+ (event: "edit", schemaGroup: SchemaGroup): void;
+}>();
+
+const { t } = useI18n();
+const router = useRouter();
+const formatedSchemaGroupList = ref<FormatedSchemaGroup[]>([]);
+
+const COLUMN_LIST = computed(() => {
+ const columns: BBGridColumn[] = [
+ { title: t("common.name"), width: "1fr" },
+ {
+ title: "",
+ width: "10rem",
+ },
+ ];
+
+ return columns;
+});
+
+const clickSchemaGroup = ({ schemaGroup }: FormatedSchemaGroup) => {
+ const [projectName, databaseGroupName, schemaGroupName] =
+ getProjectNameAndDatabaseGroupNameAndSchemaGroupName(schemaGroup.name);
+ router.push(
+ `/projects/${projectName}/database-groups/${databaseGroupName}/schema-groups/${schemaGroupName}`
+ );
+};
+
+watch(
+ () => [props.schemaGroupList],
+ () => {
+ const list: FormatedSchemaGroup[] = [];
+ for (const schemaGroup of props.schemaGroupList) {
+ list.push({
+ resourceId: schemaGroup.name.split("/").pop() || "",
+ schemaGroup,
+ });
+ }
+ formatedSchemaGroupList.value = list;
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/plugins/cel/types/factor.ts b/frontend/src/plugins/cel/types/factor.ts
index aa9d61df41..5eea10a06c 100644
--- a/frontend/src/plugins/cel/types/factor.ts
+++ b/frontend/src/plugins/cel/types/factor.ts
@@ -25,7 +25,7 @@ export const StringFactorList = [
"request.export_format",
// Database/table group related factors
- "resource.environment_id", // using `environment.resource_id`
+ "resource.environment_name", // using `environment.name`
"resource.database_name",
"resource.table_name",
] as const;
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 5d98c3f33d..a4a64fb10b 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -1049,6 +1049,30 @@ const routes: Array<RouteRecordRaw> = [
},
props: { content: true },
},
+ // Resource name related routes.
+ {
+ path: "projects/:projectName",
+ children: [
+ {
+ path: "database-groups/:databaseGroupName",
+ name: "workspace.database-group.detail",
+ components: {
+ content: () => import("../views/DatabaseGroupDetail.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: true,
+ },
+ {
+ path: "database-groups/:databaseGroupName/schema-groups/:schemaGroupName",
+ name: "workspace.database-group.schema-group.detail",
+ components: {
+ content: () => import("../views/SchemaGroupDetail.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: true,
+ },
+ ],
+ },
],
},
],
@@ -1394,6 +1418,7 @@ router.beforeEach((to, from, next) => {
to.name === "workspace.issue" ||
to.name === "workspace.environment" ||
to.name === "sql-editor.home" ||
+ to.name?.toString().startsWith("workspace.database-group") ||
to.name?.toString().startsWith("sheets") ||
(to.name?.toString().startsWith("setting") &&
to.name?.toString() != "setting.workspace.gitops.detail" &&
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index f2167a7c7a..083d21b41e 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -44,6 +44,10 @@ export const useDBGroupStore = defineStore("db-group", () => {
);
};
+ const getDBGroupByName = (name: string) => {
+ return dbGroupMapById.value.get(name);
+ };
+
const createDatabaseGroup = async (
projectName: string,
databaseGroup: DatabaseGroup,
@@ -99,13 +103,28 @@ export const useDBGroupStore = defineStore("db-group", () => {
return schemaGroup;
};
- const getOrFetchSchemaListByDBGroupName = async (dbGroupName: string) => {
+ const getOrFetchSchemaGroupListByDBGroupName = async (
+ dbGroupName: string
+ ) => {
const { schemaGroups } = await projectServiceClient.listSchemaGroups({
parent: dbGroupName,
});
+ for (const schemaGroup of schemaGroups) {
+ schemaGroupMapById.value.set(schemaGroup.name, schemaGroup);
+ }
return schemaGroups;
};
+ const getSchemaGroupListByDBGroupName = (dbGroupName: string) => {
+ return Array.from(schemaGroupMapById.value.values()).filter((schemaGroup) =>
+ schemaGroup.name.startsWith(dbGroupName)
+ );
+ };
+
+ const getSchemaGroupByName = (name: string) => {
+ return schemaGroupMapById.value.get(name);
+ };
+
const createSchemaGroup = async (
dbGroupName: string,
schemaGroup: SchemaGroup,
@@ -150,11 +169,14 @@ export const useDBGroupStore = defineStore("db-group", () => {
getOrFetchDBGroupById,
getOrFetchDBGroupListByProjectName,
getDBGroupListByProjectName,
+ getDBGroupByName,
createDatabaseGroup,
updateDatabaseGroup,
deleteDatabaseGroup,
getOrFetchSchemaGroupById,
- getOrFetchSchemaListByDBGroupName,
+ getOrFetchSchemaGroupListByDBGroupName,
+ getSchemaGroupListByDBGroupName,
+ getSchemaGroupByName,
createSchemaGroup,
updateSchemaGroup,
deleteSchemaGroup,
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 94c1692260..eeef1c73b1 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -221,6 +221,21 @@ export const useRouterStore = defineStore("router", {
}
}
+ {
+ // /projects/proj-nt-iq3z/database-groups/test/schema-groups/asd123
+ const schemaGroupDetailComponents = currentRoute.path.match(
+ "/projects/([0-9a-zA-Z_-]+)/database-groups/([0-9a-zA-Z_-]+)/schema-groups/([0-9a-zA-Z_-]+)"
+ ) || ["/", undefined];
+
+ if (schemaGroupDetailComponents.length === 4) {
+ return {
+ projectName: schemaGroupDetailComponents[1],
+ databaseGroupName: schemaGroupDetailComponents[2],
+ schemaGroupName: schemaGroupDetailComponents[3],
+ };
+ }
+ }
+
return {};
},
},
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index bf05ffd163..372b24d285 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -17,6 +17,8 @@ export const idpNamePrefix = "idps/";
export const policyNamePrefix = "policies/";
export const settingNamePrefix = "settings/";
export const sheetNamePrefix = "sheets/";
+export const databaseGroupNamePrefix = "databaseGroups/";
+export const schemaGroupNamePrefix = "schemaGroups/";
export const getNameParentTokens = (
name: string,
@@ -81,6 +83,35 @@ export const getIdentityProviderResourceId = (name: string): ResourceId => {
return tokens[0];
};
+export const getProjectNameAndDatabaseGroupName = (name: string): string[] => {
+ const tokens = getNameParentTokens(name, [
+ projectNamePrefix,
+ databaseGroupNamePrefix,
+ ]);
+
+ if (tokens.length !== 2) {
+ return ["", ""];
+ }
+
+ return tokens;
+};
+
+export const getProjectNameAndDatabaseGroupNameAndSchemaGroupName = (
+ name: string
+): string[] => {
+ const tokens = getNameParentTokens(name, [
+ projectNamePrefix,
+ databaseGroupNamePrefix,
+ schemaGroupNamePrefix,
+ ]);
+
+ if (tokens.length !== 3) {
+ return ["", "", ""];
+ }
+
+ return tokens;
+};
+
export const getEnvironmentPathByLegacyEnvironment = (
env: Environment
): string => {
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 980fccb8a5..9284f089f3 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -68,6 +68,11 @@ export type RouterSlug = {
sheetSlug?: string;
sqlReviewPolicySlug?: string;
ssoName?: string;
+
+ // Resource names.
+ projectName?: string;
+ databaseGroupName?: string;
+ schemaGroupName?: string;
};
// Quick Action Type
diff --git a/frontend/src/utils/databaseGroup/cel.ts b/frontend/src/utils/databaseGroup/cel.ts
index 62f9adf3bd..14e16d62ac 100644
--- a/frontend/src/utils/databaseGroup/cel.ts
+++ b/frontend/src/utils/databaseGroup/cel.ts
@@ -17,17 +17,24 @@ export const stringifyDatabaseGroupExpr = (
databaseGroupExpr: DatabaseGroupExpr
): string => {
const { environmentId, conditionGroupExpr } = databaseGroupExpr;
- return convertToCELString({
- operator: "_&&_",
- args: [
- // Make the environment ID a condition first to avoid confusion when converting from CEL string.
- {
- operator: "_==_",
- args: ["resource.environment_id", environmentId],
- },
- conditionGroupExpr,
- ],
- });
+ if (conditionGroupExpr.args.length > 0) {
+ return convertToCELString({
+ operator: "_&&_",
+ args: [
+ // Make the environment ID a condition first to avoid confusion when converting from CEL string.
+ {
+ operator: "_==_",
+ args: ["resource.environment_name", environmentId],
+ },
+ conditionGroupExpr,
+ ],
+ });
+ } else {
+ return convertToCELString({
+ operator: "_==_",
+ args: ["resource.environment_name", environmentId],
+ });
+ }
};
export const convertDatabaseGroupExprFromCEL = async (
@@ -57,6 +64,12 @@ export const convertDatabaseGroupExprFromCEL = async (
const getEnvironmentIdAndConditionExpr = (
expr: SimpleExpr
): [string, ConditionGroupExpr] => {
+ if (expr.operator === "_==_") {
+ const [left, right] = expr.args;
+ if (left === "resource.environment_name") {
+ return [right as string, emptySimpleExpr()];
+ }
+ }
if (expr.operator !== "_&&_") {
throw ["", emptySimpleExpr()];
}
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
new file mode 100644
index 0000000000..49160176bb
--- /dev/null
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -0,0 +1,229 @@
+<template>
+ <div
+ v-if="state.isLoaded"
+ class="flex-1 overflow-auto focus:outline-none"
+ tabindex="0"
+ v-bind="$attrs"
+ >
+ <main class="flex-1 relative overflow-y-auto">
+ <!-- Highlight Panel -->
+ <div
+ class="px-4 space-y-2 lg:space-y-0 lg:flex lg:items-center lg:justify-between"
+ >
+ <div class="flex-1 min-w-0 shrink-0">
+ <!-- Summary -->
+ <div class="flex items-center">
+ <div>
+ <div class="flex items-center">
+ <h1
+ class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate flex items-center gap-x-3"
+ >
+ {{ databaseGroupName }}
+ <BBBadge text="Group" :can-remove="false" class="text-xs" />
+ </h1>
+ </div>
+ </div>
+ </div>
+ <dl
+ class="flex flex-col space-y-1 md:space-y-0 md:flex-row md:flex-wrap"
+ >
+ <dt class="sr-only">{{ $t("common.environment") }}</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel"
+ >{{ $t("common.environment") }}&nbsp;-&nbsp;</span
+ >
+ <EnvironmentV1Name
+ :environment="state.environment"
+ icon-class="textinfolabel"
+ />
+ </dd>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel"
+ >{{ $t("common.project") }}&nbsp;-&nbsp;</span
+ >
+ <ProjectV1Name :project="project" hash="#database-groups" />
+ </dd>
+ </dl>
+ </div>
+
+ <div
+ class="flex flex-row justify-end items-center flex-wrap shrink gap-x-2 gap-y-2"
+ >
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="handleEditDatabaseGroup"
+ >
+ Configure
+ </button>
+ </div>
+ </div>
+
+ <hr class="my-4" />
+
+ <div class="w-full px-3 max-w-5xl grid grid-cols-5 gap-x-6">
+ <div class="col-span-3">
+ <p class="pl-1 text-lg mb-2">Condition</p>
+ <ExprEditor
+ :expr="state.expr!"
+ :allow-admin="false"
+ :resource-type="'DATABASE_GROUP'"
+ />
+ </div>
+ <div class="col-span-2">
+ <p class="text-lg mb-2">Databases</p>
+ <MatchedDatabaseView
+ :project="project"
+ :environment-id="state.environment?.name || ''"
+ :expr="state.expr!"
+ />
+ </div>
+ </div>
+
+ <hr class="mt-8 my-4" />
+ <div class="w-full max-w-5xl px-4">
+ <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"
+ >
+ New table group
+ </button>
+ </div>
+ </div>
+ <SchemaGroupTable
+ :schema-group-list="schemaGroupList"
+ @edit="handleEditSchemaGroup"
+ />
+ </div>
+ </main>
+ </div>
+
+ <DatabaseGroupPanel
+ v-if="editState.showConfigurePanel"
+ :project="project"
+ :resource-type="editState.type"
+ :database-group="editState.databaseGroup"
+ @close="editState.showConfigurePanel = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { onMounted, reactive, computed, watch } from "vue";
+import {
+ useDBGroupStore,
+ useEnvironmentV1Store,
+ useProjectV1Store,
+} from "@/store";
+import {
+ databaseGroupNamePrefix,
+ projectNamePrefix,
+} from "@/store/modules/v1/common";
+import { DatabaseGroup, SchemaGroup } from "@/types/proto/v1/project_service";
+import { convertDatabaseGroupExprFromCEL } from "@/utils/databaseGroup/cel";
+import { ConditionGroupExpr } from "@/plugins/cel";
+import { Environment } from "@/types/proto/v1/environment_service";
+import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
+import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
+import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
+import SchemaGroupTable from "@/components/DatabaseGroup/SchemaGroupTable.vue";
+import { ResourceType } from "@/components/DatabaseGroup/common/ExprEditor/context";
+
+interface LocalState {
+ isLoaded: boolean;
+ environment?: Environment;
+ expr?: ConditionGroupExpr;
+}
+
+interface EditDatabaseGroupState {
+ showConfigurePanel: boolean;
+ type: ResourceType;
+ databaseGroup?: DatabaseGroup | SchemaGroup;
+}
+
+const props = defineProps({
+ projectName: {
+ required: true,
+ type: String,
+ },
+ databaseGroupName: {
+ required: true,
+ type: String,
+ },
+});
+
+const environmentStore = useEnvironmentV1Store();
+const projectStore = useProjectV1Store();
+const dbGroupStore = useDBGroupStore();
+const state = reactive<LocalState>({
+ isLoaded: false,
+});
+const editState = reactive<EditDatabaseGroupState>({
+ showConfigurePanel: false,
+ type: "DATABASE_GROUP",
+});
+const databaseGroupResourceName = computed(() => {
+ return `${projectNamePrefix}${props.projectName}/${databaseGroupNamePrefix}${props.databaseGroupName}`;
+});
+const databaseGroup = computed(() => {
+ return dbGroupStore.getDBGroupByName(databaseGroupResourceName.value);
+});
+const schemaGroupList = computed(() => {
+ return dbGroupStore.getSchemaGroupListByDBGroupName(
+ databaseGroupResourceName.value
+ );
+});
+const project = computed(() => {
+ return projectStore.getProjectByName(
+ `${projectNamePrefix}${props.projectName}`
+ );
+});
+
+onMounted(async () => {
+ await dbGroupStore.getOrFetchDBGroupById(databaseGroupResourceName.value);
+});
+
+const handleEditDatabaseGroup = () => {
+ editState.type = "DATABASE_GROUP";
+ editState.databaseGroup = databaseGroup.value;
+ editState.showConfigurePanel = true;
+};
+
+const handleCreateSchemaGroup = () => {
+ editState.type = "SCHEMA_GROUP";
+ editState.databaseGroup = undefined;
+ editState.showConfigurePanel = true;
+};
+
+const handleEditSchemaGroup = (schemaGroup: SchemaGroup) => {
+ editState.type = "SCHEMA_GROUP";
+ editState.databaseGroup = schemaGroup;
+ editState.showConfigurePanel = true;
+};
+
+watch(
+ () => [databaseGroup.value],
+ async () => {
+ if (!databaseGroup.value) {
+ return;
+ }
+
+ const expression = databaseGroup.value.databaseExpr?.expression ?? "";
+ const convertResult = await convertDatabaseGroupExprFromCEL(expression);
+ state.environment = environmentStore.getEnvironmentByName(
+ convertResult.environmentId
+ );
+ state.expr = convertResult.conditionGroupExpr;
+ await dbGroupStore.getOrFetchSchemaGroupListByDBGroupName(
+ databaseGroup.value.name
+ );
+ state.isLoaded = true;
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/views/SchemaGroupDetail.vue b/frontend/src/views/SchemaGroupDetail.vue
new file mode 100644
index 0000000000..3c16e8a786
--- /dev/null
+++ b/frontend/src/views/SchemaGroupDetail.vue
@@ -0,0 +1,177 @@
+<template>
+ <div
+ v-if="state.isLoaded"
+ class="flex-1 overflow-auto focus:outline-none"
+ tabindex="0"
+ v-bind="$attrs"
+ >
+ <main class="flex-1 relative overflow-y-auto">
+ <!-- Highlight Panel -->
+ <div
+ class="px-4 space-y-2 lg:space-y-0 lg:flex lg:items-center lg:justify-between"
+ >
+ <div class="flex-1 min-w-0 shrink-0">
+ <!-- Summary -->
+ <div class="flex items-center">
+ <div>
+ <div class="flex items-center">
+ <h1
+ class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate flex items-center gap-x-3"
+ >
+ {{ schemaGroupName }}
+ <BBBadge text="Group" :can-remove="false" class="text-xs" />
+ </h1>
+ </div>
+ </div>
+ </div>
+ <dl
+ class="flex flex-col space-y-1 md:space-y-0 md:flex-row md:flex-wrap"
+ >
+ <dt class="sr-only">{{ $t("common.environment") }}</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel"
+ >{{ $t("common.environment") }}&nbsp;-&nbsp;</span
+ >
+ <EnvironmentV1Name
+ :environment="state.environment"
+ icon-class="textinfolabel"
+ />
+ </dd>
+ <dt class="sr-only">{{ $t("common.instance") }}</dt>
+ <dt class="sr-only">{{ $t("common.project") }}</dt>
+ <dd class="flex items-center text-sm md:mr-4">
+ <span class="textlabel"
+ >{{ $t("common.project") }}&nbsp;-&nbsp;</span
+ >
+ <ProjectV1Name :project="project" hash="#database-groups" />
+ </dd>
+ </dl>
+ </div>
+
+ <div
+ class="flex flex-row justify-end items-center flex-wrap shrink gap-x-2 gap-y-2"
+ >
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="state.showConfigurePanel = true"
+ >
+ Configure
+ </button>
+ </div>
+ </div>
+
+ <hr class="my-4" />
+
+ <div class="w-full px-3 max-w-5xl grid grid-cols-5 gap-x-6">
+ <div class="col-span-3">
+ <p class="pl-1 text-lg mb-2">Condition</p>
+ <ExprEditor
+ :expr="state.expr!"
+ :allow-admin="false"
+ :resource-type="'SCHEMA_GROUP'"
+ />
+ </div>
+ <div class="col-span-2">
+ <p class="text-lg mb-2">Databases</p>
+ <MatchedDatabaseView
+ :project="project"
+ :environment-id="state.environment?.name || ''"
+ :expr="state.expr!"
+ />
+ </div>
+ </div>
+ </main>
+ </div>
+
+ <DatabaseGroupPanel
+ v-if="state.showConfigurePanel"
+ :project="project"
+ :resource-type="'SCHEMA_GROUP'"
+ :database-group="schemaGroup"
+ @close="state.showConfigurePanel = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { reactive, computed } from "vue";
+import {
+ useDBGroupStore,
+ useEnvironmentV1Store,
+ useProjectV1Store,
+} from "@/store";
+import {
+ databaseGroupNamePrefix,
+ projectNamePrefix,
+ schemaGroupNamePrefix,
+} from "@/store/modules/v1/common";
+import { convertDatabaseGroupExprFromCEL } from "@/utils/databaseGroup/cel";
+import { ConditionGroupExpr } from "@/plugins/cel";
+import { Environment } from "@/types/proto/v1/environment_service";
+import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
+import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
+import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
+import { watch } from "vue";
+
+interface LocalState {
+ isLoaded: boolean;
+ showConfigurePanel: boolean;
+ environment?: Environment;
+ expr?: ConditionGroupExpr;
+}
+
+const props = defineProps({
+ projectName: {
+ required: true,
+ type: String,
+ },
+ databaseGroupName: {
+ required: true,
+ type: String,
+ },
+ schemaGroupName: {
+ required: true,
+ type: String,
+ },
+});
+
+const environmentStore = useEnvironmentV1Store();
+const projectStore = useProjectV1Store();
+const dbGroupStore = useDBGroupStore();
+const state = reactive<LocalState>({
+ isLoaded: false,
+ showConfigurePanel: false,
+});
+const project = computed(() => {
+ return projectStore.getProjectByName(
+ `${projectNamePrefix}${props.projectName}`
+ );
+});
+const schemaGroup = computed(() => {
+ return dbGroupStore.getSchemaGroupByName(
+ `${projectNamePrefix}${props.projectName}/${databaseGroupNamePrefix}${props.databaseGroupName}/${schemaGroupNamePrefix}${props.schemaGroupName}`
+ );
+});
+
+watch(
+ () => [props, schemaGroup.value],
+ async () => {
+ const schemaGroup = await dbGroupStore.getOrFetchSchemaGroupById(
+ `${projectNamePrefix}${props.projectName}/${databaseGroupNamePrefix}${props.databaseGroupName}/${schemaGroupNamePrefix}${props.schemaGroupName}`
+ );
+
+ const expression = schemaGroup.tableExpr?.expression ?? "";
+ const convertResult = await convertDatabaseGroupExprFromCEL(expression);
+ const environment = environmentStore.getEnvironmentByName(
+ convertResult.environmentId
+ );
+
+ state.environment = environment;
+ state.expr = convertResult.conditionGroupExpr;
+ state.isLoaded = true;
+ },
+ {
+ immediate: true,
+ }
+);
+</script>