Skip to content

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

chore: update change history data table (#12294)

boojack0a5b676842a9
diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue b/frontend/src/components/ChangeHistory/ChangeHistoryDataTable.vue
similarity index 74%
rename from frontend/src/components/ChangeHistory/ChangeHistoryTable.vue
rename to frontend/src/components/ChangeHistory/ChangeHistoryDataTable.vue
index 9e7c6bb9e4..0b9ed50e24 100644
--- a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue
+++ b/frontend/src/components/ChangeHistory/ChangeHistoryDataTable.vue
@@ -1,51 +1,26 @@
<template>
- <div
- ref="containerRef"
- class="overflow-x-hidden flex flex-col gap-y-4"
- :data-width="containerWidth"
- >
- <div
- v-for="(section, i) in historySectionList"
- :key="i"
- class="flex flex-col gap-y-1"
- >
- <router-link v-if="section.link" :to="section.link" class="normal-link">
- {{ section.title }}
- </router-link>
- <h1 v-else>
- {{ section.title }}
- </h1>
- <NDataTable
- :columns="columnList"
- :data="section.list"
- :row-key="(history: ChangeHistory) => history.name"
- :striped="true"
- :scroll-x="containerWidth - 2"
- :scrollbar-props="{
- trigger: 'none',
- }"
- :row-props="rowProps"
- :checked-row-keys="selectedChangeHistoryNames"
- row-class-name="cursor-pointer"
- style="--n-td-padding: 0.375rem 0.5rem; --n-th-padding: 0.375rem 0.5rem"
- @update:checked-row-keys="
- (keys: string[]) => $emit('update:selected-change-history-names', keys)"
- />
- </div>
- </div>
+ <NDataTable
+ size="small"
+ :columns="columnList"
+ :data="changeHistories"
+ :row-key="(history: ChangeHistory) => history.name"
+ :striped="true"
+ :row-props="rowProps"
+ :checked-row-keys="selectedChangeHistoryNames"
+ @update:checked-row-keys="
+ (keys) => $emit('update:selected-change-history-names', keys as string[])
+ "
+ />
</template>
<script lang="tsx" setup>
-import { useElementSize } from "@vueuse/core";
-import { type DataTableColumn } from "naive-ui";
-import { computed, ref } from "vue";
+import { type DataTableColumn, NDataTable } from "naive-ui";
+import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { RouterLink } from "vue-router";
-import type { BBTableSectionDataSource } from "@/bbkit/types";
import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";
import { useUserStore } from "@/store";
-import type { ComposedDatabase } from "@/types";
import type { ChangeHistory } from "@/types/proto/v1/database_service";
import {
ChangeHistory_Status,
@@ -64,14 +39,11 @@ import {
import HumanizeDate from "../misc/HumanizeDate.vue";
import ChangeHistoryStatusIcon from "./ChangeHistoryStatusIcon.vue";
-type Mode = "DATABASE" | "PROJECT";
-
const props = defineProps<{
- mode?: Mode;
- databaseSectionList: ComposedDatabase[];
- historySectionList: BBTableSectionDataSource<ChangeHistory>[];
+ changeHistories: ChangeHistory[];
selectedChangeHistoryNames?: string[];
customClick?: boolean;
+ showSelection?: boolean;
}>();
const emit = defineEmits<{
@@ -79,16 +51,14 @@ const emit = defineEmits<{
(event: "row-click", id: string): void;
}>();
-const containerRef = ref<HTMLDivElement>();
const router = useRouter();
const { t } = useI18n();
-const { width: containerWidth } = useElementSize(containerRef);
const columnList = computed(() => {
const columns: (DataTableColumn<ChangeHistory> & { hide?: boolean })[] = [
{
type: "selection",
- hide: props.mode !== "DATABASE",
+ hide: !props.showSelection,
width: "2rem",
disabled: (history) => {
return !allowToSelectChangeHistory(history);
@@ -112,7 +82,6 @@ const columnList = computed(() => {
},
{
key: "type",
- hide: props.mode !== "DATABASE",
title: t("change-history.change-type"),
width: "4rem",
render: (history) => {
@@ -176,21 +145,20 @@ const columnList = computed(() => {
},
{
key: "tables",
- hide: props.mode !== "DATABASE",
title: t("db.tables"),
width: "15rem",
resizable: true,
ellipsis: true,
render: (history) => {
const tables = getAffectedTablesOfChangeHistory(history);
- const content = tables.map(getAffectedTableDisplayName).join(", ");
return (
- <TextOverflowPopover
- content={content}
- maxLength={100}
- placement="bottom"
- class="inline-flex items-center truncate max-w-full"
- />
+ <p class="space-x-2 truncate">
+ {tables.map((table) => (
+ <span class={table.dropped ? "text-gray-400 italic" : ""}>
+ {getAffectedTableDisplayName(table)}
+ </span>
+ ))}
+ </p>
);
},
},
@@ -252,6 +220,7 @@ const rowProps = (history: ChangeHistory) => {
emit("row-click", history.uid);
return;
}
+
const url = changeHistoryLink(history);
if (e.ctrlKey || e.metaKey) {
window.open(url, "_blank");
diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryDetail.vue b/frontend/src/components/ChangeHistory/ChangeHistoryDetail.vue
index 89f396fd86..63245f34a3 100644
--- a/frontend/src/components/ChangeHistory/ChangeHistoryDetail.vue
+++ b/frontend/src/components/ChangeHistory/ChangeHistoryDetail.vue
@@ -319,6 +319,7 @@ import {
toClipboard,
getStatementSize,
hasProjectPermissionV2,
+ getAffectedTableDisplayName,
} from "@/utils";
interface LocalState {
@@ -411,18 +412,6 @@ const switchShowDiff = async (showDiff: boolean) => {
state.showDiff = showDiff;
};
-const getAffectedTableDisplayName = (affectedTable: AffectedTable): string => {
- const { schema, table, dropped } = affectedTable;
- let name = table;
- if (schema !== "") {
- name = `${schema}.${table}`;
- }
- if (dropped) {
- name = `${name} (deleted)`;
- }
- return name;
-};
-
const handleAffectedTableClick = (affectedTable: AffectedTable): void => {
if (affectedTable.dropped) {
return;
diff --git a/frontend/src/components/ChangeHistory/index.ts b/frontend/src/components/ChangeHistory/index.ts
index 0c866882d3..c26b6120ef 100644
--- a/frontend/src/components/ChangeHistory/index.ts
+++ b/frontend/src/components/ChangeHistory/index.ts
@@ -1,11 +1,11 @@
import AffectedTableSelect from "./AffectedTableSelect.vue";
+import ChangeHistoryDataTable from "./ChangeHistoryDataTable.vue";
import ChangeHistoryDetail from "./ChangeHistoryDetail.vue";
import ChangeHistoryStatusIcon from "./ChangeHistoryStatusIcon.vue";
-import ChangeHistoryTable from "./ChangeHistoryTable.vue";
export {
- ChangeHistoryTable,
ChangeHistoryDetail,
ChangeHistoryStatusIcon,
AffectedTableSelect,
+ ChangeHistoryDataTable,
};
diff --git a/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue b/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue
index e9eab1f59d..442d6520c5 100644
--- a/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue
+++ b/frontend/src/components/Database/DatabaseChangeHistoryPanel.vue
@@ -74,14 +74,13 @@
</div>
</div>
- <ChangeHistoryTable
+ <ChangeHistoryDataTable
v-model:selected-change-history-names="
state.selectedChangeHistoryNameList
"
- :mode="'DATABASE'"
- :database-section-list="[database]"
- :history-section-list="changeHistorySectionList"
+ :change-histories="shownChangeHistoryList"
:custom-click="true"
+ :show-selection="true"
@row-click="(id: string) => (state.selectedChangeHistoryId = id)"
/>
</div>
@@ -125,10 +124,9 @@ import { NCheckbox } from "naive-ui";
import { computed, onBeforeMount, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import type { BBTableSectionDataSource } from "@/bbkit/types";
import {
AffectedTableSelect,
- ChangeHistoryTable,
+ ChangeHistoryDataTable,
ChangeHistoryDetail,
} from "@/components/ChangeHistory";
import { useDatabaseDetailContext } from "@/components/Database/context";
@@ -140,7 +138,6 @@ import type { ComposedDatabase } from "@/types";
import { DEFAULT_PROJECT_V1_NAME } from "@/types";
import type { AffectedTable } from "@/types/changeHistory";
import { EmptyAffectedTable } from "@/types/changeHistory";
-import type { ChangeHistory } from "@/types/proto/v1/database_service";
import {
ChangeHistory_Status,
ChangeHistory_Type,
@@ -230,17 +227,6 @@ const shownChangeHistoryList = computed(() => {
});
});
-const changeHistorySectionList = computed(
- (): BBTableSectionDataSource<ChangeHistory>[] => {
- return [
- {
- title: "",
- list: shownChangeHistoryList.value,
- },
- ];
- }
-);
-
const handleExportChangeHistory = async () => {
if (state.isExporting) {
return;
diff --git a/frontend/src/components/ProjectChangeHistoryPanel.vue b/frontend/src/components/ProjectChangeHistoryPanel.vue
index b800549cbf..39ef04ebc1 100644
--- a/frontend/src/components/ProjectChangeHistoryPanel.vue
+++ b/frontend/src/components/ProjectChangeHistoryPanel.vue
@@ -4,11 +4,21 @@
<div class="text-left textinfolabel">
{{ $t("change-history.list-limit") }}
</div>
- <ChangeHistoryTable
- :mode="'PROJECT'"
- :database-section-list="state.databaseSectionList"
- :history-section-list="state.changeHistorySectionList"
- />
+ <div v-for="(section, i) in state.changeHistorySectionList" :key="i">
+ <div class="mb-2">
+ <router-link
+ v-if="section.link"
+ :to="section.link"
+ class="normal-link"
+ >
+ {{ section.title }}
+ </router-link>
+ <h1 v-else>
+ {{ section.title }}
+ </h1>
+ </div>
+ <ChangeHistoryDataTable :change-histories="section.list" />
+ </div>
</template>
<NoDataPlaceholder v-else>
<div class="text-center">
@@ -27,7 +37,7 @@
import type { PropType } from "vue";
import { reactive, watchEffect } from "vue";
import type { BBTableSectionDataSource } from "@/bbkit/types";
-import { ChangeHistoryTable } from "@/components/ChangeHistory";
+import { ChangeHistoryDataTable } from "@/components/ChangeHistory";
import { useChangeHistoryStore } from "@/store";
import type { ComposedDatabase } from "@/types";
import type { ChangeHistory } from "@/types/proto/v1/database_service";
diff --git a/frontend/src/utils/v1/changeHistory.ts b/frontend/src/utils/v1/changeHistory.ts
index 90db37f847..01730914eb 100644
--- a/frontend/src/utils/v1/changeHistory.ts
+++ b/frontend/src/utils/v1/changeHistory.ts
@@ -98,7 +98,7 @@ export const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {
let name = stringifyAffectedTable(affectedTable);
if (affectedTable.dropped) {
- name = `${name} (deleted)`;
+ name = `${name}(deleted)`;
}
return name;
};