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: add function table (#5679)
boojacke5cdafbbd38f
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vueindex 0efdef7a55..d11d305f4f 100644--- a/frontend/src/components/DatabaseOverviewPanel.vue+++ b/frontend/src/components/DatabaseOverviewPanel.vue@@ -124,6 +124,17 @@</div><DBExtensionTable :db-extension-list="dbExtensionList" /></template>++ <template v-if="database.instance.engine === 'POSTGRES'">+ <div class="mt-6 text-lg leading-6 font-medium text-main mb-4">+ {{ $t("db.functions") }}+ </div>+ <FunctionTable+ :database="database"+ :schema-name="state.selectedSchemaName"+ :function-list="functionList"+ />+ </template></template></div>@@ -220,12 +231,8 @@</template><script lang="ts" setup>+import { cloneDeep, head, isEqual } from "lodash-es";import { computed, reactive, watchEffect, PropType } from "vue";-import AnomalyTable from "../components/AnomalyTable.vue";-import DataSourceTable from "../components/DataSourceTable.vue";-import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";-import TableTable from "../components/TableTable.vue";-import ViewTable from "../components/ViewTable.vue";import { hasWorkspacePermission, memberListInProject } from "../utils";import {Anomaly,@@ -234,8 +241,6 @@ import {DataSourcePatch,EngineType,} from "../types";-import { cloneDeep, head, isEqual } from "lodash-es";-import { BBTableSectionDataSource } from "../bbkit/types";import {featureToRef,useCurrentUser,@@ -243,6 +248,13 @@ import {useAnomalyList,useDBSchemaStore,} from "@/store";+import { BBTableSectionDataSource } from "../bbkit/types";+import AnomalyTable from "../components/AnomalyTable.vue";+import DataSourceTable from "../components/DataSourceTable.vue";+import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";+import TableTable from "../components/TableTable.vue";+import ViewTable from "../components/ViewTable.vue";+import FunctionTable from "../components/FunctionTable.vue";interface LocalState {selectedSchemaName: string;@@ -343,6 +355,17 @@ const dbExtensionList = computed(() => {return dbSchemaStore.getExtensionListByDatabaseId(props.database.id);});+const functionList = computed(() => {+ if (hasSchemaProperty.value) {+ return (+ schemaList.value.find(+ (schema) => schema.name === state.selectedSchemaName+ )?.functions || []+ );+ }+ return dbSchemaStore.getFunctionListByDatabaseId(props.database.id);+});+const allowConfigInstance = computed(() => {return hasWorkspacePermission("bb.permission.workspace.manage-instance",diff --git a/frontend/src/components/FunctionDefinitionView.vue b/frontend/src/components/FunctionDefinitionView.vuenew file mode 100644index 0000000000..b6988e477a--- /dev/null+++ b/frontend/src/components/FunctionDefinitionView.vue@@ -0,0 +1,65 @@+<template>+ <div class="relative w-full">+ <div ref="containerRef" class="w-full overflow-hidden text-ellipsis">+ <div class="w-full h-auto leading-5 whitespace-pre-wrap font-mono">+ <template v-if="state.expanded">+ {{ formatedDefinition }}+ </template>+ <NEllipsis+ v-else+ expand-trigger="click"+ :line-clamp="3"+ :tooltip="false"+ >+ {{ formatedDefinition }}+ </NEllipsis>+ </div>+ </div>+ <button+ v-if="state.showExpandButton"+ class="inline-block cursor-pointer border px-1 rounded text-xs text-green-600 border-green-600 bg-green-50 hover:opacity-80"+ @click="state.expanded = !state.expanded"+ >+ {{ $t("common." + (state.expanded ? "collapse" : "expand")) }}+ </button>+ </div>+</template>++<script lang="ts" setup>+import { NEllipsis } from "naive-ui";+import { computed, ref, reactive, onMounted } from "vue";++const MAX_HEIGHT = 60;++interface LocalState {+ showExpandButton: boolean;+ expanded: boolean;+}++const props = defineProps({+ definition: {+ type: String,+ default: "",+ },+});++const state = reactive<LocalState>({+ showExpandButton: false,+ expanded: true,+});+const containerRef = ref<HTMLDivElement | null>(null);++const formatedDefinition = computed(() => {+ return props.definition.trim();+});++onMounted(() => {+ if (containerRef.value) {+ const height = containerRef.value.clientHeight;+ if (height > MAX_HEIGHT) {+ state.showExpandButton = true;+ state.expanded = false;+ }+ }+});+</script>diff --git a/frontend/src/components/FunctionTable.vue b/frontend/src/components/FunctionTable.vuenew file mode 100644index 0000000000..2c42e997dd--- /dev/null+++ b/frontend/src/components/FunctionTable.vue@@ -0,0 +1,86 @@+<template>+ <BBTable+ :column-list="columnList"+ :data-source="functionList"+ :show-header="true"+ :left-bordered="true"+ :right-bordered="true"+ :row-clickable="true"+ :custom-footer="true"+ >+ <template #body="{ rowData: functionItem }">+ <BBTableCell v-if="hasSchemaProperty" :left-padding="4" class="w-[10%]">+ {{ schemaName }}+ </BBTableCell>+ <BBTableCell :left-padding="hasSchemaProperty ? 2 : 4">+ <div class="flex items-center space-x-2">+ <EllipsisText>{{ functionItem.name }}</EllipsisText>+ </div>+ </BBTableCell>+ <BBTableCell>+ <FunctionDefinitionView :definition="functionItem.definition" />+ </BBTableCell>+ </template>+ </BBTable>+</template>++<script lang="ts" setup>+import { computed, PropType } from "vue";+import { useI18n } from "vue-i18n";+import { Database } from "@/types";+import { FunctionMetadata } from "@/types/proto/store/database";+import EllipsisText from "@/components/EllipsisText.vue";+import FunctionDefinitionView from "@/components/FunctionDefinitionView.vue";++const props = defineProps({+ database: {+ required: true,+ type: Object as PropType<Database>,+ },+ schemaName: {+ type: String,+ default: "",+ },+ functionList: {+ required: true,+ type: Object as PropType<FunctionMetadata[]>,+ },+});++console.log(props.functionList);++const { t } = useI18n();++const isPostgres = props.database.instance.engine === "POSTGRES";++const hasSchemaProperty =+ isPostgres ||+ props.database.instance.engine === "SNOWFLAKE" ||+ props.database.instance.engine === "ORACLE" ||+ props.database.instance.engine === "MSSQL";++const columnList = computed(() => {+ if (hasSchemaProperty) {+ return [+ {+ title: t("common.schema"),+ },+ {+ title: t("common.name"),+ },+ {+ title: t("common.definition"),+ },+ ];+ } else {+ return [+ {+ title: t("common.name"),+ },+ {+ title: t("common.definition"),+ },+ ];+ }+});+</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex bd3eb94136..acadf866bc 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -238,7 +238,9 @@"active": "Active","added": "Added","revoke": "Revoke",- "cannot-undo-this-action": "You cannot undo this action"+ "cannot-undo-this-action": "You cannot undo this action",+ "expand": "Expand",+ "collapse": "Collapse"},"error-page": {"go-back-home": "Go back home"@@ -789,6 +791,7 @@"collections": "Collections","views": "Views","extensions": "Extensions",+ "functions": "Functions","parent": "Parent","last-successful-sync": "Last successful sync","sync-status": "Sync status",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex f5d4add269..86f98efa90 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -236,7 +236,9 @@"active": "开启","added": "已创建","revoke": "撤销",- "cannot-undo-this-action": "这个操作无法撤销"+ "cannot-undo-this-action": "这个操作无法撤销",+ "expand": "展开",+ "collapse": "收起"},"error-page": {"go-back-home": "回到主页"@@ -787,6 +789,7 @@"collections": "集合","views": "视图","extensions": "插件",+ "functions": "函数","parent": "母","last-successful-sync": "上次成功同步于","sync-status": "同步状态",diff --git a/frontend/src/store/modules/dbSchema.ts b/frontend/src/store/modules/dbSchema.tsindex 9f076c0454..2c7f0e4d60 100644--- a/frontend/src/store/modules/dbSchema.ts+++ b/frontend/src/store/modules/dbSchema.ts@@ -8,6 +8,7 @@ import {SchemaMetadata,TableMetadata,ViewMetadata,+ FunctionMetadata,} from "@/types/proto/store/database";export const useDBSchemaStore = defineStore("dbSchema", {@@ -139,6 +140,26 @@ export const useDBSchemaStore = defineStore("dbSchema", {return databaseMetadata.extensions;},+ async getOrFetchFunctionListByDatabaseId(+ databaseId: DatabaseId+ ): Promise<FunctionMetadata[]> {+ if (!this.databaseMetadataById.has(databaseId)) {+ await this.getOrFetchDatabaseMetadataById(databaseId);+ }+ return this.getFunctionListByDatabaseId(databaseId);+ },+ getFunctionListByDatabaseId(databaseId: DatabaseId): FunctionMetadata[] {+ const databaseMetadata = this.databaseMetadataById.get(databaseId);+ if (!databaseMetadata) {+ return [];+ }++ const functionList: FunctionMetadata[] = [];+ for (const schema of databaseMetadata.schemas) {+ functionList.push(...schema.functions);+ }+ return functionList;+ },removeCacheByDatabaseId(databaseId: DatabaseId) {this.requestCache.delete(databaseId);this.databaseMetadataById.delete(databaseId);