Skip to content

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

chore: support column labels (#8628)

ecmadao5e7d81975796
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index e18e21d8f6..406845f95f 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -2023,6 +2023,7 @@ func convertDatabaseConfig(config *storepb.DatabaseConfig) []*v1pb.SchemaConfig
t.ColumnConfigs = append(t.ColumnConfigs, &v1pb.ColumnConfig{
Name: column.Name,
SemanticTypeId: column.SemanticTypeId,
+ Labels: column.Labels,
})
}
s.TableConfigs = append(s.TableConfigs, t)
@@ -2048,6 +2049,7 @@ func convertV1DatabaseConfig(databaseName string, schemaConfig []*v1pb.SchemaCon
t.ColumnConfigs = append(t.ColumnConfigs, &storepb.ColumnConfig{
Name: column.Name,
SemanticTypeId: column.SemanticTypeId,
+ Labels: column.Labels,
})
}
s.TableConfigs = append(s.TableConfigs, t)
diff --git a/frontend/src/components/ColumnTable.vue b/frontend/src/components/ColumnTable.vue
index 1ecc2b2fb7..4fbe7fb894 100644
--- a/frontend/src/components/ColumnTable.vue
+++ b/frontend/src/components/ColumnTable.vue
@@ -44,7 +44,7 @@
</i18n-t>
</NTooltip>
<button
- v-if="allowAdmin"
+ v-if="hasSensitiveDataPermission"
class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
@click.prevent="openSensitiveDrawer(column)"
>
@@ -56,16 +56,18 @@
<div class="flex items-center">
{{ getColumnSemanticType(column.name)?.title }}
<button
- v-if="allowAdmin && getColumnSemanticType(column.name)"
+ v-if="
+ hasSensitiveDataPermission && getColumnSemanticType(column.name)
+ "
class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
@click.prevent="onSemanticTypeRemove(column.name)"
>
<heroicons-outline:x class="w-4 h-4" />
</button>
<button
- v-if="allowAdmin"
+ v-if="hasSensitiveDataPermission"
class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
- @click.prevent="state.pendingUpdateColumn = column.name"
+ @click.prevent="openSemanticTypeDrawer(column)"
>
<heroicons-outline:pencil class="w-4 h-4" />
</button>
@@ -107,6 +109,21 @@
<BBTableCell class="bb-grid-cell">
{{ column.userComment }}
</BBTableCell>
+ <BBTableCell class="bb-grid-cell">
+ <div class="flex items-center space-x-1">
+ <LabelsColumn
+ :labels="getColumnConfig(column.name).labels"
+ :show-count="2"
+ />
+ <button
+ v-if="hasEditLabelsPermission"
+ class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
+ @click.prevent="openLabelsDrawer(column)"
+ >
+ <heroicons-outline:pencil class="w-4 h-4" />
+ </button>
+ </div>
+ </BBTableCell>
</template>
</BBTable>
@@ -118,20 +135,32 @@
/>
<SensitiveColumnDrawer
- :show="!!state.activeColumn"
+ v-if="state.activeColumn"
+ :show="state.showSensitiveDataDrawer"
:column="{
maskData: getColumnMasking(state.activeColumn ?? {} as ColumnMetadata),
database: props.database,
}"
- @dismiss="state.activeColumn = undefined"
+ @dismiss="state.showSensitiveDataDrawer = false"
/>
<SemanticTypesDrawer
- :show="!!state.pendingUpdateColumn"
+ v-if="state.activeColumn"
+ :show="state.showSemanticTypesDrawer"
:semantic-type-list="semanticTypeList"
- @dismiss="state.pendingUpdateColumn = undefined"
+ @dismiss="state.showSemanticTypesDrawer = false"
@apply="onSemanticTypeApply($event)"
/>
+
+ <LabelEditorDrawer
+ v-if="state.activeColumn"
+ :show="state.showLabelsDrawer"
+ :readonly="!hasEditLabelsPermission"
+ :database="database"
+ :labels="getColumnConfig(state.activeColumn.name).labels"
+ @dismiss="state.showLabelsDrawer = false"
+ @apply="onLabelsApply($event)"
+ />
</template>
<script lang="ts" setup>
@@ -157,15 +186,22 @@ import {
TableMetadata,
TableConfig,
SchemaConfig,
+ ColumnConfig,
} from "@/types/proto/v1/database_service";
import { MaskData } from "@/types/proto/v1/org_policy_service";
import { DataClassificationSetting_DataClassificationConfig } from "@/types/proto/v1/setting_service";
-import { hasWorkspacePermissionV1, isDev } from "@/utils";
+import {
+ hasWorkspacePermissionV1,
+ hasPermissionInProjectV1,
+ isDev,
+} from "@/utils";
type LocalState = {
showFeatureModal: boolean;
activeColumn?: ColumnMetadata;
- pendingUpdateColumn?: string;
+ showSensitiveDataDrawer: boolean;
+ showSemanticTypesDrawer: boolean;
+ showLabelsDrawer: boolean;
};
const props = defineProps({
@@ -201,6 +237,9 @@ const props = defineProps({
const { t } = useI18n();
const state = reactive<LocalState>({
showFeatureModal: false,
+ showSensitiveDataDrawer: false,
+ showSemanticTypesDrawer: false,
+ showLabelsDrawer: false,
});
const engine = computed(() => {
return props.database.instanceEntity.engine;
@@ -255,14 +294,16 @@ const tableConfig = computed(() => {
});
const getColumnConfig = (columnName: string) => {
- return tableConfig.value.columnConfigs.find(
- (config) => config.name === columnName
+ return (
+ tableConfig.value.columnConfigs.find(
+ (config) => config.name === columnName
+ ) ?? ColumnConfig.fromPartial({})
);
};
const getColumnSemanticType = (columnName: string) => {
const config = getColumnConfig(columnName);
- if (!config || !config.semanticTypeId) {
+ if (!config.semanticTypeId) {
return;
}
return semanticTypeList.value.find(
@@ -270,43 +311,54 @@ const getColumnSemanticType = (columnName: string) => {
);
};
+const onLabelsApply = async (labels: { [key: string]: string }) => {
+ const column = state.activeColumn;
+ if (!column) {
+ return;
+ }
+ try {
+ await updateColumnConfig(column.name, { labels });
+ } finally {
+ state.showLabelsDrawer = false;
+ }
+};
+
const onSemanticTypeApply = async (semanticTypeId: string) => {
- const column = state.pendingUpdateColumn;
+ const column = state.activeColumn;
if (!column) {
return;
}
try {
- await updateSemanticType(column, semanticTypeId);
+ await updateColumnConfig(column.name, { semanticTypeId });
} finally {
- state.pendingUpdateColumn = undefined;
+ state.showSemanticTypesDrawer = false;
}
};
const onSemanticTypeRemove = async (column: string) => {
- await updateSemanticType(column, "");
+ await updateColumnConfig(column, { semanticTypeId: "" });
};
-const updateSemanticType = async (column: string, semanticTypeId: string) => {
+const updateColumnConfig = async (
+ column: string,
+ config: Partial<ColumnConfig>
+) => {
const index = tableConfig.value.columnConfigs.findIndex(
(config) => config.name === column
);
- if (index < 0 && !semanticTypeId) {
- return;
- }
const pendingUpdateTableConfig = cloneDeep(tableConfig.value);
if (index < 0) {
- if (!semanticTypeId) {
- return;
- }
- pendingUpdateTableConfig.columnConfigs.push({
- name: column,
- semanticTypeId,
- });
+ pendingUpdateTableConfig.columnConfigs.push(
+ ColumnConfig.fromPartial({
+ name: column,
+ ...config,
+ })
+ );
} else {
pendingUpdateTableConfig.columnConfigs[index] = {
- name: column,
- semanticTypeId,
+ ...pendingUpdateTableConfig.columnConfigs[index],
+ ...config,
};
}
@@ -364,7 +416,7 @@ const showClassificationColumn = computed(() => {
});
const currentUserV1 = useCurrentUserV1();
-const allowAdmin = computed(() => {
+const hasSensitiveDataPermission = computed(() => {
if (
hasWorkspacePermissionV1(
"bb.permission.workspace.manage-sensitive-data",
@@ -380,6 +432,21 @@ const allowAdmin = computed(() => {
return false;
});
+const hasEditLabelsPermission = computed(() => {
+ const project = props.database.projectEntity;
+ return (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-label",
+ currentUserV1.value.userRole
+ ) ||
+ hasPermissionInProjectV1(
+ project.iamPolicy,
+ currentUserV1.value,
+ "bb.permission.project.manage-general"
+ )
+ );
+});
+
const NORMAL_COLUMN_LIST = computed(() => {
const columnList: BBTableColumn[] = [
{
@@ -403,6 +470,9 @@ const NORMAL_COLUMN_LIST = computed(() => {
{
title: t("database.comment"),
},
+ {
+ title: t("common.labels"),
+ },
];
if (showSensitiveColumn.value) {
if (isDev()) {
@@ -441,6 +511,9 @@ const POSTGRES_COLUMN_LIST = computed(() => {
{
title: t("database.comment"),
},
+ {
+ title: t("common.labels"),
+ },
];
if (showSensitiveColumn.value) {
if (isDev()) {
@@ -475,6 +548,9 @@ const CLICKHOUSE_SNOWFLAKE_COLUMN_LIST = computed((): BBTableColumn[] => [
{
title: t("database.comment"),
},
+ {
+ title: t("common.labels"),
+ },
]);
const columnNameList = computed(() => {
@@ -519,6 +595,22 @@ const openSensitiveDrawer = (column: ColumnMetadata) => {
return;
}
+ state.showSensitiveDataDrawer = true;
+ state.activeColumn = column;
+};
+
+const openSemanticTypeDrawer = (column: ColumnMetadata) => {
+ if (!hasSensitiveDataFeature.value || instanceMissingLicense.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ state.showSemanticTypesDrawer = true;
+ state.activeColumn = column;
+};
+
+const openLabelsDrawer = (column: ColumnMetadata) => {
+ state.showLabelsDrawer = true;
state.activeColumn = column;
};
diff --git a/frontend/src/components/LabelEditorDrawer.vue b/frontend/src/components/LabelEditorDrawer.vue
new file mode 100644
index 0000000000..af8e673283
--- /dev/null
+++ b/frontend/src/components/LabelEditorDrawer.vue
@@ -0,0 +1,104 @@
+<template>
+ <Drawer :show="show" @close="$emit('dismiss')">
+ <DrawerContent :title="$t('common.labels')">
+ <LabelListEditor
+ ref="labelListEditorRef"
+ v-model:kv-list="state.kvList"
+ :readonly="readonly"
+ :show-errors="dirty"
+ class="max-w-[30rem]"
+ />
+ <template #footer>
+ <div class="w-full flex justify-between items-center">
+ <div class="w-full flex justify-end items-center gap-x-3">
+ <NButton @click.prevent="$emit('dismiss')">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton
+ v-if="!readonly"
+ :disabled="!allowSave"
+ type="primary"
+ @click="$emit('apply', convertKVListToLabels(state.kvList))"
+ >
+ {{ $t("common.save") }}
+ </NButton>
+ </div>
+ </div>
+ </template>
+ </DrawerContent>
+ </Drawer>
+</template>
+
+<script lang="ts" setup>
+import { cloneDeep, isEqual } from "lodash-es";
+import { computed, reactive, watch, ref } from "vue";
+import LabelListEditor from "@/components/Label/LabelListEditor.vue";
+import { Drawer, DrawerContent } from "@/components/v2";
+import { type ComposedDatabase } from "@/types";
+import {
+ PRESET_LABEL_KEYS,
+ convertKVListToLabels,
+ convertLabelsToKVList,
+} from "@/utils";
+
+const props = defineProps<{
+ show: boolean;
+ readonly: boolean;
+ database: ComposedDatabase;
+ labels: {
+ [key: string]: string;
+ };
+}>();
+defineEmits<{
+ (event: "dismiss"): void;
+ (
+ event: "apply",
+ labels: {
+ [key: string]: string;
+ }
+ ): void;
+}>();
+
+type LocalState = {
+ kvList: { key: string; value: string }[];
+};
+
+const state = reactive<LocalState>({
+ kvList: [],
+});
+const labelListEditorRef = ref<InstanceType<typeof LabelListEditor>>();
+
+const convert = () => {
+ const labels = cloneDeep(props.labels);
+ // Pre-fill preset label keys with empty values
+ for (const key of PRESET_LABEL_KEYS) {
+ if (!(key in labels)) {
+ labels[key] = "";
+ }
+ }
+ return convertLabelsToKVList(labels, true /* sort */);
+};
+
+const dirty = computed(() => {
+ const original = convert();
+ const local = state.kvList;
+ return !isEqual(original, local);
+});
+
+const allowSave = computed(() => {
+ if (!dirty.value) return false;
+ const errors = labelListEditorRef.value?.flattenErrors ?? [];
+ return errors.length === 0;
+});
+
+watch(
+ () => props.labels,
+ () => {
+ state.kvList = convert();
+ },
+ {
+ immediate: true,
+ deep: true,
+ }
+);
+</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue
index 71569b483a..c398c03c5b 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue
@@ -44,25 +44,7 @@
/>
</div>
<div v-if="showLabelsColumn" class="bb-grid-cell">
- <NTooltip :disabled="Object.keys(database.labels).length <= 1">
- <template #trigger>
- <div class="flex items-center space-x-1">
- <div
- v-for="[key, label] in Object.entries(database.labels).slice(0, 1)"
- :key="key"
- class="rounded-lg bg-gray-100 py-1 px-2 text-sm"
- >
- {{ `${key}:${label}` }}
- </div>
- <span v-if="Object.keys(database.labels).length > 1">...</span>
- </div>
- </template>
- <div class="text-sm flex flex-col space-y-1">
- <div v-for="[key, label] in Object.entries(database.labels)" :key="key">
- {{ `${key}:${label}` }}
- </div>
- </div>
- </NTooltip>
+ <LabelsColumn :labels="database.labels" :show-count="1" placeholder="-" />
</div>
</template>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/LabelsColumn.vue b/frontend/src/components/v2/Model/DatabaseV1Table/LabelsColumn.vue
new file mode 100644
index 0000000000..3d0f4ab378
--- /dev/null
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/LabelsColumn.vue
@@ -0,0 +1,45 @@
+<template>
+ <NTooltip :disabled="Object.keys(labels).length <= minimumShowCount">
+ <template #trigger>
+ <div
+ v-if="Object.entries(labels).length > 0"
+ class="flex items-center space-x-1"
+ >
+ <div
+ v-for="[key, label] in Object.entries(labels).slice(
+ 0,
+ minimumShowCount
+ )"
+ :key="key"
+ class="rounded-lg bg-gray-100 py-1 px-2 text-sm"
+ >
+ {{ `${key}:${label}` }}
+ </div>
+ <span v-if="Object.keys(labels).length > minimumShowCount">...</span>
+ </div>
+ <div v-else>{{ placeholder }}</div>
+ </template>
+ <div class="text-sm flex flex-col space-y-1">
+ <div v-for="[key, label] in Object.entries(labels)" :key="key">
+ {{ `${key}:${label}` }}
+ </div>
+ </div>
+ </NTooltip>
+</template>
+
+<script setup lang="ts">
+const props = withDefaults(
+ defineProps<{
+ labels: {
+ [key: string]: string;
+ };
+ showCount: number;
+ placeholder?: string;
+ }>(),
+ {
+ placeholder: "",
+ }
+);
+
+const minimumShowCount = Math.max(1, props.showCount);
+</script>