Skip to content

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

feat(schema-editor): show last updater in the schema tree (#12186)

Liu Ji1e006bb037b4
diff --git a/frontend/src/bbkit/BBAvatar.vue b/frontend/src/bbkit/BBAvatar.vue
index d471bdfed1..36bc5d07ff 100644
--- a/frontend/src/bbkit/BBAvatar.vue
+++ b/frontend/src/bbkit/BBAvatar.vue
@@ -42,6 +42,7 @@ const BACKGROUND_COLOR_LIST: string[] = [
];
const sizeClassMap: Map<BBAvatarSizeType, string> = new Map([
+ ["MINI", "w-[18px] h-[18px] font-medium"],
["TINY", "w-5 h-5 font-medium"],
["SMALL", "w-6 h-6 font-medium"],
["NORMAL", "w-8 h-8 font-medium"],
@@ -50,6 +51,7 @@ const sizeClassMap: Map<BBAvatarSizeType, string> = new Map([
]);
const fontStyleClassMap: Map<BBAvatarSizeType, string> = new Map([
+ ["MINI", "0.5rem"], // customized font size
["TINY", "0.5rem"], // customized font size
["SMALL", "0.675rem"], // customized font size
["NORMAL", "0.875rem"], // text-sm
diff --git a/frontend/src/bbkit/types.ts b/frontend/src/bbkit/types.ts
index 3f43b470e8..008360224f 100644
--- a/frontend/src/bbkit/types.ts
+++ b/frontend/src/bbkit/types.ts
@@ -47,4 +47,10 @@ export type BBTabItem<T = any> = {
data?: T;
};
-export type BBAvatarSizeType = "TINY" | "SMALL" | "NORMAL" | "LARGE" | "HUGE";
+export type BBAvatarSizeType =
+ | "MINI"
+ | "TINY"
+ | "SMALL"
+ | "NORMAL"
+ | "LARGE"
+ | "HUGE";
diff --git a/frontend/src/components/SchemaEditorLite/Aside/LastUpdate.vue b/frontend/src/components/SchemaEditorLite/Aside/LastUpdate.vue
new file mode 100644
index 0000000000..428218c2dc
--- /dev/null
+++ b/frontend/src/components/SchemaEditorLite/Aside/LastUpdate.vue
@@ -0,0 +1,91 @@
+<template>
+ <NPopover
+ v-if="updater"
+ :disabled="!updateTime"
+ placement="right"
+ >
+ <template #trigger>
+ <UserAvatar :user="updater" size="MINI" />
+ </template>
+ <template #default>
+ <div class="flex flex-col items-stretch gap-2 text-sm">
+ <div class="flex justify-between gap-4">
+ <div>
+ {{ $t("branch.last-update.self") }}
+ </div>
+
+ <div class="flex justify-end gap-1">
+ <UserAvatar :user="updater" size="TINY" />
+ {{ updater?.title }}
+ </div>
+ </div>
+ <div v-if="updateTime" class="flex justify-end gap-1 text-xs">
+ {{ dayjs(updateTime).format("YYYY-MM-DD HH:mm:ss UTCZZ") }}
+ </div>
+ </div>
+ </template>
+ </NPopover>
+</template>
+
+<script setup lang="ts">
+import { NPopover } from "naive-ui";
+import { computed } from "vue";
+import UserAvatar from "@/components/User/UserAvatar.vue";
+import { extractUserEmail, useUserStore } from "@/store";
+import type {
+ TreeNodeForFunction,
+ TreeNodeForProcedure,
+ TreeNodeForTable,
+ TreeNodeForView,
+} from "./common";
+
+const props = defineProps<{
+ node:
+ | TreeNodeForTable
+ | TreeNodeForView
+ | TreeNodeForProcedure
+ | TreeNodeForFunction;
+}>();
+
+const config = computed(() => {
+ const { type, metadata } = props.node;
+ const schemaConfig = metadata.database.schemaConfigs.find(
+ (sc) => sc.name === metadata.schema.name
+ );
+ if (!schemaConfig) {
+ return undefined;
+ }
+ if (type === "table") {
+ return schemaConfig.tableConfigs.find(
+ (tc) => tc.name === metadata.table.name
+ );
+ }
+ if (type === "view") {
+ return schemaConfig.viewConfigs.find(
+ (vc) => vc.name === metadata.view.name
+ );
+ }
+ if (type === "procedure") {
+ return schemaConfig.procedureConfigs.find(
+ (pc) => pc.name === metadata.procedure.name
+ );
+ }
+ if (type === "function") {
+ return schemaConfig.functionConfigs.find(
+ (fc) => fc.name === metadata.function.name
+ );
+ }
+
+ return undefined;
+});
+
+const updater = computed(() => {
+ if (!config.value?.updater) return undefined;
+ const email = extractUserEmail(config.value.updater);
+ return useUserStore().getUserByEmail(email);
+});
+
+const updateTime = computed(() => {
+ return config.value?.updateTime;
+});
+</script>
diff --git a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
index 9adb77b7d0..c73bf88d8d 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
@@ -97,7 +97,16 @@ import { cloneDeep, debounce, escape, head } from "lodash-es";
import { MoreHorizontalIcon, CopyIcon } from "lucide-vue-next";
import type { TreeOption } from "naive-ui";
import { NInput, NDropdown, NTree, NPerformantEllipsis } from "naive-ui";
-import { computed, onMounted, watch, ref, h, reactive, nextTick } from "vue";
+import {
+ computed,
+ onMounted,
+ watch,
+ ref,
+ h,
+ reactive,
+ nextTick,
+ type VNode,
+} from "vue";
import { useI18n } from "vue-i18n";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import type { ComposedDatabase } from "@/types";
@@ -116,6 +125,7 @@ import TableNameModal from "../Modals/TableNameModal.vue";
import { useSchemaEditorContext } from "../context";
import { keyForResource, keyForResourceName } from "../context/common";
import { engineSupportsMultiSchema } from "../spec";
+import LastUpdate from "./LastUpdate.vue";
import NodePrefix from "./NodePrefix.vue";
import type {
TreeNode,
@@ -495,10 +505,27 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
// Render a 'menu' icon in the right of the node
const renderSuffix = ({ option }: { option: TreeOption }) => {
+ const node = option as TreeNode;
+ const icons: VNode[] = [];
+
+ const renderIcons = () => {
+ if (icons.length === 0) return null;
+ return h("div", { class: "inline-flex gap-1" }, icons);
+ };
+
+ if (
+ node.type === "table" ||
+ node.type === "view" ||
+ node.type === "procedure" ||
+ node.type === "function"
+ ) {
+ icons.push(h(LastUpdate, { node }));
+ }
+
if (readonly.value) {
- return null;
+ return renderIcons();
}
- const node = option as TreeNode;
+
const menuIcon = h(MoreHorizontalIcon, {
class: "w-4 h-auto text-gray-600",
onClick: (e) => {
@@ -508,19 +535,18 @@ const renderSuffix = ({ option }: { option: TreeOption }) => {
if (node.type === "database") {
const { engine } = node.db.instanceEntity;
if (engineSupportsMultiSchema(engine)) {
- return menuIcon;
+ icons.push(menuIcon);
}
}
if (node.type === "schema") {
- return menuIcon;
+ icons.push(menuIcon);
}
if (node.type === "group") {
- return menuIcon;
+ icons.push(menuIcon);
}
if (node.type === "table") {
- const icons = [menuIcon];
const duplicateIcon = h(CopyIcon, {
- class: "w-4 h-auto mr-2 text-gray-600",
+ class: "w-4 h-auto text-gray-600",
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
@@ -529,17 +555,17 @@ const renderSuffix = ({ option }: { option: TreeOption }) => {
handleDuplicateTable(node);
},
});
- icons.unshift(duplicateIcon);
- return icons;
+ icons.push(duplicateIcon);
+ icons.push(menuIcon);
}
if (node.type === "procedure") {
- return menuIcon;
+ icons.push(menuIcon);
}
if (node.type === "function") {
- return menuIcon;
+ icons.push(menuIcon);
}
- return null;
+ return renderIcons();
};
const handleDuplicateTable = (treeNode: TreeNodeForTable) => {
diff --git a/frontend/src/components/SchemaEditorLite/Panels/CommonCodeEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/CommonCodeEditor.vue
index ee6950df9a..5df538ec4b 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/CommonCodeEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/CommonCodeEditor.vue
@@ -24,6 +24,7 @@
</NButton>
<NButton
size="small"
+ type="primary"
:disabled="props.code === state.code"
@click="confirmEdit"
>
diff --git a/frontend/src/components/SchemaEditorLite/Panels/FunctionEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/FunctionEditor.vue
index a1524c2d45..5ebbe6a077 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/FunctionEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/FunctionEditor.vue
@@ -5,16 +5,7 @@
:readonly="disallowChangeFunction"
:status="status"
@update:code="handleUpdateDefinition"
- >
- <template v-if="showLastUpdater && functionConfig" #header-suffix>
- <div class="flex justify-end items-center h-[28px]">
- <LastUpdater
- :updater="functionConfig.updater"
- :update-time="functionConfig.updateTime"
- />
- </div>
- </template>
- </CommonCodeEditor>
+ />
</template>
<script setup lang="ts">
@@ -36,13 +27,8 @@ const props = defineProps<{
func: FunctionMetadata;
}>();
-const {
- readonly,
- showLastUpdater,
- markEditStatus,
- getSchemaStatus,
- getFunctionStatus,
-} = useSchemaEditorContext();
+const { readonly, markEditStatus, getSchemaStatus, getFunctionStatus } =
+ useSchemaEditorContext();
const statusForSchema = () => {
return getSchemaStatus(props.db, {
@@ -76,14 +62,6 @@ const disallowChangeFunction = computed(() => {
return statusForSchema() === "dropped" || status.value === "dropped";
});
-const functionConfig = computed(() => {
- const sc = props.database.schemaConfigs.find(
- (sc) => sc.name === props.schema.name
- );
- if (!sc) return undefined;
- return sc.functionConfigs.find((pc) => pc.name === props.func.name);
-});
-
const handleUpdateDefinition = (code: string) => {
// eslint-disable-next-line vue/no-mutating-props
props.func.definition = code;
diff --git a/frontend/src/components/SchemaEditorLite/Panels/ProcedureEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/ProcedureEditor.vue
index 0855502d24..982700dde6 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/ProcedureEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/ProcedureEditor.vue
@@ -5,16 +5,7 @@
:readonly="disallowChangeProcedure"
:status="status"
@update:code="handleUpdateDefinition"
- >
- <template v-if="showLastUpdater && procedureConfig" #header-suffix>
- <div class="flex justify-end items-center h-[28px]">
- <LastUpdater
- :updater="procedureConfig.updater"
- :update-time="procedureConfig.updateTime"
- />
- </div>
- </template>
- </CommonCodeEditor>
+ />
</template>
<script setup lang="ts">
@@ -28,7 +19,6 @@ import type {
import { useSchemaEditorContext } from "../context";
import type { EditStatus } from "../types";
import CommonCodeEditor from "./CommonCodeEditor.vue";
-import { LastUpdater } from "./common";
const props = defineProps<{
db: ComposedDatabase;
@@ -37,13 +27,8 @@ const props = defineProps<{
procedure: ProcedureMetadata;
}>();
-const {
- readonly,
- showLastUpdater,
- markEditStatus,
- getSchemaStatus,
- getProcedureStatus,
-} = useSchemaEditorContext();
+const { readonly, markEditStatus, getSchemaStatus, getProcedureStatus } =
+ useSchemaEditorContext();
const statusForSchema = () => {
return getSchemaStatus(props.db, {
@@ -77,14 +62,6 @@ const disallowChangeProcedure = computed(() => {
return statusForSchema() === "dropped" || status.value === "dropped";
});
-const procedureConfig = computed(() => {
- const sc = props.database.schemaConfigs.find(
- (sc) => sc.name === props.schema.name
- );
- if (!sc) return undefined;
- return sc.procedureConfigs.find((pc) => pc.name === props.procedure.name);
-});
-
const handleUpdateDefinition = (code: string) => {
// eslint-disable-next-line vue/no-mutating-props
props.procedure.definition = code;
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
index 6be9244e56..f09367162f 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
@@ -92,11 +92,6 @@
}"
/>
</div>
- <LastUpdater
- v-if="(showLastUpdater, tableConfig)"
- :updater="tableConfig.updater"
- :update-time="tableConfig.updateTime"
- />
</div>
</div>
@@ -251,7 +246,6 @@ const { t } = useI18n();
const {
project,
readonly,
- showLastUpdater,
events,
addTab,
markEditStatus,
@@ -346,14 +340,6 @@ const disableAlterColumn = (column: ColumnMetadata): boolean => {
);
};
-const tableConfig = computed(() => {
- const sc = props.database.schemaConfigs.find(
- (sc) => sc.name === props.schema.name
- );
- if (!sc) return undefined;
- return sc.tableConfigs.find((pc) => pc.name === props.table.name);
-});
-
const setColumnPrimaryKey = (column: ColumnMetadata, isPrimaryKey: boolean) => {
if (isPrimaryKey) {
column.nullable = false;
diff --git a/frontend/src/components/SchemaEditorLite/Panels/common/LastUpdater.vue b/frontend/src/components/SchemaEditorLite/Panels/common/LastUpdater.vue
deleted file mode 100644
index 739ac620a3..0000000000
--- a/frontend/src/components/SchemaEditorLite/Panels/common/LastUpdater.vue
+++ /dev/null
@@ -1,46 +0,0 @@
-<template>
- <NPopover>
- <template #trigger>
- <NButton size="tiny" text>
- <template #icon>
- <FileClockIcon class="w-4 h-4" />
- </template>
- </NButton>
- </template>
- <template #default>
- <div class="flex flex-col items-stretch gap-2 text-sm">
- <div class="flex justify-between gap-4">
- <div>
- {{ $t("branch.last-update.self") }}
- </div>
-
- <div class="flex justify-end gap-1">
- <UserAvatar :user="user" size="TINY" />
- {{ user?.title }}
- </div>
- </div>
- <div v-if="updateTime" class="flex justify-end gap-1 text-xs">
- {{ dayjs(updateTime).format("YYYY-MM-DD HH:mm:ss UTCZZ") }}
- </div>
- </div>
- </template>
- </NPopover>
-</template>
-
-<script setup lang="ts">
-import { FileClockIcon } from "lucide-vue-next";
-import { NButton, NPopover } from "naive-ui";
-import { computed } from "vue";
-import UserAvatar from "@/components/User/UserAvatar.vue";
-import { extractUserEmail, useUserStore } from "@/store";
-
-const props = defineProps<{
- updater: string; // Format: users/{email}
- updateTime: Date | undefined;
-}>();
-
-const user = computed(() => {
- const email = extractUserEmail(props.updater);
- return useUserStore().getUserByEmail(email);
-});
-</script>
diff --git a/frontend/src/components/SchemaEditorLite/Panels/common/index.ts b/frontend/src/components/SchemaEditorLite/Panels/common/index.ts
index a20425dadb..6b57160892 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/common/index.ts
+++ b/frontend/src/components/SchemaEditorLite/Panels/common/index.ts
@@ -1,4 +1 @@
-import LastUpdater from "./LastUpdater.vue";
-
export * from "./common";
-export { LastUpdater };