Skip to content

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

chore: migrate changelisttable to ntable (#11768)

boojack5337522d2e73
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
index 4ccf22cee9..fc0e019b3e 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
+++ b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDashboard.vue
@@ -1,14 +1,11 @@
<template>
<div class="flex flex-col gap-y-4">
<NavBar :disable-project-select="!!project" :allow-create="allowCreate" />
-
- <ChangelistTable
+ <ChangelistDataTable
:changelists="filteredChangelists"
- :is-fetching="isFetching"
- :keyword="filter.keyword"
- :hide-project-column="!!project"
+ :loading="isFetching"
+ :show-project="!project"
/>
-
<CreateChangelistPanel
:project="project"
:disable-project-select="!!project"
@@ -23,7 +20,7 @@ import { useChangelistStore, useCurrentUserV1 } from "@/store";
import type { ComposedProject } from "@/types";
import type { Changelist } from "@/types/proto/v1/changelist_service";
import { hasProjectPermissionV2 } from "@/utils";
-import ChangelistTable from "./ChangelistTable.vue";
+import ChangelistDataTable from "./ChangelistDataTable.vue";
import CreateChangelistPanel from "./CreateChangelistPanel.vue";
import NavBar from "./NavBar.vue";
import { provideChangelistDashboardContext } from "./context";
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDataTable.vue b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDataTable.vue
new file mode 100644
index 0000000000..cf3e6223d1
--- /dev/null
+++ b/frontend/src/components/Changelist/ChangelistDashboard/ChangelistDataTable.vue
@@ -0,0 +1,126 @@
+<template>
+ <NDataTable
+ size="small"
+ :columns="columnList"
+ :data="changelists"
+ :striped="true"
+ :bordered="bordered"
+ :loading="loading"
+ :row-key="(data: Changelist) => data.name"
+ :row-props="rowProps"
+ :pagination="pagination"
+ :paginate-single-page="false"
+ />
+</template>
+
+<script setup lang="tsx">
+import { NDataTable } from "naive-ui";
+import type { DataTableColumn, PaginationProps } from "naive-ui";
+import { computed } from "vue";
+import { I18nT, useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import HumanizeDate from "@/components/misc/HumanizeDate.vue";
+import { useUserStore } from "@/store";
+import type { Changelist } from "@/types/proto/v1/changelist_service";
+import {
+ extractUserResourceName,
+ extractChangelistResourceName,
+} from "@/utils";
+import { projectForChangelist } from "../ChangelistDetail/common";
+
+type ChangelistDataTableColumn = DataTableColumn<Changelist> & {
+ hide?: boolean;
+};
+
+const props = withDefaults(
+ defineProps<{
+ changelists: Changelist[];
+ bordered?: boolean;
+ loading?: boolean;
+ pagination?: false | PaginationProps;
+ showProject: boolean;
+ }>(),
+ {
+ bordered: true,
+ showProject: true,
+ pagination: () => ({ pageSize: 20 }) as PaginationProps,
+ }
+);
+
+const { t } = useI18n();
+const router = useRouter();
+
+const columnList = computed((): ChangelistDataTableColumn[] => {
+ return (
+ [
+ {
+ key: "name",
+ title: t("changelist.self"),
+ render: (changelist) => {
+ return changelist.description;
+ },
+ },
+ {
+ key: "project",
+ title: t("common.project"),
+ width: 256,
+ hide: !props.showProject,
+ render: (changelist) => {
+ return projectForChangelist(changelist).title;
+ },
+ },
+ {
+ key: "updated-by",
+ title: t("common.updated-at"),
+ width: 256,
+ render: (changelist) => {
+ return (
+ <I18nT keypath="common.updated-at-by">
+ {{
+ time: () => <HumanizeDate date={changelist.createTime} />,
+ user: () => getUser(changelist.creator)?.title,
+ }}
+ </I18nT>
+ );
+ },
+ },
+ {
+ key: "created-by",
+ title: t("common.created-at"),
+ width: 256,
+ render: (changelist) => {
+ return (
+ <I18nT keypath="common.created-at-by">
+ {{
+ time: () => <HumanizeDate date={changelist.createTime} />,
+ user: () => getUser(changelist.creator)?.title,
+ }}
+ </I18nT>
+ );
+ },
+ },
+ ] as ChangelistDataTableColumn[]
+ ).filter((column) => !column.hide);
+});
+
+const getUser = (name: string) => {
+ const email = extractUserResourceName(name);
+ return useUserStore().getUserByEmail(email);
+};
+
+const rowProps = (changelist: Changelist) => {
+ return {
+ style: "cursor: pointer;",
+ onClick: (e: MouseEvent) => {
+ const url = router.resolve({
+ path: `changelists/${extractChangelistResourceName(changelist.name)}`,
+ }).fullPath;
+ if (e.ctrlKey || e.metaKey) {
+ window.open(url, "_blank");
+ } else {
+ window.location.href = url;
+ }
+ },
+ };
+};
+</script>
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/context.ts b/frontend/src/components/Changelist/ChangelistDashboard/context.ts
index 616a2dbe20..ab76ac0677 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/context.ts
+++ b/frontend/src/components/Changelist/ChangelistDashboard/context.ts
@@ -1,7 +1,6 @@
import Emittery from "emittery";
import type { InjectionKey, Ref } from "vue";
-import { inject, provide, ref, watch } from "vue";
-import { useRoute, useRouter } from "vue-router";
+import { inject, provide, ref } from "vue";
export type ChangelistDashboardFilter = {
project: string;
@@ -29,9 +28,6 @@ export const useChangelistDashboardContext = () => {
export const provideChangelistDashboardContext = (
project: string = "projects/-"
) => {
- const route = useRoute();
- const router = useRouter();
-
const context: ChangelistDashboardContext = {
filter: ref({
project,
@@ -41,38 +37,6 @@ export const provideChangelistDashboardContext = (
events: new Emittery(),
};
- watch(
- () => route.query.project as string,
- (project) => {
- if (project) {
- context.filter.value.project = project;
- }
- },
- { immediate: true }
- );
-
- watch(
- () => context.filter.value.project,
- (project) => {
- const projectInQuery = (route.query.project as string) ?? "";
- const projectParam = project === "projects/-" ? "" : project;
- const query = {
- ...route.query,
- project: projectParam,
- };
- if (query.project === "") {
- delete (query as any)["project"];
- }
- if (projectInQuery !== projectParam) {
- router.replace({
- ...route,
- query,
- });
- }
- },
- { immediate: true }
- );
-
provide(KEY, context);
return context;
diff --git a/frontend/src/components/Project/ProjectSwitchModal.vue b/frontend/src/components/Project/ProjectSwitchModal.vue
index d74d89d44e..94e5b1e2f6 100644
--- a/frontend/src/components/Project/ProjectSwitchModal.vue
+++ b/frontend/src/components/Project/ProjectSwitchModal.vue
@@ -32,7 +32,7 @@
:project-list="tab.list"
:current-project="currentProject"
:pagination="false"
- @click="$emit('dismiss')"
+ @row-click="$emit('dismiss')"
/>
</NTabPane>
</NTabs>
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
index c3914e26e7..b2aa37dcad 100644
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -53,7 +53,7 @@ const props = withDefaults(
);
const emit = defineEmits<{
- (event: "click"): void;
+ (event: "row-click"): void;
}>();
const router = useRouter();
@@ -116,7 +116,7 @@ const rowProps = (project: ComposedProject) => {
} else {
window.location.href = route.fullPath;
}
- emit("click");
+ emit("row-click");
},
};
};