Skip to content

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

chore: add filterable to affected table select (#11920)

boojack527a9c85ace0
diff --git a/frontend/src/components/ChangeHistory/AffectedTableSelect.vue b/frontend/src/components/ChangeHistory/AffectedTableSelect.vue
index b6ce61c453..2493dae06f 100644
--- a/frontend/src/components/ChangeHistory/AffectedTableSelect.vue
+++ b/frontend/src/components/ChangeHistory/AffectedTableSelect.vue
@@ -2,20 +2,25 @@
<NSelect
:value="selectedKey"
:options="affectedTableOptions"
+ :filter="filterByTitle"
+ filterable
+ :render-label="renderLabel"
@update:value="updateSelectedKey"
/>
</template>
-<script setup lang="ts">
-import { orderBy, uniqBy } from "lodash-es";
+<script setup lang="tsx">
+import { isEqual, orderBy, uniqBy } from "lodash-es";
+import { NSelect } from "naive-ui";
import type { SelectOption } from "naive-ui";
-import { computed, h } from "vue";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
import type { AffectedTable } from "@/types";
import { EmptyAffectedTable } from "@/types";
import type { ChangeHistory } from "@/types/proto/v1/database_service";
import {
- getAffectedTableDisplayName,
getAffectedTablesOfChangeHistory,
+ stringifyAffectedTable,
} from "@/utils";
type AffectedTableSelectOption = SelectOption & {
@@ -31,6 +36,8 @@ const emit = defineEmits<{
(event: "update:affected-table", affectedTable: AffectedTable): void;
}>();
+const { t } = useI18n();
+
const affectedTables = computed(() => {
return [
EmptyAffectedTable,
@@ -48,25 +55,39 @@ const affectedTables = computed(() => {
];
});
+const filterByTitle = (pattern: string, option: SelectOption) => {
+ const { affectedTable } = option as AffectedTableSelectOption;
+ pattern = pattern.toLowerCase();
+ return affectedTable.table.toLowerCase().includes(pattern);
+};
+
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 renderLabel = (option: SelectOption) => {
+ const { affectedTable } = option as AffectedTableSelectOption;
+ if (isEqual(affectedTable, EmptyAffectedTable)) {
+ return t("change-history.all-tables");
+ }
+ const name = stringifyAffectedTable(affectedTable);
+ if (affectedTable.dropped) {
+ return (
+ <div class="w-full flex flex-row justify-between items-center gap-1">
+ <span class="truncate">{name}</span>
+ <span class="shrink-0">(Dropped)</span>
+ </div>
+ );
+ }
+ return <span class="truncate">{name}</span>;
+};
+
const selectedKey = computed(() => {
return JSON.stringify(props.affectedTable);
});
diff --git a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue
index a21ab308ee..205b8d0ff4 100644
--- a/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue
+++ b/frontend/src/components/ChangeHistory/ChangeHistoryTable.vue
@@ -47,7 +47,6 @@ import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { useUserStore } from "@/store";
import type { ComposedDatabase } from "@/types";
-import type { AffectedTable } from "@/types/changeHistory";
import type { ChangeHistory } from "@/types/proto/v1/database_service";
import {
ChangeHistory_Status,
@@ -63,6 +62,7 @@ import {
extractProjectResourceName,
humanizeDurationV1,
isDescendantOf,
+ getAffectedTableDisplayName,
} from "@/utils";
import HumanizeDate from "../misc/HumanizeDate.vue";
import ChangeHistoryStatusIcon from "./ChangeHistoryStatusIcon.vue";
@@ -264,18 +264,6 @@ const creatorOfChangeHistory = (history: ChangeHistory) => {
return useUserStore().getUserByEmail(email);
};
-const getAffectedTableDisplayName = (affectedTable: AffectedTable) => {
- const { schema, table, dropped } = affectedTable;
- let name = table;
- if (schema !== "") {
- name = `${schema}.${table}`;
- }
- if (dropped) {
- name = `${name} (deleted)`;
- }
- return name;
-};
-
const allowToSelectChangeHistory = (history: ChangeHistory) => {
return (
history.status === ChangeHistory_Status.DONE &&
diff --git a/frontend/src/utils/v1/changeHistory.ts b/frontend/src/utils/v1/changeHistory.ts
index db8ba30e46..90db37f847 100644
--- a/frontend/src/utils/v1/changeHistory.ts
+++ b/frontend/src/utils/v1/changeHistory.ts
@@ -83,17 +83,21 @@ export const getAffectedTablesOfChangeHistory = (
);
};
+export const stringifyAffectedTable = (affectedTable: AffectedTable) => {
+ const { schema, table } = affectedTable;
+ if (schema !== "") {
+ return `${schema}.${table}`;
+ }
+ return table;
+};
+
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) {
+ let name = stringifyAffectedTable(affectedTable);
+ if (affectedTable.dropped) {
name = `${name} (deleted)`;
}
return name;