Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: use naive-ui components and create shared AffectedTableSelect component (#8967)
Liu Ji16319c5aaa22
diff --git a/frontend/src/components/ChangeHistory/AffectedTableSelect.vue b/frontend/src/components/ChangeHistory/AffectedTableSelect.vuenew file mode 100644index 0000000000..056192f7df--- /dev/null+++ b/frontend/src/components/ChangeHistory/AffectedTableSelect.vue@@ -0,0 +1,76 @@+<template>+ <NSelect+ :value="selectedKey"+ :options="affectedTableOptions"+ @update:value="updateSelectedKey"+ />+</template>++<script setup lang="ts">+import { orderBy, uniqBy } from "lodash-es";+import { SelectOption } from "naive-ui";+import { computed, h } from "vue";+import { AffectedTable, EmptyAffectedTable } from "@/types";+import { ChangeHistory } from "@/types/proto/v1/database_service";+import {+ getAffectedTableDisplayName,+ getAffectedTablesOfChangeHistory,+} from "@/utils";++type AffectedTableSelectOption = SelectOption & {+ affectedTable: AffectedTable;+ value: string;+};++const props = defineProps<{+ affectedTable: AffectedTable;+ changeHistoryList: ChangeHistory[];+}>();+const emit = defineEmits<{+ (event: "update:affected-table", affectedTable: AffectedTable): void;+}>();++const affectedTables = computed(() => {+ return [+ EmptyAffectedTable,+ ...orderBy(+ uniqBy(+ props.changeHistoryList+ .map((changeHistory) =>+ getAffectedTablesOfChangeHistory(changeHistory)+ )+ .flat(),+ (affectedTable) => `${affectedTable.schema}.${affectedTable.table}`+ ),+ ["dropped", "table", "schema"]+ ),+ ];+});++const affectedTableOptions = computed(() => {+ return affectedTables.value.map<AffectedTableSelectOption>((item) => {+ const key = JSON.stringify(item);+ const name = getAffectedTableDisplayName(item);+ return {+ label: name,+ value: key,+ affectedTable: item,+ renderLabel() {+ const classes = ["truncate"];+ if (item.dropped) {+ classes.push("text-gray-400");+ }+ return h("span", { class: classes, "data-key": key }, name);+ },+ };+ });+});++const selectedKey = computed(() => {+ return JSON.stringify(props.affectedTable);+});++const updateSelectedKey = (key: string, opt: AffectedTableSelectOption) => {+ emit("update:affected-table", opt.affectedTable);+};+</script>diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vueindex 64f8cde7f2..a1c70c1f00 100644--- a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue+++ b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue@@ -56,7 +56,7 @@@update:checked="handleToggleChangeHistorySelected(history)"/></BBTableCell>- <BBTableCell :left-padding="mode !== 'DATABASE' && 4">+ <BBTableCell :left-padding="mode !== 'DATABASE' ? 4 : undefined"><ChangeHistoryStatusIcon class="mx-auto" :status="history.status" /></BBTableCell><BBTableCell v-if="mode === 'DATABASE'">diff --git a/frontend/src/components/ChangeHistory/index.ts b/frontend/src/components/ChangeHistory/index.tsindex 9887fc2038..accbd967e8 100644--- a/frontend/src/components/ChangeHistory/index.ts+++ b/frontend/src/components/ChangeHistory/index.ts@@ -1,4 +1,5 @@+import AffectedTableSelect from "./AffectedTableSelect.vue";import ChangeHistoryStatusIcon from "./ChangeHistoryStatusIcon.vue";import ChangeHistoryTable from "./ChangeHistoryTable.vue";-export { ChangeHistoryTable, ChangeHistoryStatusIcon };+export { ChangeHistoryTable, ChangeHistoryStatusIcon, AffectedTableSelect };diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryForm.vue b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryForm.vueindex 7ed8ab50de..1dfbd505c5 100644--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryForm.vue+++ b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryForm.vue@@ -25,9 +25,9 @@v-model:database="state.databaseUID":project="project.uid"/>- <NSelect- v-model:value="state.affectedTableKey"- :options="affectedTableOptions"+ <AffectedTableSelect+ v-model:affected-table="state.affectedTable"+ :change-history-list="state.changeHistoryList"style="width: 12rem"/><NCheckboxGroup v-model:value="state.changeHistoryTypes">@@ -59,10 +59,10 @@</template><script setup lang="ts">-import { first } from "lodash-es";-import { NCheckbox, NCheckboxGroup, NSelect, SelectOption } from "naive-ui";+import { first, isEqual } from "lodash-es";+import { NCheckbox, NCheckboxGroup } from "naive-ui";import { computed, reactive, watch } from "vue";-import { h } from "vue";+import { AffectedTableSelect } from "@/components/ChangeHistory";import { DatabaseSelect, SearchBox } from "@/components/v2";import {useChangeHistoryStore,@@ -88,30 +88,18 @@ import { useChangelistDetailContext } from "../../context";import { useAddChangeContext } from "../context";import ChangeHistoryChangeItem from "./ChangeHistoryChangeItem.vue";import ChangeHistoryTable from "./ChangeHistoryTable";-import {- getAffectedTableDisplayName,- getAffectedTableKey,- getAffectedTablesFromChangeHistoryList,- semanticChangeHistoryType,-} from "./utils";+import { semanticChangeHistoryType } from "./utils";type LocalState = {isLoading: boolean;keyword: string;databaseUID: string | undefined;changeHistoryList: ChangeHistory[];- affectedTableKey: string | undefined;+ affectedTable: AffectedTable;changeHistoryTypes: ChangeHistory_Type[];detailChangeHistoryName: string | undefined;};-type AffectedTableSelectOption = SelectOption & {- affectedTable: AffectedTable;- value: string;-};--const ALL_TABLE_KEY = getAffectedTableKey(EmptyAffectedTable);-const { project } = useChangelistDetailContext();const { changesFromChangeHistory: changes } = useAddChangeContext();const localSheetStore = useLocalSheetStore();@@ -121,7 +109,7 @@ const state = reactive<LocalState>({keyword: "",databaseUID: undefined,changeHistoryList: [],- affectedTableKey: undefined,+ affectedTable: EmptyAffectedTable,changeHistoryTypes: [ChangeHistory_Type.DATA, ChangeHistory_Type.MIGRATE],detailChangeHistoryName: undefined,});@@ -132,29 +120,6 @@ const database = computed(() => {return useDatabaseV1Store().getDatabaseByUID(uid);});-const affectedTableOptions = computed(() => {- const affectedTables = getAffectedTablesFromChangeHistoryList(- state.changeHistoryList- );-- return affectedTables.map<AffectedTableSelectOption>((item) => {- const key = getAffectedTableKey(item);- const name = getAffectedTableDisplayName(item);- return {- label: name,- value: key,- affectedTable: item,- renderLabel() {- const classes = ["truncate"];- if (item.dropped) {- classes.push("text-gray-400");- }- return h("span", { class: classes, "data-key": key }, name);- },- };- });-});-const filteredChangeHistoryList = computed(() => {let list = [...state.changeHistoryList];const types = state.changeHistoryTypes;@@ -169,13 +134,11 @@ const filteredChangeHistoryList = computed(() => {changeHistory.version.toLowerCase().includes(kw));}- const tableKey = state.affectedTableKey;- if (tableKey && tableKey !== ALL_TABLE_KEY) {+ const { affectedTable: table } = state;+ if (!isEqual(table, EmptyAffectedTable)) {list = list.filter((changeHistory) => {const affectedTables = getAffectedTablesOfChangeHistory(changeHistory);- return affectedTables.find(- (item) => getAffectedTableKey(item) === tableKey- );+ return affectedTables.find((item) => isEqual(item, table));});}@@ -271,9 +234,9 @@ watch(watch(() => database.value?.uid, fetchChangeHistoryList, { immediate: true });watch(- affectedTableOptions,+ () => state.changeHistoryList,(options) => {- state.affectedTableKey = first(options)?.value;+ state.affectedTable = EmptyAffectedTable;},{ immediate: true });diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryTable/Tables.vue b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryTable/Tables.vueindex b00089a092..44736052a3 100644--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryTable/Tables.vue+++ b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/ChangeHistoryTable/Tables.vue@@ -10,8 +10,10 @@import { computed } from "vue";import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";import { ChangeHistory } from "@/types/proto/v1/database_service";-import { getAffectedTablesOfChangeHistory } from "@/utils";-import { getAffectedTableDisplayName } from "../utils";+import {+ getAffectedTableDisplayName,+ getAffectedTablesOfChangeHistory,+} from "@/utils";const props = defineProps<{changeHistory: ChangeHistory;diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/utils.ts b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/utils.tsindex afb75072f2..04595030f0 100644--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/utils.ts+++ b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/utils.ts@@ -1,6 +1,5 @@-import { isEqual, orderBy, uniqBy } from "lodash-es";-import { t } from "@/plugins/i18n";-import { AffectedTable, EmptyAffectedTable } from "@/types/changeHistory";+import { orderBy, uniqBy } from "lodash-es";+import { EmptyAffectedTable } from "@/types/changeHistory";import {ChangeHistory,ChangeHistory_Type,@@ -26,26 +25,6 @@ export const getAffectedTablesFromChangeHistoryList = (];};-export const getAffectedTableKey = (affectedTable: AffectedTable) => {- return JSON.stringify(affectedTable);-};--export const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {- if (isEqual(affectedTable, EmptyAffectedTable)) {- return t("change-history.all-tables");- }-- const { schema, table, dropped } = affectedTable;- let name = table;- if (schema !== "") {- name = `${schema}.${table}`;- }- if (dropped) {- name = `${name} (deleted)`;- }- return name;-};-export const semanticChangeHistoryType = (type: ChangeHistory_Type) => {switch (type) {case ChangeHistory_Type.BASELINE:diff --git a/frontend/src/components/DatabaseChangeHistoryPanel.vue b/frontend/src/components/DatabaseChangeHistoryPanel.vueindex 198f89f6fe..1e0fb54583 100644--- a/frontend/src/components/DatabaseChangeHistoryPanel.vue+++ b/frontend/src/components/DatabaseChangeHistoryPanel.vue@@ -5,20 +5,10 @@><div class="flex flex-row justify-start items-center space-x-4"><div class="w-44">- <BBSelect- :selected-item="state.selectedAffectedTable"- :item-list="affectedTables"- @select-item="(item: AffectedTable) => state.selectedAffectedTable = item"- >- <template #menuItem="{ item }">- <span- class="block w-full truncate"- :class="item.dropped && 'text-gray-400'"- >- {{ getAffectedTableDisplayName(item) }}- </span>- </template>- </BBSelect>+ <AffectedTableSelect+ v-model:affected-table="state.selectedAffectedTable"+ :change-history-list="changeHistoryList"+ /></div><div class="flex items-center"><label@@ -40,28 +30,31 @@v-if="state.loading":title="$t('change-history.refreshing-history')"/>- <BBTooltipButton- type="normal"- :disabled="!allowExportChangeHistory || state.isExporting"+ <TooltipButtontooltip-mode="DISABLED-ONLY"+ :disabled="!allowExportChangeHistory"+ :loading="state.isExporting"@click="handleExportChangeHistory">- {{ $t("change-history.export") }}+ <template #default>+ {{ $t("change-history.export") }}+ </template><template #tooltip><div class="whitespace-pre-line">{{ $t("change-history.need-to-select-first") }}</div></template>- </BBTooltipButton>- <BBTooltipButton+ </TooltipButton>+ <TooltipButtonv-if="showEstablishBaselineButton"+ tooltip-mode="DISABLED-ONLY"type="primary":disabled="!allowMigrate"- tooltip-mode="DISABLED-ONLY"- data-label="bb-establish-baseline-button"@click="state.showBaselineModal = true">- {{ $t("change-history.establish-baseline") }}+ <template #default>+ {{ $t("change-history.establish-baseline") }}+ </template><templatev-if="database.project === DEFAULT_PROJECT_V1_NAME"#tooltip@@ -76,7 +69,7 @@}}</div></template>- </BBTooltipButton>+ </TooltipButton></div></div><ChangeHistoryTable@@ -110,14 +103,16 @@import dayjs from "dayjs";import saveAs from "file-saver";import JSZip from "jszip";-import { isEqual, orderBy, uniqBy } from "lodash-es";+import { isEqual } from "lodash-es";import { NCheckbox } from "naive-ui";-import { computed, onBeforeMount, PropType, reactive } from "vue";+import { computed, onBeforeMount, PropType, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";-import { BBTooltipButton } from "@/bbkit";import { BBTableSectionDataSource } from "@/bbkit/types";-import { ChangeHistoryTable } from "@/components/ChangeHistory";+import {+ AffectedTableSelect,+ ChangeHistoryTable,+} from "@/components/ChangeHistory";import { useChangeHistoryStore, useDBSchemaV1Store } from "@/store";import { ComposedDatabase, DEFAULT_PROJECT_V1_NAME } from "@/types";import { AffectedTable, EmptyAffectedTable } from "@/types/changeHistory";@@ -133,6 +128,7 @@ import {instanceV1HasAlterSchema,getHistoryChangeType,} from "@/utils";+import { TooltipButton } from "./v2";interface LocalState {showBaselineModal: boolean;@@ -247,39 +243,6 @@ const changeHistorySectionList = computed(});-const affectedTables = computed(() => {- return [- EmptyAffectedTable,- ...orderBy(- uniqBy(- changeHistoryList.value- .map((changeHistory) =>- getAffectedTablesOfChangeHistory(changeHistory)- )- .flat(),- (affectedTable) => `${affectedTable.schema}.${affectedTable.table}`- ),- ["dropped", "table", "schema"]- ),- ];-});--const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {- if (isEqual(affectedTable, EmptyAffectedTable)) {- return t("change-history.all-tables");- }-- const { schema, table, dropped } = affectedTable;- let name = table;- if (schema !== "") {- name = `${schema}.${table}`;- }- if (dropped) {- name = `${name} (deleted)`;- }- return name;-};-const handleExportChangeHistory = async () => {if (state.isExporting) {return;@@ -349,4 +312,12 @@ const toggleChangeType = (type: string, checked: boolean) => {if (checked) state.selectedChangeType.add(type);else state.selectedChangeType.delete(type);};++watch(+ changeHistoryList,+ () => {+ state.selectedAffectedTable = EmptyAffectedTable;+ },+ { immediate: true }+);</script>diff --git a/frontend/src/components/v2/Button/TooltipButton.vue b/frontend/src/components/v2/Button/TooltipButton.vueindex 3ad3ac4be0..a6fc8c12f5 100644--- a/frontend/src/components/v2/Button/TooltipButton.vue+++ b/frontend/src/components/v2/Button/TooltipButton.vue@@ -1,5 +1,5 @@<template>- <NTooltip v-bind="tooltipProps" :disabled="!tooltipDisabled">+ <NTooltip v-bind="tooltipProps" :disabled="!tooltipEnabled"><template #trigger><NButtonv-bind="$attrs"@@ -52,9 +52,13 @@ defineEmits<{const slots = useSlots();-const tooltipDisabled = computed(() => {- if (props.tooltipMode === "ALWAYS") return false;- if (!slots.tooltip) return true;+const tooltipEnabled = computed(() => {+ // Enable tooltip when tooltipMode is "ALWAYS"+ if (props.tooltipMode === "ALWAYS") return true;+ // Disable tooltip if no tooltip contents+ if (!slots.tooltip) return false;+ // Enable tooltip if button is disabled+ // Disable tooltip otherwisereturn props.disabled;});</script>diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 3b0bdd2998..40b5c7ed1c 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -43,5 +43,6 @@ export * from "./slowQuery";export * from "./dbGroup";export * from "./quickAction";export * from "./setting";+export * from "./changeHistory";export * from "./v1";diff --git a/frontend/src/utils/v1/changeHistory.ts b/frontend/src/utils/v1/changeHistory.tsindex 5cedf09e21..a11b34f7a2 100644--- a/frontend/src/utils/v1/changeHistory.ts+++ b/frontend/src/utils/v1/changeHistory.ts@@ -1,7 +1,8 @@-import { isUndefined, orderBy, uniqBy } from "lodash-es";+import { isEqual, isUndefined, orderBy, uniqBy } from "lodash-es";import slug from "slug";+import { t } from "@/plugins/i18n";import { useDBSchemaV1Store, useDatabaseV1Store } from "@/store";-import { AffectedTable } from "@/types/changeHistory";+import { AffectedTable, EmptyAffectedTable } from "@/types/changeHistory";import {ChangeHistory,ChangeHistory_Type,@@ -86,6 +87,22 @@ export const getAffectedTablesOfChangeHistory = ();};+export const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {+ if (isEqual(affectedTable, EmptyAffectedTable)) {+ return t("change-history.all-tables");+ }++ const { schema, table, dropped } = affectedTable;+ let name = table;+ if (schema !== "") {+ name = `${schema}.${table}`;+ }+ if (dropped) {+ name = `${name} (deleted)`;+ }+ return name;+};+export const getHistoryChangeType = (type: ChangeHistory_Type) => {switch (type) {case ChangeHistory_Type.BASELINE: