Skip to content

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

chore: use `NDataTable` for column list (#9453)

boojack11b906541289
diff --git a/frontend/src/components/ColumnDataTable/LabelsCell.vue b/frontend/src/components/ColumnDataTable/LabelsCell.vue
new file mode 100644
index 0000000000..069fd13d07
--- /dev/null
+++ b/frontend/src/components/ColumnDataTable/LabelsCell.vue
@@ -0,0 +1,155 @@
+<template>
+ <div class="flex items-center space-x-1">
+ <LabelsColumn :labels="labels" :show-count="2" />
+ <button
+ v-if="!readonly"
+ class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
+ @click.prevent="openLabelsDrawer()"
+ >
+ <heroicons-outline:pencil class="w-4 h-4" />
+ </button>
+ </div>
+
+ <LabelEditorDrawer
+ v-if="state.showLabelsDrawer"
+ :show="true"
+ :readonly="!!readonly"
+ :title="$t('db.labels-for-resource', { resource: `'${column.name}'` })"
+ :labels="[labels]"
+ @dismiss="state.showLabelsDrawer = false"
+ @apply="onLabelsApply($event)"
+ />
+</template>
+
+<script lang="ts" setup>
+import { cloneDeep } from "lodash-es";
+import { computed } from "vue";
+import { reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { pushNotification, useDBSchemaV1Store } from "@/store";
+import { ComposedDatabase } from "@/types";
+import {
+ ColumnConfig,
+ ColumnMetadata,
+ SchemaConfig,
+ TableConfig,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
+
+type LocalState = {
+ showLabelsDrawer: boolean;
+};
+
+const props = defineProps<{
+ database: ComposedDatabase;
+ schema: string;
+ table: TableMetadata;
+ column: ColumnMetadata;
+ readonly?: boolean;
+}>();
+
+const { t } = useI18n();
+const dbSchemaV1Store = useDBSchemaV1Store();
+const state = reactive<LocalState>({
+ showLabelsDrawer: false,
+});
+
+const databaseMetadata = computed(() => {
+ return dbSchemaV1Store.getDatabaseMetadata(props.database.name);
+});
+
+const schemaConfig = computed(() => {
+ return (
+ databaseMetadata.value.schemaConfigs.find(
+ (config) => config.name === props.schema
+ ) ??
+ SchemaConfig.fromPartial({
+ name: props.schema,
+ tableConfigs: [],
+ })
+ );
+});
+
+const tableConfig = computed(() => {
+ return (
+ schemaConfig.value.tableConfigs.find(
+ (config) => config.name === props.table.name
+ ) ??
+ TableConfig.fromPartial({
+ name: props.table.name,
+ columnConfigs: [],
+ })
+ );
+});
+
+const labels = computed(() => {
+ return (
+ tableConfig.value.columnConfigs.find(
+ (config) => config.name === props.column.name
+ ) ?? ColumnConfig.fromPartial({})
+ ).labels;
+});
+
+const openLabelsDrawer = () => {
+ state.showLabelsDrawer = true;
+};
+
+const onLabelsApply = async (labelsList: { [key: string]: string }[]) => {
+ await updateColumnConfig(props.column.name, { labels: labelsList[0] });
+};
+
+const updateColumnConfig = async (
+ column: string,
+ config: Partial<ColumnConfig>
+) => {
+ const index = tableConfig.value.columnConfigs.findIndex(
+ (config) => config.name === column
+ );
+
+ const pendingUpdateTableConfig = cloneDeep(tableConfig.value);
+ if (index < 0) {
+ pendingUpdateTableConfig.columnConfigs.push(
+ ColumnConfig.fromPartial({
+ name: column,
+ ...config,
+ })
+ );
+ } else {
+ pendingUpdateTableConfig.columnConfigs[index] = {
+ ...pendingUpdateTableConfig.columnConfigs[index],
+ ...config,
+ };
+ }
+
+ const pendingUpdateSchemaConfig = cloneDeep(schemaConfig.value);
+ const tableIndex = pendingUpdateSchemaConfig.tableConfigs.findIndex(
+ (config) => config.name === pendingUpdateTableConfig.name
+ );
+ if (tableIndex < 0) {
+ pendingUpdateSchemaConfig.tableConfigs.push(pendingUpdateTableConfig);
+ } else {
+ pendingUpdateSchemaConfig.tableConfigs[tableIndex] =
+ pendingUpdateTableConfig;
+ }
+
+ const pendingUpdateDatabaseConfig = cloneDeep(databaseMetadata.value);
+ const schemaIndex = pendingUpdateDatabaseConfig.schemaConfigs.findIndex(
+ (config) => config.name === pendingUpdateSchemaConfig.name
+ );
+ if (schemaIndex < 0) {
+ pendingUpdateDatabaseConfig.schemaConfigs.push(pendingUpdateSchemaConfig);
+ } else {
+ pendingUpdateDatabaseConfig.schemaConfigs[schemaIndex] =
+ pendingUpdateSchemaConfig;
+ }
+
+ await dbSchemaV1Store.updateDatabaseSchemaConfigs(
+ pendingUpdateDatabaseConfig
+ );
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+};
+</script>
diff --git a/frontend/src/components/ColumnDataTable/MaskingLevelCell.vue b/frontend/src/components/ColumnDataTable/MaskingLevelCell.vue
new file mode 100644
index 0000000000..a27f7164a4
--- /dev/null
+++ b/frontend/src/components/ColumnDataTable/MaskingLevelCell.vue
@@ -0,0 +1,146 @@
+<template>
+ <div class="flex items-center">
+ <span class="mr-2">
+ <template v-if="isColumnConfigMasking">
+ {{ maskingLevelText }}
+ </template>
+ <template v-else
+ >({{
+ $t(
+ `settings.sensitive-data.masking-level.${maskingLevelToJSON(
+ column.effectiveMaskingLevel
+ ).toLowerCase()}`
+ )
+ }})</template
+ >
+ </span>
+ <NTooltip v-if="!isColumnConfigMasking">
+ <template #trigger>
+ <heroicons-outline:question-mark-circle class="shrink-0 h-4 w-4 mr-2" />
+ </template>
+ <i18n-t
+ tag="div"
+ keypath="settings.sensitive-data.column-detail.column-effective-masking-tips"
+ class="whitespace-pre-line"
+ >
+ <template #link>
+ <router-link
+ class="flex items-center light-link text-sm"
+ to="/setting/sensitive-data#global-masking-rule"
+ >
+ {{ $t("settings.sensitive-data.global-rules.check-rules") }}
+ </router-link>
+ </template>
+ </i18n-t>
+ </NTooltip>
+ <button
+ v-if="!readonly"
+ class="shrink-0 w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
+ @click.prevent="openSensitiveDrawer()"
+ >
+ <heroicons-outline:pencil class="w-4 h-4" />
+ </button>
+ </div>
+
+ <FeatureModal
+ feature="bb.feature.sensitive-data"
+ :instance="database.instanceEntity"
+ :open="state.showFeatureModal"
+ @cancel="state.showFeatureModal = false"
+ />
+
+ <SensitiveColumnDrawer
+ v-if="state.showSensitiveDataDrawer"
+ :show="true"
+ :column="{
+ maskData: columnMasking,
+ database: props.database,
+ }"
+ @dismiss="state.showSensitiveDataDrawer = false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { useSubscriptionV1Store } from "@/store";
+import { ComposedDatabase } from "@/types";
+import { MaskingLevel, maskingLevelToJSON } from "@/types/proto/v1/common";
+import {
+ ColumnMetadata,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
+import { MaskData } from "@/types/proto/v1/org_policy_service";
+
+type LocalState = {
+ showFeatureModal: boolean;
+ showSensitiveDataDrawer: boolean;
+};
+
+const props = defineProps<{
+ database: ComposedDatabase;
+ schema: string;
+ table: TableMetadata;
+ column: ColumnMetadata;
+ maskDataList: MaskData[];
+ readonly?: boolean;
+}>();
+
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ showFeatureModal: false,
+ showSensitiveDataDrawer: false,
+});
+const subscriptionV1Store = useSubscriptionV1Store();
+
+const hasSensitiveDataFeature = computed(() => {
+ return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
+});
+
+const instanceMissingLicense = computed(() => {
+ return subscriptionV1Store.instanceMissingLicense(
+ "bb.feature.sensitive-data",
+ props.database.instanceEntity
+ );
+});
+
+const maskingLevelText = computed(() => {
+ const level = maskingLevelToJSON(columnMasking.value.maskingLevel);
+ return t(`settings.sensitive-data.masking-level.${level.toLowerCase()}`);
+});
+
+const columnMasking = computed(() => {
+ return (
+ props.maskDataList.find((sensitiveData) => {
+ return (
+ sensitiveData.table === props.table.name &&
+ sensitiveData.column === props.column.name &&
+ sensitiveData.schema === props.schema
+ );
+ }) ?? {
+ schema: props.schema,
+ table: props.table.name,
+ column: props.column.name,
+ maskingLevel: MaskingLevel.MASKING_LEVEL_UNSPECIFIED,
+ fullMaskingAlgorithmId: "",
+ partialMaskingAlgorithmId: "",
+ }
+ );
+});
+
+const isColumnConfigMasking = computed(() => {
+ return (
+ columnMasking.value.maskingLevel !== MaskingLevel.MASKING_LEVEL_UNSPECIFIED
+ );
+});
+
+const openSensitiveDrawer = () => {
+ if (!hasSensitiveDataFeature.value || instanceMissingLicense.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ state.showSensitiveDataDrawer = true;
+};
+</script>
diff --git a/frontend/src/components/ColumnDataTable/SemanticTypeCell.vue b/frontend/src/components/ColumnDataTable/SemanticTypeCell.vue
new file mode 100644
index 0000000000..1b1f660c9e
--- /dev/null
+++ b/frontend/src/components/ColumnDataTable/SemanticTypeCell.vue
@@ -0,0 +1,213 @@
+<template>
+ <div class="flex items-center">
+ {{ columnSemanticType?.title }}
+ <button
+ v-if="!readonly && columnSemanticType"
+ class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
+ @click.prevent="onSemanticTypeRemove()"
+ >
+ <heroicons-outline:x class="w-4 h-4" />
+ </button>
+ <button
+ v-if="!readonly"
+ class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
+ @click.prevent="openSemanticTypeDrawer()"
+ >
+ <heroicons-outline:pencil class="w-4 h-4" />
+ </button>
+ </div>
+
+ <FeatureModal
+ feature="bb.feature.sensitive-data"
+ :instance="database.instanceEntity"
+ :open="state.showFeatureModal"
+ @cancel="state.showFeatureModal = false"
+ />
+
+ <SemanticTypesDrawer
+ v-if="state.showSemanticTypesDrawer"
+ :show="true"
+ :semantic-type-list="semanticTypeList"
+ @dismiss="state.showSemanticTypesDrawer = false"
+ @apply="onSemanticTypeApply($event)"
+ />
+</template>
+
+<script lang="ts" setup>
+import { cloneDeep } from "lodash-es";
+import { computed } from "vue";
+import { reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import {
+ pushNotification,
+ useDBSchemaV1Store,
+ useSettingV1Store,
+ useSubscriptionV1Store,
+} from "@/store";
+import { ComposedDatabase } from "@/types";
+import {
+ ColumnConfig,
+ ColumnMetadata,
+ SchemaConfig,
+ TableConfig,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
+
+type LocalState = {
+ showFeatureModal: boolean;
+ showSemanticTypesDrawer: boolean;
+};
+
+const props = defineProps<{
+ database: ComposedDatabase;
+ schema: string;
+ table: TableMetadata;
+ column: ColumnMetadata;
+ readonly?: boolean;
+}>();
+
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ showFeatureModal: false,
+ showSemanticTypesDrawer: false,
+});
+const subscriptionV1Store = useSubscriptionV1Store();
+const settingV1Store = useSettingV1Store();
+const dbSchemaV1Store = useDBSchemaV1Store();
+
+const hasSensitiveDataFeature = computed(() => {
+ return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
+});
+
+const instanceMissingLicense = computed(() => {
+ return subscriptionV1Store.instanceMissingLicense(
+ "bb.feature.sensitive-data",
+ props.database.instanceEntity
+ );
+});
+
+const semanticTypeList = computed(() => {
+ return (
+ settingV1Store.getSettingByName("bb.workspace.semantic-types")?.value
+ ?.semanticTypeSettingValue?.types ?? []
+ );
+});
+
+const databaseMetadata = computed(() => {
+ return dbSchemaV1Store.getDatabaseMetadata(props.database.name);
+});
+
+const schemaConfig = computed(() => {
+ return (
+ databaseMetadata.value.schemaConfigs.find(
+ (config) => config.name === props.schema
+ ) ??
+ SchemaConfig.fromPartial({
+ name: props.schema,
+ tableConfigs: [],
+ })
+ );
+});
+
+const tableConfig = computed(() => {
+ return (
+ schemaConfig.value.tableConfigs.find(
+ (config) => config.name === props.table.name
+ ) ??
+ TableConfig.fromPartial({
+ name: props.table.name,
+ columnConfigs: [],
+ })
+ );
+});
+
+const getColumnConfig = (columnName: string) => {
+ return (
+ tableConfig.value.columnConfigs.find(
+ (config) => config.name === columnName
+ ) ?? ColumnConfig.fromPartial({})
+ );
+};
+
+const columnSemanticType = computed(() => {
+ const config = getColumnConfig(props.column.name);
+ if (!config.semanticTypeId) {
+ return;
+ }
+ return semanticTypeList.value.find(
+ (data) => data.id === config.semanticTypeId
+ );
+});
+
+const openSemanticTypeDrawer = () => {
+ if (!hasSensitiveDataFeature.value || instanceMissingLicense.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ state.showSemanticTypesDrawer = true;
+};
+
+const onSemanticTypeApply = async (semanticTypeId: string) => {
+ await updateColumnConfig(props.column.name, { semanticTypeId });
+};
+
+const onSemanticTypeRemove = async () => {
+ await updateColumnConfig(props.column.name, { semanticTypeId: "" });
+};
+
+const updateColumnConfig = async (
+ column: string,
+ config: Partial<ColumnConfig>
+) => {
+ const index = tableConfig.value.columnConfigs.findIndex(
+ (config) => config.name === column
+ );
+
+ const pendingUpdateTableConfig = cloneDeep(tableConfig.value);
+ if (index < 0) {
+ pendingUpdateTableConfig.columnConfigs.push(
+ ColumnConfig.fromPartial({
+ name: column,
+ ...config,
+ })
+ );
+ } else {
+ pendingUpdateTableConfig.columnConfigs[index] = {
+ ...pendingUpdateTableConfig.columnConfigs[index],
+ ...config,
+ };
+ }
+
+ const pendingUpdateSchemaConfig = cloneDeep(schemaConfig.value);
+ const tableIndex = pendingUpdateSchemaConfig.tableConfigs.findIndex(
+ (config) => config.name === pendingUpdateTableConfig.name
+ );
+ if (tableIndex < 0) {
+ pendingUpdateSchemaConfig.tableConfigs.push(pendingUpdateTableConfig);
+ } else {
+ pendingUpdateSchemaConfig.tableConfigs[tableIndex] =
+ pendingUpdateTableConfig;
+ }
+
+ const pendingUpdateDatabaseConfig = cloneDeep(databaseMetadata.value);
+ const schemaIndex = pendingUpdateDatabaseConfig.schemaConfigs.findIndex(
+ (config) => config.name === pendingUpdateSchemaConfig.name
+ );
+ if (schemaIndex < 0) {
+ pendingUpdateDatabaseConfig.schemaConfigs.push(pendingUpdateSchemaConfig);
+ } else {
+ pendingUpdateDatabaseConfig.schemaConfigs[schemaIndex] =
+ pendingUpdateSchemaConfig;
+ }
+
+ await dbSchemaV1Store.updateDatabaseSchemaConfigs(
+ pendingUpdateDatabaseConfig
+ );
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.updated"),
+ });
+};
+</script>
diff --git a/frontend/src/components/ColumnDataTable/index.vue b/frontend/src/components/ColumnDataTable/index.vue
new file mode 100644
index 0000000000..e8d0429ddb
--- /dev/null
+++ b/frontend/src/components/ColumnDataTable/index.vue
@@ -0,0 +1,255 @@
+<template>
+ <NDataTable
+ :columns="columns"
+ :data="columnList"
+ :max-height="640"
+ :virtual-scroll="true"
+ :striped="true"
+ :bordered="true"
+ :bottom-bordered="true"
+ />
+</template>
+
+<script lang="ts" setup>
+import { DataTableColumn, NDataTable } from "naive-ui";
+import { computed, PropType } from "vue";
+import { h } from "vue";
+import { useI18n } from "vue-i18n";
+import { getColumnDefaultValuePlaceholder } from "@/components/SchemaEditorV1/utils/columnDefaultValue";
+import ClassificationLevelBadge from "@/components/SchemaTemplate/ClassificationLevelBadge.vue";
+import { useCurrentUserV1, useSubscriptionV1Store } from "@/store";
+import { ComposedDatabase } from "@/types";
+import { Engine } from "@/types/proto/v1/common";
+import {
+ ColumnMetadata,
+ TableMetadata,
+} 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 } from "@/utils";
+import LabelsCell from "./LabelsCell.vue";
+import MaskingLevelCell from "./MaskingLevelCell.vue";
+import SemanticTypeCell from "./SemanticTypeCell.vue";
+
+const props = defineProps({
+ database: {
+ required: true,
+ type: Object as PropType<ComposedDatabase>,
+ },
+ schema: {
+ required: true,
+ type: String,
+ },
+ table: {
+ required: true,
+ type: Object as PropType<TableMetadata>,
+ },
+ columnList: {
+ required: true,
+ type: Object as PropType<ColumnMetadata[]>,
+ },
+ maskDataList: {
+ required: true,
+ type: Array as PropType<MaskData[]>,
+ },
+ classificationConfig: {
+ required: false,
+ default: undefined,
+ type: Object as PropType<
+ DataClassificationSetting_DataClassificationConfig | undefined
+ >,
+ },
+});
+
+const { t } = useI18n();
+const engine = computed(() => {
+ return props.database.instanceEntity.engine;
+});
+const currentUserV1 = useCurrentUserV1();
+const subscriptionV1Store = useSubscriptionV1Store();
+
+const hasSensitiveDataFeature = computed(() => {
+ return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
+});
+
+const showSensitiveColumn = computed(() => {
+ return (
+ hasSensitiveDataFeature.value &&
+ (engine.value === Engine.MYSQL ||
+ engine.value === Engine.TIDB ||
+ engine.value === Engine.POSTGRES ||
+ engine.value === Engine.REDSHIFT ||
+ engine.value === Engine.ORACLE ||
+ engine.value === Engine.SNOWFLAKE ||
+ engine.value === Engine.MSSQL ||
+ engine.value === Engine.RISINGWAVE)
+ );
+});
+
+const showClassificationColumn = computed(() => {
+ return (
+ (engine.value === Engine.MYSQL || engine.value === Engine.POSTGRES) &&
+ props.classificationConfig
+ );
+});
+
+const showCollationColumn = computed(() => {
+ return (
+ engine.value !== Engine.CLICKHOUSE && engine.value !== Engine.SNOWFLAKE
+ );
+});
+
+const hasSensitiveDataPermission = computed(() => {
+ if (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-sensitive-data",
+ currentUserV1.value.userRole
+ )
+ ) {
+ // True if the currentUser has workspace level sensitive data
+ // R+W privileges. AKA DBA or Workspace owner
+ return true;
+ }
+
+ // False otherwise
+ return false;
+});
+
+const columns = computed(() => {
+ const columns: (DataTableColumn<ColumnMetadata> & { hide?: boolean })[] = [
+ {
+ key: "name",
+ title: t("common.name"),
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return column.name;
+ },
+ },
+ {
+ key: "maskingLevel",
+ title: t("settings.sensitive-data.masking-level.self"),
+ hide: !showSensitiveColumn.value,
+ resizable: true,
+ width: 220,
+ render: (column) => {
+ return h(MaskingLevelCell, {
+ database: props.database,
+ schema: props.schema,
+ table: props.table,
+ column: column,
+ maskDataList: props.maskDataList,
+ readonly: !hasSensitiveDataPermission.value,
+ });
+ },
+ },
+ {
+ key: "semanticType",
+ title: t("settings.sensitive-data.semantic-types.self"),
+ hide: !showSensitiveColumn.value,
+ resizable: true,
+ width: 140,
+ render: (column) => {
+ return h(SemanticTypeCell, {
+ database: props.database,
+ schema: props.schema,
+ table: props.table,
+ column: column,
+ readonly: !hasSensitiveDataPermission.value,
+ });
+ },
+ },
+ {
+ key: "classification",
+ title: t("database.classification.self"),
+ hide: !showClassificationColumn.value,
+ width: 140,
+ render: (column) => {
+ return h(ClassificationLevelBadge, {
+ classification: column.classification,
+ classificationConfig: props.classificationConfig,
+ });
+ },
+ },
+ {
+ key: "type",
+ title: t("common.type"),
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return column.type;
+ },
+ },
+ {
+ key: "default",
+ title: t("common.default"),
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return getColumnDefaultValuePlaceholder(column);
+ },
+ },
+ {
+ key: "nullable",
+ title: t("database.nullable"),
+ resizable: true,
+ width: 140,
+ render: (column) => {
+ return column.nullable;
+ },
+ },
+ {
+ key: "characterSet",
+ title: t("db.character-set"),
+ hide: engine.value === Engine.POSTGRES,
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return column.characterSet;
+ },
+ },
+ {
+ key: "collation",
+ title: t("db.collation"),
+ hide: !showCollationColumn.value,
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return column.collation;
+ },
+ },
+ {
+ key: "comment",
+ title: t("database.comment"),
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ render: (column) => {
+ return column.userComment;
+ },
+ },
+ {
+ key: "labels",
+ resizable: true,
+ width: 140,
+ title: t("common.labels"),
+ render: (column) => {
+ return h(LabelsCell, {
+ database: props.database,
+ schema: props.schema,
+ table: props.table,
+ column: column,
+ readonly: !hasSensitiveDataPermission.value,
+ });
+ },
+ },
+ ];
+
+ return columns.filter((column) => !column.hide);
+});
+</script>
diff --git a/frontend/src/components/ColumnTable.vue b/frontend/src/components/ColumnTable.vue
deleted file mode 100644
index aa59852444..0000000000
--- a/frontend/src/components/ColumnTable.vue
+++ /dev/null
@@ -1,613 +0,0 @@
-<template>
- <BBTable
- :column-list="columnNameList"
- :data-source="columnList"
- :show-header="true"
- :left-bordered="true"
- :right-bordered="true"
- :row-clickable="false"
- v-bind="$attrs"
- >
- <template #body="{ rowData: column }: { rowData: ColumnMetadata }">
- <BBTableCell class="bb-grid-cell">
- {{ column.name }}
- </BBTableCell>
- <BBTableCell v-if="showSensitiveColumn" class="bb-grid-cell">
- <div class="flex items-center">
- {{ getMaskingLevelText(column) }}
- <span v-if="!isColumnConfigMasking(column)">
- ({{
- $t(
- `settings.sensitive-data.masking-level.${maskingLevelToJSON(
- column.effectiveMaskingLevel
- ).toLowerCase()}`
- )
- }})
- </span>
- <NTooltip v-if="!isColumnConfigMasking(column)">
- <template #trigger>
- <heroicons-outline:question-mark-circle class="h-4 w-4 mr-2" />
- </template>
- <i18n-t
- tag="div"
- keypath="settings.sensitive-data.column-detail.column-effective-masking-tips"
- class="whitespace-pre-line"
- >
- <template #link>
- <router-link
- class="flex items-center light-link text-sm"
- to="/setting/sensitive-data#global-masking-rule"
- >
- {{ $t("settings.sensitive-data.global-rules.check-rules") }}
- </router-link>
- </template>
- </i18n-t>
- </NTooltip>
- <button
- v-if="hasSensitiveDataPermission"
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
- @click.prevent="openSensitiveDrawer(column)"
- >
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
- </div>
- </BBTableCell>
- <BBTableCell v-if="showSensitiveColumn" class="bb-grid-cell">
- <div class="flex items-center">
- {{ getColumnSemanticType(column.name)?.title }}
- <button
- 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="hasSensitiveDataPermission"
- class="w-5 h-5 p-0.5 hover:bg-gray-300 rounded cursor-pointer"
- @click.prevent="openSemanticTypeDrawer(column)"
- >
- <heroicons-outline:pencil class="w-4 h-4" />
- </button>
- </div>
- </BBTableCell>
- <BBTableCell v-if="showClassificationColumn" class="bb-grid-cell">
- <ClassificationLevelBadge
- :classification="column.classification"
- :classification-config="classificationConfig"
- />
- </BBTableCell>
- <BBTableCell class="bb-grid-cell">
- {{ column.type }}
- </BBTableCell>
- <BBTableCell class="bb-grid-cell">
- {{ getColumnDefaultValuePlaceholder(column) }}
- </BBTableCell>
- <BBTableCell class="bb-grid-cell">
- {{ column.nullable }}
- </BBTableCell>
- <BBTableCell
- v-if="
- engine !== Engine.POSTGRES &&
- engine !== Engine.CLICKHOUSE &&
- engine !== Engine.SNOWFLAKE
- "
- class="bb-grid-cell"
- >
- {{ column.characterSet }}
- </BBTableCell>
- <BBTableCell
- v-if="engine !== Engine.CLICKHOUSE && engine !== Engine.SNOWFLAKE"
- class="bb-grid-cell"
- >
- {{ column.collation }}
- </BBTableCell>
- <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>
-
- <FeatureModal
- feature="bb.feature.sensitive-data"
- :instance="database.instanceEntity"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
-
- <SensitiveColumnDrawer
- v-if="state.activeColumn"
- :show="state.showSensitiveDataDrawer"
- :column="{
- maskData: getColumnMasking(state.activeColumn ?? {} as ColumnMetadata),
- database: props.database,
- }"
- @dismiss="state.showSensitiveDataDrawer = false"
- />
-
- <SemanticTypesDrawer
- v-if="state.activeColumn"
- :show="state.showSemanticTypesDrawer"
- :semantic-type-list="semanticTypeList"
- @dismiss="state.showSemanticTypesDrawer = false"
- @apply="onSemanticTypeApply($event)"
- />
-
- <LabelEditorDrawer
- v-if="state.activeColumn"
- :show="state.showLabelsDrawer"
- :readonly="!hasEditLabelsPermission"
- :title="
- $t('db.labels-for-resource', { resource: `'${state.activeColumn.name}'` })
- "
- :labels="[getColumnConfig(state.activeColumn.name).labels]"
- @dismiss="state.showLabelsDrawer = false"
- @apply="onLabelsApply($event)"
- />
-</template>
-
-<script lang="ts" setup>
-import { cloneDeep } from "lodash-es";
-import { computed, PropType, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { BBTableColumn } from "@/bbkit/types";
-import { getColumnDefaultValuePlaceholder } from "@/components/SchemaEditorV1/utils/columnDefaultValue";
-import {
- useCurrentUserV1,
- useDBSchemaV1Store,
- useSettingV1Store,
- useSubscriptionV1Store,
- pushNotification,
-} from "@/store";
-import { ComposedDatabase } from "@/types";
-import {
- Engine,
- MaskingLevel,
- maskingLevelToJSON,
-} from "@/types/proto/v1/common";
-import {
- ColumnMetadata,
- 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, hasPermissionInProjectV1 } from "@/utils";
-
-type LocalState = {
- showFeatureModal: boolean;
- activeColumn?: ColumnMetadata;
- showSensitiveDataDrawer: boolean;
- showSemanticTypesDrawer: boolean;
- showLabelsDrawer: boolean;
-};
-
-const props = defineProps({
- database: {
- required: true,
- type: Object as PropType<ComposedDatabase>,
- },
- schema: {
- required: true,
- type: String,
- },
- table: {
- required: true,
- type: Object as PropType<TableMetadata>,
- },
- columnList: {
- required: true,
- type: Object as PropType<ColumnMetadata[]>,
- },
- maskDataList: {
- required: true,
- type: Array as PropType<MaskData[]>,
- },
- classificationConfig: {
- required: false,
- default: undefined,
- type: Object as PropType<
- DataClassificationSetting_DataClassificationConfig | undefined
- >,
- },
-});
-
-const { t } = useI18n();
-const state = reactive<LocalState>({
- showFeatureModal: false,
- showSensitiveDataDrawer: false,
- showSemanticTypesDrawer: false,
- showLabelsDrawer: false,
-});
-const engine = computed(() => {
- return props.database.instanceEntity.engine;
-});
-const subscriptionV1Store = useSubscriptionV1Store();
-const dbSchemaV1Store = useDBSchemaV1Store();
-const settingV1Store = useSettingV1Store();
-
-const instanceMissingLicense = computed(() => {
- return subscriptionV1Store.instanceMissingLicense(
- "bb.feature.sensitive-data",
- props.database.instanceEntity
- );
-});
-const hasSensitiveDataFeature = computed(() => {
- return subscriptionV1Store.hasFeature("bb.feature.sensitive-data");
-});
-
-const semanticTypeList = computed(() => {
- return (
- settingV1Store.getSettingByName("bb.workspace.semantic-types")?.value
- ?.semanticTypeSettingValue?.types ?? []
- );
-});
-
-const databaseMetadata = computed(() => {
- return dbSchemaV1Store.getDatabaseMetadata(props.database.name);
-});
-
-const schemaConfig = computed(() => {
- return (
- databaseMetadata.value.schemaConfigs.find(
- (config) => config.name === props.schema
- ) ??
- SchemaConfig.fromPartial({
- name: props.schema,
- tableConfigs: [],
- })
- );
-});
-
-const tableConfig = computed(() => {
- return (
- schemaConfig.value.tableConfigs.find(
- (config) => config.name === props.table.name
- ) ??
- TableConfig.fromPartial({
- name: props.table.name,
- columnConfigs: [],
- })
- );
-});
-
-const getColumnConfig = (columnName: string) => {
- return (
- tableConfig.value.columnConfigs.find(
- (config) => config.name === columnName
- ) ?? ColumnConfig.fromPartial({})
- );
-};
-
-const getColumnSemanticType = (columnName: string) => {
- const config = getColumnConfig(columnName);
- if (!config.semanticTypeId) {
- return;
- }
- return semanticTypeList.value.find(
- (data) => data.id === config.semanticTypeId
- );
-};
-
-const onLabelsApply = async (labelsList: { [key: string]: string }[]) => {
- const column = state.activeColumn;
- if (!column) {
- return;
- }
- await updateColumnConfig(column.name, { labels: labelsList[0] });
-};
-
-const onSemanticTypeApply = async (semanticTypeId: string) => {
- const column = state.activeColumn;
- if (!column) {
- return;
- }
- await updateColumnConfig(column.name, { semanticTypeId });
-};
-
-const onSemanticTypeRemove = async (column: string) => {
- await updateColumnConfig(column, { semanticTypeId: "" });
-};
-
-const updateColumnConfig = async (
- column: string,
- config: Partial<ColumnConfig>
-) => {
- const index = tableConfig.value.columnConfigs.findIndex(
- (config) => config.name === column
- );
-
- const pendingUpdateTableConfig = cloneDeep(tableConfig.value);
- if (index < 0) {
- pendingUpdateTableConfig.columnConfigs.push(
- ColumnConfig.fromPartial({
- name: column,
- ...config,
- })
- );
- } else {
- pendingUpdateTableConfig.columnConfigs[index] = {
- ...pendingUpdateTableConfig.columnConfigs[index],
- ...config,
- };
- }
-
- const pendingUpdateSchemaConfig = cloneDeep(schemaConfig.value);
- const tableIndex = pendingUpdateSchemaConfig.tableConfigs.findIndex(
- (config) => config.name === pendingUpdateTableConfig.name
- );
- if (tableIndex < 0) {
- pendingUpdateSchemaConfig.tableConfigs.push(pendingUpdateTableConfig);
- } else {
- pendingUpdateSchemaConfig.tableConfigs[tableIndex] =
- pendingUpdateTableConfig;
- }
-
- const pendingUpdateDatabaseConfig = cloneDeep(databaseMetadata.value);
- const schemaIndex = pendingUpdateDatabaseConfig.schemaConfigs.findIndex(
- (config) => config.name === pendingUpdateSchemaConfig.name
- );
- if (schemaIndex < 0) {
- pendingUpdateDatabaseConfig.schemaConfigs.push(pendingUpdateSchemaConfig);
- } else {
- pendingUpdateDatabaseConfig.schemaConfigs[schemaIndex] =
- pendingUpdateSchemaConfig;
- }
-
- await dbSchemaV1Store.updateDatabaseSchemaConfigs(
- pendingUpdateDatabaseConfig
- );
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.updated"),
- });
-};
-
-const showSensitiveColumn = computed(() => {
- return (
- hasSensitiveDataFeature.value &&
- (engine.value === Engine.MYSQL ||
- engine.value === Engine.TIDB ||
- engine.value === Engine.POSTGRES ||
- engine.value === Engine.REDSHIFT ||
- engine.value === Engine.ORACLE ||
- engine.value === Engine.SNOWFLAKE ||
- engine.value === Engine.MSSQL ||
- engine.value === Engine.RISINGWAVE)
- );
-});
-
-const showClassificationColumn = computed(() => {
- return (
- (engine.value === Engine.MYSQL || engine.value === Engine.POSTGRES) &&
- props.classificationConfig
- );
-});
-
-const currentUserV1 = useCurrentUserV1();
-const hasSensitiveDataPermission = computed(() => {
- if (
- hasWorkspacePermissionV1(
- "bb.permission.workspace.manage-sensitive-data",
- currentUserV1.value.userRole
- )
- ) {
- // True if the currentUser has workspace level sensitive data
- // R+W privileges. AKA DBA or Workspace owner
- return true;
- }
-
- // False otherwise
- 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: {
- title: string;
- hide?: boolean;
- }[] = [
- {
- title: t("common.name"),
- },
- {
- title: t("settings.sensitive-data.masking-level.self"),
- hide: !showSensitiveColumn.value,
- },
- {
- title: t("settings.sensitive-data.semantic-types.self"),
- hide: !showSensitiveColumn.value,
- },
- {
- title: t("database.classification.self"),
- hide: !showClassificationColumn.value,
- },
- {
- title: t("common.type"),
- },
- {
- title: t("common.Default"),
- },
- {
- title: t("database.nullable"),
- },
- {
- title: t("db.character-set"),
- },
- {
- title: t("db.collation"),
- },
- {
- title: t("database.comment"),
- },
- {
- title: t("common.labels"),
- },
- ];
- return columnList;
-});
-const POSTGRES_COLUMN_LIST = computed(() => {
- const columnList: {
- title: string;
- hide?: boolean;
- }[] = [
- {
- title: t("common.name"),
- },
- {
- title: t("settings.sensitive-data.masking-level.self"),
- hide: !showSensitiveColumn.value,
- },
- {
- title: t("settings.sensitive-data.semantic-types.self"),
- hide: !showSensitiveColumn.value,
- },
- {
- title: t("database.classification.self"),
- hide: !showClassificationColumn.value,
- },
- {
- title: t("common.type"),
- },
- {
- title: t("common.Default"),
- },
- {
- title: t("database.nullable"),
- },
- {
- title: t("db.collation"),
- },
- {
- title: t("database.comment"),
- },
- {
- title: t("common.labels"),
- },
- ];
- return columnList;
-});
-const CLICKHOUSE_SNOWFLAKE_COLUMN_LIST = computed((): BBTableColumn[] => [
- {
- title: t("common.name"),
- },
- {
- title: t("common.type"),
- },
- {
- title: t("common.Default"),
- },
- {
- title: t("database.nullable"),
- },
- {
- title: t("database.comment"),
- },
- {
- title: t("common.labels"),
- },
-]);
-
-const columnNameList = computed((): BBTableColumn[] => {
- switch (engine.value) {
- case Engine.POSTGRES:
- return POSTGRES_COLUMN_LIST.value.filter((col) => !col.hide);
- case Engine.CLICKHOUSE:
- case Engine.SNOWFLAKE:
- return CLICKHOUSE_SNOWFLAKE_COLUMN_LIST.value;
- default:
- return NORMAL_COLUMN_LIST.value.filter((col) => !col.hide);
- }
-});
-
-const isColumnConfigMasking = (column: ColumnMetadata): boolean => {
- return (
- getColumnMasking(column).maskingLevel !==
- MaskingLevel.MASKING_LEVEL_UNSPECIFIED
- );
-};
-
-const getColumnMasking = (column: ColumnMetadata): MaskData => {
- return (
- props.maskDataList.find((sensitiveData) => {
- return (
- sensitiveData.table === props.table.name &&
- sensitiveData.column === column.name &&
- sensitiveData.schema === props.schema
- );
- }) ?? {
- schema: props.schema,
- table: props.table.name,
- column: column.name,
- maskingLevel: MaskingLevel.MASKING_LEVEL_UNSPECIFIED,
- fullMaskingAlgorithmId: "",
- partialMaskingAlgorithmId: "",
- }
- );
-};
-
-const openSensitiveDrawer = (column: ColumnMetadata) => {
- if (!hasSensitiveDataFeature.value || instanceMissingLicense.value) {
- state.showFeatureModal = true;
- 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;
-};
-
-const getMaskingLevelText = (column: ColumnMetadata) => {
- const masking = getColumnMasking(column);
- const level = maskingLevelToJSON(masking.maskingLevel);
- return t(`settings.sensitive-data.masking-level.${level.toLowerCase()}`);
-};
-</script>
diff --git a/frontend/src/components/TableDetailDrawer.vue b/frontend/src/components/TableDetailDrawer.vue
index 4bcd31109c..75340cc783 100644
--- a/frontend/src/components/TableDetailDrawer.vue
+++ b/frontend/src/components/TableDetailDrawer.vue
@@ -167,7 +167,7 @@
<div class="text-lg leading-6 font-medium text-main mb-4">
{{ $t("database.columns") }}
</div>
- <ColumnTable
+ <ColumnDataTable
:database="database"
:schema="schemaName"
:table="table"
@@ -214,7 +214,7 @@ import {
isDatabaseV1Queryable,
isGhostTable,
} from "@/utils";
-import ColumnTable from "./ColumnTable.vue";
+import ColumnDataTable from "./ColumnDataTable/index.vue";
import { SQLEditorButtonV1 } from "./DatabaseDetail";
import IndexTable from "./IndexTable.vue";