Skip to content

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

feat(frontend): add revision routes and polish UI to match changelog (#18839)

boojackfcb8e92724af
diff --git a/frontend/src/components/Database/DatabaseRevisionPanel.vue b/frontend/src/components/Database/DatabaseRevisionPanel.vue
index cfc87e1d0a..d117975190 100644
--- a/frontend/src/components/Database/DatabaseRevisionPanel.vue
+++ b/frontend/src/components/Database/DatabaseRevisionPanel.vue
@@ -17,8 +17,7 @@
:loading="loading"
:revisions="list"
:show-selection="true"
- :custom-click="true"
- @row-click="(name) => (selectedRevisionName = name)"
+ @delete="refreshList"
/>
</template>
</PagedTable>
@@ -30,31 +29,14 @@
:database="database.name"
@created="handleRevisionCreated"
/>
-
- <Drawer
- :show="!!selectedRevisionName"
- @close="selectedRevisionName = undefined"
- >
- <DrawerContent
- style="width: 75vw; max-width: calc(100vw - 8rem)"
- :title="$t('common.detail')"
- >
- <RevisionDetailPanel
- v-if="selectedRevisionName"
- :database="database"
- :revision-name="selectedRevisionName"
- />
- </DrawerContent>
- </Drawer>
</template>
<script lang="ts" setup>
import { create } from "@bufbuild/protobuf";
import { NButton } from "naive-ui";
import { ref } from "vue";
-import { RevisionDataTable, RevisionDetailPanel } from "@/components/Revision";
+import { RevisionDataTable } from "@/components/Revision";
import CreateRevisionDrawer from "@/components/Revision/CreateRevisionDrawer.vue";
-import { Drawer, DrawerContent } from "@/components/v2";
import PagedTable from "@/components/v2/Model/PagedTable.vue";
import { revisionServiceClientConnect } from "@/connect";
import type { ComposedDatabase } from "@/types";
@@ -67,7 +49,6 @@ const props = defineProps<{
const { pagedRevisionTableSessionKey } = useDatabaseDetailContext();
const showCreateRevisionDrawer = ref(false);
-const selectedRevisionName = ref<string>();
const fetchRevisionList = async ({
pageToken,
@@ -91,9 +72,10 @@ const fetchRevisionList = async ({
const handleRevisionCreated = () => {
showCreateRevisionDrawer.value = false;
+ refreshList();
+};
- // Refresh the revision list to show the newly created revision
- // The PagedTable component will automatically refresh when we trigger it
- pagedRevisionTableSessionKey.value = `${pagedRevisionTableSessionKey.value}-refresh-${Date.now()}`;
+const refreshList = () => {
+ pagedRevisionTableSessionKey.value = `bb.paged-revision-table.${Date.now()}`;
};
</script>
diff --git a/frontend/src/components/Revision/RevisionDataTable.vue b/frontend/src/components/Revision/RevisionDataTable.vue
index cf217998ae..3e82ed5f90 100644
--- a/frontend/src/components/Revision/RevisionDataTable.vue
+++ b/frontend/src/components/Revision/RevisionDataTable.vue
@@ -8,14 +8,15 @@
:striped="true"
:row-props="rowProps"
:loading="loading"
+ :checked-row-keys="[...selectedRevisionNames]"
@update:checked-row-keys="
- (val) => (state.selectedRevisionNameList = new Set(val as string[]))
+ (keys) => (selectedRevisionNames = new Set(keys as string[]))
"
/>
<div
- v-if="state.selectedRevisionNameList.size > 0"
- class="sticky w-full flex items-center gap-x-2"
+ v-if="showSelection && selectedRevisionNames.size > 0"
+ class="sticky bottom-0 w-full flex items-center gap-x-2 bg-white py-2"
>
<NButton size="small" type="error" quaternary @click="onDelete">
<template #icon>
@@ -29,16 +30,13 @@
<script lang="tsx" setup>
import { TrashIcon } from "lucide-vue-next";
import { type DataTableColumn, NButton, NDataTable, useDialog } from "naive-ui";
-import { computed, reactive } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { useRevisionStore } from "@/store";
import { getDateForPbTimestampProtoEs } from "@/types";
-import {
- type Revision,
- Revision_Type,
-} from "@/types/proto-es/v1/revision_service_pb";
-import { useDatabaseDetailContext } from "../Database/context";
+import type { Revision } from "@/types/proto-es/v1/revision_service_pb";
+import { getRevisionType, revisionLink } from "@/utils/v1/revision";
import HumanizeDate from "../misc/HumanizeDate.vue";
const props = defineProps<{
@@ -48,28 +46,24 @@ const props = defineProps<{
loading?: boolean;
}>();
-interface LocalState {
- selectedRevisionNameList: Set<string>;
-}
-
const emit = defineEmits<{
- (event: "row-click", name: string): void;
+ (event: "row-click", revision: Revision): void;
+ (event: "delete"): void;
}>();
const { t } = useI18n();
const router = useRouter();
const dialog = useDialog();
const revisionStore = useRevisionStore();
-const { pagedRevisionTableSessionKey, database } = useDatabaseDetailContext();
-const state = reactive<LocalState>({
- selectedRevisionNameList: new Set(),
-});
+
+const selectedRevisionNames = ref<Set<string>>(new Set());
const columnList = computed(() => {
const columns: (DataTableColumn<Revision> & { hide?: boolean })[] = [
{
type: "selection",
- width: 40,
+ hide: !props.showSelection,
+ width: "2rem",
cellProps: () => {
return {
onClick: (e: MouseEvent) => {
@@ -77,12 +71,11 @@ const columnList = computed(() => {
},
};
},
- hide: !props.showSelection,
},
{
key: "version",
title: t("common.version"),
- width: 160,
+ minWidth: 160,
resizable: true,
render: (revision) => revision.version,
},
@@ -90,13 +83,12 @@ const columnList = computed(() => {
key: "type",
title: t("common.type"),
width: 128,
- resizable: true,
- render: (revision) => Revision_Type[revision.type],
+ render: (revision) => getRevisionType(revision.type),
},
{
key: "created-at",
title: t("common.created-at"),
- width: 128,
+ width: 180,
render: (revision) => (
<HumanizeDate
date={getDateForPbTimestampProtoEs(revision.createTime)}
@@ -111,11 +103,11 @@ const rowProps = (revision: Revision) => {
return {
onClick: (e: MouseEvent) => {
if (props.customClick) {
- emit("row-click", revision.name);
+ emit("row-click", revision);
return;
}
- const url = `/${database.value.project}/${revision.name}`;
+ const url = revisionLink(revision);
if (e.ctrlKey || e.metaKey) {
window.open(url, "_blank");
} else {
@@ -132,10 +124,11 @@ const onDelete = () => {
negativeText: t("common.cancel"),
positiveText: t("common.confirm"),
onPositiveClick: async () => {
- for (const name of state.selectedRevisionNameList) {
+ for (const name of selectedRevisionNames.value) {
await revisionStore.deleteRevision(name);
}
- pagedRevisionTableSessionKey.value = `bb.paged-revision-table.${Date.now()}`;
+ selectedRevisionNames.value = new Set();
+ emit("delete");
},
});
};
diff --git a/frontend/src/components/Revision/RevisionDetailPanel.vue b/frontend/src/components/Revision/RevisionDetailPanel.vue
index dc70e4fc43..e4ceeda3e6 100644
--- a/frontend/src/components/Revision/RevisionDetailPanel.vue
+++ b/frontend/src/components/Revision/RevisionDetailPanel.vue
@@ -1,67 +1,129 @@
<template>
- <div v-if="revision" class="w-full">
- <div class="flex flex-row items-center gap-2">
- <p class="text-lg flex gap-x-1">
- <span class="text-control">{{ $t("common.version") }}:</span>
- <span class="font-bold text-main">{{ revision.version }}</span>
- </p>
- </div>
+ <div class="focus:outline-hidden" tabindex="0" v-bind="$attrs">
<div
- class="mt-3 text-control text-base flex flex-row items-center flex-wrap gap-x-4"
+ v-if="state.loading"
+ class="flex items-center justify-center py-2 text-gray-400 text-sm"
>
- <span>
- {{ $t("database.revision.applied-at") }}:
- <HumanizeDate
- :date="getDateForPbTimestampProtoEs(revision.createTime)"
- />
- </span>
+ <BBSpin />
</div>
- </div>
+ <main v-else-if="revision" class="flex flex-col relative gap-y-6">
+ <!-- Highlight Panel -->
+ <div class="flex flex-col gap-y-4">
+ <!-- Version Title -->
+ <h2 class="text-2xl font-semibold text-main">
+ {{ revision.version }}
+ </h2>
- <div class="flex flex-col my-4">
- <p class="w-auto flex items-center text-base text-main mb-2 gap-x-2">
- <span>{{ $t("common.statement") }}</span>
- <CopyButton :content="fetchedStatement" />
- </p>
- <div class="relative">
- <NSpin v-if="loading" :show="loading" class="absolute inset-0 z-10" />
- <MonacoEditor
- class="h-auto max-h-[480px] min-h-[120px] border rounded-[3px] text-sm overflow-clip relative"
- :content="fetchedStatement"
- :readonly="true"
- :auto-height="{ min: 120, max: 480 }"
- />
- </div>
- </div>
+ <!-- Metadata Row -->
+ <div class="flex items-center gap-x-3 text-sm text-control-light">
+ <span>{{ getRevisionType(revision.type) }}</span>
+ <span v-if="formattedCreateTime">•</span>
+ <span v-if="formattedCreateTime">
+ {{ formattedCreateTime }}
+ </span>
+ </div>
+ </div>
- <div v-if="revision?.taskRun" class="my-4">
- <p class="w-auto flex items-center text-base text-main mb-2">
- {{ $t("issue.task-run.logs") }}
- </p>
- <TaskRunLogViewer :task-run-name="revision.taskRun" />
+ <div class="flex flex-col gap-y-6">
+ <!-- Task Run Logs Section -->
+ <div v-if="revision.taskRun" class="flex flex-col gap-y-2">
+ <div class="flex items-center justify-between">
+ <p class="text-lg text-main">
+ {{ $t("issue.task-run.logs") }}
+ </p>
+ <router-link
+ v-if="taskFullLink"
+ :to="taskFullLink"
+ class="flex items-center gap-x-1 text-sm text-control-light hover:text-accent transition-colors"
+ >
+ {{ $t("common.show-more") }}
+ <ArrowUpRightIcon class="w-4 h-4" />
+ </router-link>
+ </div>
+ <TaskRunLogViewer :task-run-name="revision.taskRun" />
+ </div>
+
+ <!-- Statement Section -->
+ <div class="flex flex-col gap-y-2">
+ <p class="flex items-center text-lg text-main gap-x-2">
+ {{ $t("common.statement") }}
+ <span
+ v-if="formattedStatementSize"
+ class="text-sm font-normal text-control-light"
+ >
+ ({{ formattedStatementSize }})
+ </span>
+ <CopyButton size="small" :content="state.statement" />
+ </p>
+ <MonacoEditor
+ class="h-auto max-h-[600px] min-h-[120px] border rounded-md text-sm overflow-clip relative"
+ :content="state.statement"
+ :readonly="true"
+ :auto-height="{ min: 120, max: 600 }"
+ />
+ </div>
+ </div>
+ </main>
</div>
</template>
<script lang="ts" setup>
-import { NSpin } from "naive-ui";
-import { computed, ref, watch } from "vue";
+import { ArrowUpRightIcon } from "lucide-vue-next";
+import { computed, reactive, watch } from "vue";
+import { BBSpin } from "@/bbkit";
import { MonacoEditor } from "@/components/MonacoEditor";
import { TaskRunLogViewer } from "@/components/RolloutV1/components/TaskRunLogViewer";
import { CopyButton } from "@/components/v2";
import { sheetServiceClientConnect } from "@/connect";
import { useRevisionStore } from "@/store";
-import { type ComposedDatabase, getDateForPbTimestampProtoEs } from "@/types";
-import HumanizeDate from "../misc/HumanizeDate.vue";
+import type { ComposedDatabase } from "@/types";
+import { getDateForPbTimestampProtoEs } from "@/types";
+import type { Revision } from "@/types/proto-es/v1/revision_service_pb";
+import { bytesToString } from "@/utils";
+import { extractTaskLink, getRevisionType } from "@/utils/v1/revision";
+
+interface LocalState {
+ loading: boolean;
+ statement: string;
+}
const props = defineProps<{
database: ComposedDatabase;
revisionName: string;
}>();
-const loading = ref(false);
-const fetchedStatement = ref("");
-
const revisionStore = useRevisionStore();
+const state = reactive<LocalState>({
+ loading: false,
+ statement: "",
+});
+
+const revision = computed((): Revision | undefined =>
+ revisionStore.getRevisionByName(props.revisionName)
+);
+
+const taskFullLink = computed(() => {
+ if (!revision.value?.taskRun) {
+ return "";
+ }
+ return extractTaskLink(revision.value.taskRun);
+});
+
+const formattedCreateTime = computed(() => {
+ if (!revision.value) {
+ return "";
+ }
+ return getDateForPbTimestampProtoEs(
+ revision.value.createTime
+ )?.toLocaleString();
+});
+
+const formattedStatementSize = computed(() => {
+ if (!state.statement) {
+ return "";
+ }
+ return bytesToString(new TextEncoder().encode(state.statement).length);
+});
watch(
() => props.revisionName,
@@ -70,38 +132,30 @@ watch(
return;
}
- loading.value = true;
- fetchedStatement.value = "";
+ state.loading = true;
+ state.statement = "";
try {
- const revision =
- await revisionStore.getOrFetchRevisionByName(revisionName);
- if (revision) {
- // Prepare the sheet data for statement display
- if (revision.sheet) {
- try {
- const sheet = await sheetServiceClientConnect.getSheet({
- name: revision.sheet,
- raw: true,
- });
- if (sheet.content) {
- fetchedStatement.value = new TextDecoder().decode(sheet.content);
- }
- } catch (error) {
- console.error("Failed to fetch sheet content", error);
+ const rev = await revisionStore.getOrFetchRevisionByName(revisionName);
+ if (rev?.sheet) {
+ try {
+ const sheet = await sheetServiceClientConnect.getSheet({
+ name: rev.sheet,
+ raw: true,
+ });
+ if (sheet.content) {
+ state.statement = new TextDecoder().decode(sheet.content);
}
+ } catch (error) {
+ console.error("Failed to fetch sheet content", error);
}
}
} catch (error) {
console.error("Failed to fetch revision details", error);
} finally {
- loading.value = false;
+ state.loading = false;
}
},
{ immediate: true }
);
-
-const revision = computed(() =>
- revisionStore.getRevisionByName(props.revisionName)
-);
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index aaaf4c0bc9..5c3d98d672 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1764,7 +1764,6 @@
"engine-not-supported-for-backup": "Prior backup is not supported for: {databases}",
"revision": {
"self": "Revision",
- "applied-at": "Applied at",
"filename": "Filename",
"import-revision": "Import Revision",
"select-source": "Select Source",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index cde4a3894c..3bb7778598 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1764,7 +1764,6 @@
"engine-not-supported-for-backup": "No se admite la copia de seguridad previa para: {databases}",
"revision": {
"self": "Revisión",
- "applied-at": "Aplicado en",
"filename": "Nombre del archivo",
"import-revision": "Revisión de importación",
"select-source": "Seleccionar fuente",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 2d1a51eb54..39aab7435a 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1764,7 +1764,6 @@
"engine-not-supported-for-backup": "以前のバックアップはサポートされていません: {databases}",
"revision": {
"self": "リビジョン",
- "applied-at": "申請先",
"filename": "ファイル名",
"import-revision": "インポートリビジョン",
"select-source": "ソースを選択",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 247764a803..c32c1fbb81 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1764,7 +1764,6 @@
"engine-not-supported-for-backup": "Sao lưu trước đó không được hỗ trợ cho: {databases}",
"revision": {
"self": "Bản sửa đổi",
- "applied-at": "Đã áp dụng vào",
"filename": "Tên tệp",
"import-revision": "Nhập bản sửa đổi",
"select-source": "Chọn nguồn",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 8c37c98659..a5d8a2fe3a 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1764,7 +1764,6 @@
"engine-not-supported-for-backup": "引擎不支持预备份:{databases}",
"revision": {
"self": "版本",
- "applied-at": "应用时间",
"filename": "文件名",
"import-revision": "导入版本",
"select-source": "选择来源",
diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.ts
index bce2ebce1e..e511fb3cde 100644
--- a/frontend/src/router/dashboard/projectV1.ts
+++ b/frontend/src/router/dashboard/projectV1.ts
@@ -9,6 +9,7 @@ export const PROJECT_V1_ROUTE_MASKING_EXEMPTION = `${PROJECT_V1_ROUTE_DASHBOARD}
export const PROJECT_V1_ROUTE_MASKING_EXEMPTION_CREATE = `${PROJECT_V1_ROUTE_DASHBOARD}.masking-exemption.create`;
export const PROJECT_V1_ROUTE_DATABASE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.detail`;
export const PROJECT_V1_ROUTE_DATABASE_CHANGELOG_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.changelog.detail`;
+export const PROJECT_V1_ROUTE_DATABASE_REVISION_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database.revision.detail`;
export const PROJECT_V1_ROUTE_DATABASE_GROUPS = `${PROJECT_V1_ROUTE_DASHBOARD}.database-group`;
export const PROJECT_V1_ROUTE_DATABASE_GROUPS_CREATE = `${PROJECT_V1_ROUTE_DASHBOARD}.database-group.create`;
export const PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.database-group.detail`;
@@ -392,6 +393,22 @@ const projectV1Routes: RouteRecordRaw[] = [
changelogId: route.params.changelogId,
}),
},
+ {
+ path: "revisions/:revisionId",
+ name: PROJECT_V1_ROUTE_DATABASE_REVISION_DETAIL,
+ meta: {
+ requiredPermissionList: () => ["bb.databases.get"],
+ },
+ component: () =>
+ import("@/views/DatabaseDetail/RevisionDetail.vue"),
+ props: (route) => ({
+ ...route.params,
+ project: `projects/${route.params.projectId}`,
+ instance: `instances/${route.params.instanceId}`,
+ database: `instances/${route.params.instanceId}/databases/${route.params.databaseName}`,
+ revisionId: route.params.revisionId,
+ }),
+ },
],
},
{
diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.ts
index 8d2fb7bcae..fa3433a7f8 100644
--- a/frontend/src/utils/v1/index.ts
+++ b/frontend/src/utils/v1/index.ts
@@ -12,6 +12,7 @@ export * from "./sheet";
export * from "./worksheet";
export * from "./issue";
export * from "./changelog";
+export * from "./revision";
export * from "./cel";
export * from "./advanced-search";
export * from "./iam";
diff --git a/frontend/src/utils/v1/revision.ts b/frontend/src/utils/v1/revision.ts
new file mode 100644
index 0000000000..e7d34d0c74
--- /dev/null
+++ b/frontend/src/utils/v1/revision.ts
@@ -0,0 +1,42 @@
+import { t } from "@/plugins/i18n";
+import { useDatabaseV1Store } from "@/store";
+import type { Revision } from "@/types/proto-es/v1/revision_service_pb";
+import { Revision_Type } from "@/types/proto-es/v1/revision_service_pb";
+import { databaseV1Url, extractDatabaseResourceName } from "./database";
+
+export const extractRevisionUID = (name: string): string => {
+ const pattern = /(?:^|\/)revisions\/([^/]+)(?:$|\/)/;
+ const matches = name.match(pattern);
+ return matches?.[1] ?? "";
+};
+
+export const revisionLink = (revision: Revision): string => {
+ const parts = revision.name.split("/revisions/");
+ if (parts.length !== 2) {
+ return "";
+ }
+ const { database } = extractDatabaseResourceName(revision.name);
+ const composedDatabase = useDatabaseV1Store().getDatabaseByName(database);
+ return `${databaseV1Url(composedDatabase)}/revisions/${parts[1]}`;
+};
+
+export const getRevisionType = (type: Revision_Type): string => {
+ switch (type) {
+ case Revision_Type.VERSIONED:
+ return t("database.revision.type-versioned");
+ case Revision_Type.DECLARATIVE:
+ return t("database.revision.type-declarative");
+ default:
+ return "-";
+ }
+};
+
+// Extract task link from taskRun resource name
+// e.g., "projects/xxx/rollouts/yyy/stages/zzz/tasks/aaa/taskRuns/bbb" -> "/projects/xxx/rollouts/yyy/stages/zzz/tasks/aaa"
+export const extractTaskLink = (taskRunName: string): string => {
+ const parts = taskRunName.split("/taskRuns/");
+ if (parts.length !== 2) {
+ return "";
+ }
+ return `/${parts[0]}`;
+};
diff --git a/frontend/src/views/DatabaseDetail/RevisionDetail.vue b/frontend/src/views/DatabaseDetail/RevisionDetail.vue
new file mode 100644
index 0000000000..218952fe3c
--- /dev/null
+++ b/frontend/src/views/DatabaseDetail/RevisionDetail.vue
@@ -0,0 +1,46 @@
+<template>
+ <NBreadcrumb class="mb-4">
+ <NBreadcrumbItem @click="router.push(`/${props.project}/databases`)">
+ {{ $t("common.databases") }}
+ </NBreadcrumbItem>
+ <NBreadcrumbItem @click="router.push(databaseV1Url(database))">
+ {{ database.databaseName }}
+ </NBreadcrumbItem>
+ <NBreadcrumbItem
+ @click="router.push(`${databaseV1Url(database)}#revision`)"
+ >
+ {{ $t("database.revision.self") }}
+ </NBreadcrumbItem>
+ <NBreadcrumbItem :clickable="false">
+ {{ revisionId }}
+ </NBreadcrumbItem>
+ </NBreadcrumb>
+ <RevisionDetailView
+ v-if="ready"
+ :database="database"
+ :revision-name="`${database.name}/revisions/${revisionId}`"
+ />
+ <div v-else class="flex justify-center items-center py-10">
+ <BBSpin />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { NBreadcrumb, NBreadcrumbItem } from "naive-ui";
+import { useRouter } from "vue-router";
+import { BBSpin } from "@/bbkit";
+import { RevisionDetailPanel as RevisionDetailView } from "@/components/Revision";
+import { useDatabaseV1ByName } from "@/store";
+import { databaseV1Url } from "@/utils";
+
+const props = defineProps<{
+ project: string;
+ instance: string;
+ database: string;
+ revisionId: string;
+}>();
+
+const router = useRouter();
+
+const { database, ready } = useDatabaseV1ByName(props.database);
+</script>