Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: flexible database labels (#8630)
Liu Ji102299997f9a
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vueindex 50549cf04b..6d0e1470d3 100644--- a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue@@ -55,7 +55,7 @@import { computed, watchEffect } from "vue";import { RouterLink } from "vue-router";import { useDeploymentConfigV1ByProject } from "@/store";-import type { ComposedDatabase, LabelKeyType } from "@/types";+import type { ComposedDatabase } from "@/types";import { Environment } from "@/types/proto/v1/environment_service";import { Project } from "@/types/proto/v1/project_service";import { getPipelineFromDeploymentScheduleV1, projectV1Slug } from "@/utils";@@ -64,7 +64,7 @@ import { DeployDatabaseTable } from "../TenantDatabaseTable";export type ProjectTenantViewState = {selectedDatabaseIdListForTenantMode: Set<string>;deployingTenantDatabaseList: string[];- label: LabelKeyType;+ label: string;};const props = defineProps<{diff --git a/frontend/src/components/DatabaseDetail/Settings/components/Labels.vue b/frontend/src/components/DatabaseDetail/Settings/components/Labels.vueindex 32c3dd670b..6e19cf5cc2 100644--- a/frontend/src/components/DatabaseDetail/Settings/components/Labels.vue+++ b/frontend/src/components/DatabaseDetail/Settings/components/Labels.vue@@ -42,7 +42,7 @@</template><script setup lang="ts">-import { cloneDeep, isEqual } from "lodash-es";+import { isEqual } from "lodash-es";import { NButton } from "naive-ui";import { computed, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";@@ -55,7 +55,6 @@ import {import { type ComposedDatabase } from "@/types";import { Database } from "@/types/proto/v1/database_service";import {- PRESET_LABEL_KEYS,convertKVListToLabels,convertLabelsToKVList,hasPermissionInProjectV1,@@ -97,14 +96,7 @@ const allowAdmin = computed(() => {});const convert = () => {- const labels = cloneDeep(props.database.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 */);+ return convertLabelsToKVList(props.database.labels, true /* sort */);};const dirty = computed(() => {diff --git a/frontend/src/components/DatabaseLabels/DatabaseLabelPropItem.vue b/frontend/src/components/DatabaseLabels/DatabaseLabelPropItem.vuedeleted file mode 100644index 942e0068fb..0000000000--- a/frontend/src/components/DatabaseLabels/DatabaseLabelPropItem.vue+++ /dev/null@@ -1,160 +0,0 @@-<template>- <span class="textlabel relative inline-flex items-center gap-x-1">- <template v-if="!state.editing">- {{ value || $t("label.empty-label-value") }}-- <heroicons-outline:pencil- class="w-5 h-5 p-0.5 rounded cursor-pointer hover:bg-control-bg-hover"- @click="startEditing"- />- </template>- <template v-else-if="state.editing">- <input- ref="input"- v-model="state.value"- type="text"- autocomplete="off"- class="textfield"- :class="{ error: !!state.error && state.changed }"- :placeholder="$t('setting.label.value-placeholder')"- @blur="cancel"- @keyup.esc="cancel"- @keyup.enter="save"- />- <div class="icon-btn cancel" @click="cancel">- <heroicons-solid:x class="w-4 h-4" />- </div>- <NPopover trigger="hover" :disabled="!state.error">- <template #trigger>- <div- class="icon-btn save"- :class="{ disabled: !!state.error }"- @mousedown.prevent.stop="save"- >- <heroicons-solid:check class="w-4 h-4" />- </div>- </template>-- <div class="text-red-600 whitespace-nowrap">- {{ state.error }}- </div>- </NPopover>- </template>- </span>-</template>--<script lang="ts" setup>-import { nextTick, reactive, ref, watch } from "vue";-import { useI18n } from "vue-i18n";-import { ComposedDatabase } from "../../types";-import { MAX_LABEL_VALUE_LENGTH } from "../../utils";--type LocalState = {- editing: boolean;- value: string | undefined;- error: string | undefined;- changed: boolean;-};--const props = defineProps<{- labelKey: string;- value: string | undefined;- database: ComposedDatabase;- allowEdit: boolean;-}>();--const emit = defineEmits<{- (e: "update:value", value: string): void;-}>();--const { t } = useI18n();--const state = reactive<LocalState>({- editing: false,- value: props.value,- error: undefined,- changed: false,-});--const input = ref<HTMLInputElement>();--watch(- () => props.value,- (value) => (state.value = value)-);--const startEditing = () => {- state.value = props.value;- state.error = undefined;- state.changed = false;- state.editing = true;-- nextTick(() => {- input.value?.focus();- });-};-const validate = (): boolean => {- const value = state.value?.trim();-- if (!value) {- // Empty value is allowed- state.error = undefined;- return true;- }-- if (value.length > MAX_LABEL_VALUE_LENGTH) {- // Max length exceeded- state.error = t("label.error.max-length-exceeded", {- len: MAX_LABEL_VALUE_LENGTH,- });- } else {- state.error = undefined;- }-- return !state.error;-};--const cancel = () => {- state.editing = false;-};--const save = () => {- if (!validate()) return;-- const value = state.value?.trim() ?? "";- emit("update:value", value);- cancel();-};--watch([() => state.editing, () => state.value], ([editing, value]) => {- if (!editing) return;- if (value !== props.value) {- state.changed = true;- validate();- }-});-</script>--<style scoped lang="postcss">-.icon-btn {- @apply w-[20px] h-[20px] inline-flex items-center justify-center- rounded bg-white border border-control-border- hover:bg-control-bg-hover- cursor-pointer;-}-.icon-btn.disabled {- @apply cursor-not-allowed bg-control-bg;-}-.textfield {- @apply rounded px-0.5 py-0 text-sm w-32 h-[20px];-}-.textfield.error {- @apply border-error focus:ring-error focus:border-error;-}-.cancel {- @apply text-control;-}-.save {- @apply text-success;-}-</style>diff --git a/frontend/src/components/DatabaseLabels/DatabaseLabelProps.vue b/frontend/src/components/DatabaseLabels/DatabaseLabelProps.vuedeleted file mode 100644index 6e53358f74..0000000000--- a/frontend/src/components/DatabaseLabels/DatabaseLabelProps.vue+++ /dev/null@@ -1,63 +0,0 @@-<template>- <template v-for="label in PRESET_LABEL_KEYS" :key="label.key">- <dd class="flex items-center text-sm md:mr-4">- <slot name="label" :label="label"></slot>- <DatabaseLabelPropItem- :label-key="label"- :value="getLabelValue(label)"- :database="database"- :allow-edit="allowEdit"- @update:value="(value) => onUpdateValue(label, value)"- />- </dd>- </template>-</template>--<script lang="ts" setup>-import { cloneDeep } from "lodash-es";-import { withDefaults, watch, reactive } from "vue";-import type { ComposedDatabase } from "@/types";-import { PRESET_LABEL_KEYS } from "@/utils";-import DatabaseLabelPropItem from "./DatabaseLabelPropItem.vue";--const props = withDefaults(- defineProps<{- labels: Record<string, string>;- database: ComposedDatabase;- allowEdit?: boolean;- }>(),- {- allowEdit: false,- }-);--const emit = defineEmits<{- (event: "update:labels", labels: Record<string, string>): void;-}>();--const state = reactive({- labels: cloneDeep(props.labels),-});--watch(- () => props.labels,- (list) => (state.labels = cloneDeep(list))-);--const getLabelValue = (key: string): string | undefined => {- return state.labels[key] ?? "";-};--const setLabelValue = (key: string, value: string) => {- if (value) {- state.labels[key] = value;- } else {- delete state.labels[key];- }-};--const onUpdateValue = (key: string, value: string) => {- setLabelValue(key, value);- emit("update:labels", state.labels);-};-</script>diff --git a/frontend/src/components/DatabaseLabels/index.ts b/frontend/src/components/DatabaseLabels/index.tsdeleted file mode 100644index 5d749fc2e7..0000000000--- a/frontend/src/components/DatabaseLabels/index.ts+++ /dev/null@@ -1,3 +0,0 @@-import DatabaseLabelProps from "./DatabaseLabelProps.vue";--export { DatabaseLabelProps };diff --git a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vueindex 6f559e1633..d8946a4b82 100644--- a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue+++ b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue@@ -41,7 +41,7 @@<script lang="ts" setup>import { computed, reactive } from "vue";-import { ComposedDatabase, LabelKeyType } from "@/types";+import { ComposedDatabase } from "@/types";import { Environment } from "@/types/proto/v1/environment_service";import { DeploymentConfig } from "@/types/proto/v1/project_service";import { filterDatabaseV1ByKeyword } from "@/utils";@@ -60,7 +60,7 @@ const props = withDefaults();const state = reactive({- label: "environment" as LabelKeyType,+ label: "environment",keyword: "",});diff --git a/frontend/src/components/DeploymentConfigTool/DeploymentStage.vue b/frontend/src/components/DeploymentConfigTool/DeploymentStage.vueindex e473315385..a10bbd153c 100644--- a/frontend/src/components/DeploymentConfigTool/DeploymentStage.vue+++ b/frontend/src/components/DeploymentConfigTool/DeploymentStage.vue@@ -69,13 +69,13 @@<script lang="ts">import { computed, defineComponent, PropType } from "vue";+import { ComposedDatabase } from "@/types";import {LabelSelectorRequirement,OperatorType,ScheduleDeployment,} from "@/types/proto/v1/project_service";-import { PRESET_LABEL_KEYS, RESERVED_LABEL_KEYS } from "@/utils";-import { ComposedDatabase } from "../../types";+import { getAvailableDeploymentConfigMatchSelectorKeyList } from "@/utils";import SelectorItem from "./SelectorItem.vue";export default defineComponent({@@ -114,7 +114,11 @@ export default defineComponent({emits: ["remove", "prev", "next"],setup(props) {const keys = computed(() => {- return [...RESERVED_LABEL_KEYS, ...PRESET_LABEL_KEYS];+ return getAvailableDeploymentConfigMatchSelectorKeyList(+ props.databaseList,+ true /* withVirtualLabelKeys */,+ true /* sort */+ );});const removeSelector = (selector: LabelSelectorRequirement) => {diff --git a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue b/frontend/src/components/DeploymentConfigTool/SelectorItem.vueindex 08f7bf26a5..8103ed7474 100644--- a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue+++ b/frontend/src/components/DeploymentConfigTool/SelectorItem.vue@@ -40,8 +40,8 @@ import {OperatorType,} from "@/types/proto/v1/project_service";import {- displayLabelKey,- getAvailableLabelKeyList,+ displayDeploymentMatchSelectorKey,+ getAvailableDeploymentConfigMatchSelectorKeyList,getLabelValuesFromDatabaseV1List,} from "@/utils";import LabelSelect from "./LabelSelect.vue";@@ -71,10 +71,9 @@ defineEmits<{}>();const keys = computed(() => {- return getAvailableLabelKeyList(+ return getAvailableDeploymentConfigMatchSelectorKeyList(props.databaseList,- true /* withReserved */,- true /* withPreset */,+ true /* withVirtualLabelKeys */,true /* sort */);});@@ -95,7 +94,7 @@ const resetValues = () => {};const labelKeyModifier = (key: string | number) => {- return displayLabelKey(key as string);+ return displayDeploymentMatchSelectorKey(key as string);};const operatorToText = (op: string | number) => {diff --git a/frontend/src/components/Label/LabelEditorRow.vue b/frontend/src/components/Label/LabelEditorRow.vueindex 8ae2179746..ccc4cbf57f 100644--- a/frontend/src/components/Label/LabelEditorRow.vue+++ b/frontend/src/components/Label/LabelEditorRow.vue@@ -1,61 +1,56 @@<template>- <template v-if="!isReservedLabel(kv.key)">- <div class="contents text-sm">- <div class="flex flex-col">- <span class="text-xs font-medium"> Key {{ index + 1 }} </span>- <span v-if="isPresetLabel(kv.key) || readonly" class="leading-[34px]">- {{ displayLabelKey(kv.key) }}- </span>- <NInput- v-else- :value="kv.key"- :placeholder="$t('setting.label.key-placeholder')"- :status="errors.key.length > 0 ? 'error' : undefined"- @update:value="$emit('update-key', $event)"- />- </div>- <div class="flex flex-col">- <span class="text-xs font-medium"> Value {{ index + 1 }} </span>- <span v-if="readonly" class="leading-[34px]">- <template v-if="kv.value">{{ kv.value }}</template>- <span v-else class="text-control-placeholder">- {{ $t("label.empty-label-value") }}- </span>+ <div class="contents text-sm">+ <div class="flex flex-col">+ <span class="text-xs font-medium"> Key {{ index + 1 }} </span>+ <span v-if="readonly" class="leading-[34px]">+ {{ kv.key }}+ </span>+ <NInput+ v-else+ :value="kv.key"+ :placeholder="$t('setting.label.key-placeholder')"+ :status="errors.key.length > 0 ? 'error' : undefined"+ @update:value="$emit('update-key', $event)"+ />+ </div>+ <div class="flex flex-col">+ <span class="text-xs font-medium"> Value {{ index + 1 }} </span>+ <span v-if="readonly" class="leading-[34px]">+ <template v-if="kv.value">{{ kv.value }}</template>+ <span v-else class="text-control-placeholder">+ {{ $t("label.empty-label-value") }}</span>- <NInput- v-else- :value="kv.value"- :placeholder="$t('setting.label.value-placeholder')"- :status="errors.value.length > 0 ? 'error' : undefined"- @update:value="$emit('update-value', $event)"- />- </div>- <div class="flex flex-row self-stretch items-center pt-4">- <NButton- quaternary- size="small"- style="--n-padding: 0 6px"- :class="[- !isPresetLabel(kv.key) && !readonly ? 'visible' : 'invisible',- ]"- @click="$emit('remove')"- >- <template #icon>- <heroicons:trash />- </template>- </NButton>- </div>+ </span>+ <NInput+ v-else+ :value="kv.value"+ :placeholder="$t('setting.label.value-placeholder')"+ :status="errors.value.length > 0 ? 'error' : undefined"+ @update:value="$emit('update-value', $event)"+ /></div>- <div v-if="combinedErrors.length > 0" class="text-xs text-error col-span-3">- <ErrorList :errors="combinedErrors" bullets="always" />+ <div class="flex flex-row self-stretch items-center pt-4">+ <NButton+ quaternary+ size="small"+ style="--n-padding: 0 6px"+ :class="[readonly ? 'invisible' : 'visible']"+ @click="$emit('remove')"+ >+ <template #icon>+ <heroicons:trash />+ </template>+ </NButton></div>- </template>+ </div>+ <div v-if="combinedErrors.length > 0" class="text-xs text-error col-span-3">+ <ErrorList :errors="combinedErrors" bullets="always" />+ </div></template><script setup lang="ts">import { NButton, NInput } from "naive-ui";import { computed } from "vue";-import { isReservedLabel, isPresetLabel, displayLabelKey } from "@/utils";import ErrorList from "../misc/ErrorList.vue";const props = defineProps<{diff --git a/frontend/src/components/Label/LabelListEditor.vue b/frontend/src/components/Label/LabelListEditor.vueindex 592bc90270..8dabb3a088 100644--- a/frontend/src/components/Label/LabelListEditor.vue+++ b/frontend/src/components/Label/LabelListEditor.vue@@ -36,7 +36,7 @@ import { useI18n } from "vue-i18n";import {validateLabelKey,MAX_LABEL_VALUE_LENGTH,- isPresetLabel,+ isVirtualLabelKey,} from "@/utils";import LabelEditorRow from "./LabelEditorRow.vue";@@ -68,6 +68,9 @@ const errorList = computed(() => {if (!key) {errors.key.push(t("label.error.key-necessary"));} else {+ if (isVirtualLabelKey(key)) {+ errors.key.push(t("label.error.x-is-reserved-key", { key }));+ }if (!validateLabelKey(key)) {errors.key.push(t("label.error.key-format"));}@@ -76,9 +79,7 @@ const errorList = computed(() => {}}if (!value) {- if (!isPresetLabel(key)) {- errors.value.push(t("label.error.value-necessary"));- }+ errors.value.push(t("label.error.value-necessary"));} else if (value.length > MAX_LABEL_VALUE_LENGTH) {errors.value.push(t("label.error.max-value-length-exceeded", {diff --git a/frontend/src/components/TenantDatabaseTable/DatabaseMatrixItem.vue b/frontend/src/components/TenantDatabaseTable/DatabaseMatrixItem.vueindex da4122b717..b584a9b5ae 100644--- a/frontend/src/components/TenantDatabaseTable/DatabaseMatrixItem.vue+++ b/frontend/src/components/TenantDatabaseTable/DatabaseMatrixItem.vue@@ -68,7 +68,7 @@class="flex items-center space-y-1"><span class="text-left">- {{ displayLabelKey(label.key) }}+ {{ displayDeploymentMatchSelectorKey(label.key) }}</span><spanclass="flex-1 h-px mx-2 border-b border-control-border border-dashed"@@ -83,14 +83,14 @@<script lang="ts" setup>import { NPopover } from "naive-ui";import { computed, PropType } from "vue";+import { ComposedDatabase } from "@/types";import { State } from "@/types/proto/v1/common";-import { ComposedDatabase } from "../../types";import {convertLabelsToKVList,databaseV1Slug,- isReservedLabel,- displayLabelKey,-} from "../../utils";+ isVirtualLabelKey,+ displayDeploymentMatchSelectorKey,+} from "@/utils";import { InstanceV1Name } from "../v2";const props = defineProps({@@ -102,7 +102,7 @@ const props = defineProps({const displayLabelList = computed(() => {return convertLabelsToKVList(props.database.labels, true /* sort */)- .filter((kv) => !isReservedLabel(kv.key))+ .filter((kv) => !isVirtualLabelKey(kv.key)).filter((kv) => kv.value !== "");});diff --git a/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue b/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vueindex 643b9736a9..a4b327538c 100644--- a/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue+++ b/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue@@ -9,7 +9,7 @@<template #header><tr><BBTableHeaderCell compact class="w-1/12 pl-3 pr-2 whitespace-nowrap">- {{ displayLabelKey(label) }}+ {{ displayDeploymentMatchSelectorKey(label) }}</BBTableHeaderCell><BBTableHeaderCell@@ -106,13 +106,13 @@import { groupBy } from "lodash-es";import { NPopover } from "naive-ui";import { computed, withDefaults } from "vue";-import type { ComposedDatabase, LabelKeyType } from "@/types";+import type { ComposedDatabase } from "@/types";import { Environment } from "@/types/proto/v1/environment_service";import { DeploymentConfig } from "@/types/proto/v1/project_service";import {getLabelValuesFromDatabaseV1List,getPipelineFromDeploymentScheduleV1,- displayLabelKey,+ displayDeploymentMatchSelectorKey,getSemanticLabelValue,} from "@/utils";import { DeploymentStage } from "../DeploymentConfigTool";@@ -121,7 +121,7 @@ import DatabaseMatrixItem from "./DatabaseMatrixItem.vue";const props = withDefaults(defineProps<{databaseList: ComposedDatabase[];- label: LabelKeyType;+ label: string;environmentList: Environment[];deployment: DeploymentConfig;bordered?: boolean;diff --git a/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vueindex 55f7951b55..866507c99b 100644--- a/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue+++ b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue@@ -11,7 +11,7 @@:value="key"class="capitalize">- {{ displayLabelKey(key) }}+ {{ displayDeploymentMatchSelectorKey(key) }}</option></select></div>@@ -19,14 +19,17 @@<script lang="ts" setup>import { computed, withDefaults } from "vue";-import { ComposedDatabase, LabelKeyType } from "@/types";-import { displayLabelKey, getAvailableLabelKeyList } from "@/utils";+import { ComposedDatabase } from "@/types";+import {+ displayDeploymentMatchSelectorKey,+ getAvailableDeploymentConfigMatchSelectorKeyList,+} from "@/utils";const props = withDefaults(defineProps<{databaseList: ComposedDatabase[];- label: LabelKeyType;- excludedKeyList?: LabelKeyType[];+ label: string;+ excludedKeyList?: string[];}>(),{excludedKeyList: () => [],@@ -34,14 +37,13 @@ const props = withDefaults();const emit = defineEmits<{- (event: "update:label", label: LabelKeyType): void;+ (event: "update:label", label: string): void;}>();const labelKeyList = computed(() => {- return getAvailableLabelKeyList(+ return getAvailableDeploymentConfigMatchSelectorKeyList(props.databaseList,- true /* withReserved */,- true /* withPreset */,+ true /* withVirtualLabelKeys */,true /* sort */).filter((key) => !props.excludedKeyList.includes(key));});diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 9e78b1b4d8..9019e5da71 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2151,7 +2151,8 @@"max-label-count-exceeded": "Cannot exceed {count} labels","cannot-edit-reserved-label": "Cannot edit reserved label \"{key}\"","max-value-length-exceeded": "Value's length cannot exceed {length} characters",- "key-format": "Only alphanumeric characters ([a-z0-9A-Z]), hyphens (-), underscores (_) and dots (.) are allowed. And must begin and ends with alphanumeric characters."+ "key-format": "Only alphanumeric characters ([a-z0-9A-Z]), hyphens (-), underscores (_) and dots (.) are allowed. And must begin and ends with alphanumeric characters.",+ "x-is-reserved-key": "\"{key}\" is a system reserved key"},"placeholder": {"select-key": "Select key...",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 6208731e75..fbb20819ea 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2147,7 +2147,8 @@"max-label-count-exceeded": "No se pueden exceder las {count} etiquetas","cannot-edit-reserved-label": "No se puede editar la etiqueta reservada \"{key}\"","max-value-length-exceeded": "La longitud del valor no puede exceder {longitud} caracteres",- "key-format": "Sólo se permiten caracteres alfanuméricos ([a-z0-9A-Z]), guiones (-), guiones bajos (_) y puntos (.). \nY debe comenzar y terminar con caracteres alfanuméricos."+ "key-format": "Sólo se permiten caracteres alfanuméricos ([a-z0-9A-Z]), guiones (-), guiones bajos (_) y puntos (.). \nY debe comenzar y terminar con caracteres alfanuméricos.",+ "x-is-reserved-key": "\"{key}\" es una clave reservada del sistema"},"placeholder": {"select-key": "Seleccionar clave...",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 558f45bc81..7b695ee4e5 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2147,7 +2147,8 @@"max-label-count-exceeded": "不能多于 {count} 个标签","cannot-edit-reserved-label": "不能编辑预留标签 \"{key}\"","max-value-length-exceeded": "值长的度不能超过 {length} 字符",- "key-format": "仅允许使用字母和数字 ([a-z0-9A-Z])、连字符 (-)、下划线 (_) 和点 (.)。\n并且必须以字母和数字开头和结尾。"+ "key-format": "仅允许使用字母和数字 ([a-z0-9A-Z])、连字符 (-)、下划线 (_) 和点 (.)。\n并且必须以字母和数字开头和结尾。",+ "x-is-reserved-key": "\"{key}\" 是系统保留 Key"},"placeholder": {"select-key": "选择 Key…",diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.tsindex 5c98a83ad7..bdc8091dff 100644--- a/frontend/src/types/id.ts+++ b/frontend/src/types/id.ts@@ -59,5 +59,3 @@ export type SheetId = IdType;// Currently, only issue can be used a container.// The type is used by Activity and Messageexport type ContainerId = IssueId;--export type LabelId = IdType;diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 5c3788e15e..a833b3c28b 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -28,7 +28,6 @@ export * from "./sql";export * from "./sqlAdvice";export * from "./store";export * from "./vcs";-export * from "./label";export * from "./sqlEditor";export * from "./connectionTree";export * from "./tab";diff --git a/frontend/src/types/label.ts b/frontend/src/types/label.tsdeleted file mode 100644index 1d5267e498..0000000000--- a/frontend/src/types/label.ts+++ /dev/null@@ -1,26 +0,0 @@-import { LabelId } from "./id";--export type LabelKeyType = string;-export type LabelValueType = string;--export type Label = {- id: LabelId;-- // Domain specific fields- key: LabelKeyType;- valueList: LabelValueType[];-};--export type LabelPatch = {- valueList?: LabelValueType[];-};--export type DatabaseLabel = {- key: LabelKeyType;- value: LabelValueType;-};--export type AvailableLabel = {- key: LabelKeyType;- valueList: LabelValueType[];-};diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 943478bec5..6ccf7a6714 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -15,7 +15,6 @@ import {} from "./id";import { Instance, MigrationHistory } from "./instance";import { Issue } from "./issue";-import { Label } from "./label";import { Notification } from "./notification";import { Principal } from "./principal";import { Project } from "./project";@@ -89,10 +88,6 @@ export interface CommandState {commandListById: Map<CommandId, Command[]>;}-export interface LabelState {- labelList: Label[];-}-export interface SQLEditorState {shouldFormatContent: boolean;queryHistoryList: QueryHistory[];diff --git a/frontend/src/utils/label.ts b/frontend/src/utils/label.tsindex 50cc9a8f32..3c0b426598 100644--- a/frontend/src/utils/label.ts+++ b/frontend/src/utils/label.ts@@ -1,52 +1,10 @@import { orderBy, uniq } from "lodash-es";import { useEnvironmentV1Store } from "@/store";import { ComposedDatabase } from "@/types";-import {- LabelSelector,- LabelSelectorRequirement,- OperatorType,- Schedule,-} from "@/types/proto/v1/project_service";import { extractEnvironmentResourceName } from "./v1";export const MAX_LABEL_VALUE_LENGTH = 63;-export const RESERVED_LABEL_KEYS = ["environment"];--export const PRESET_LABEL_KEYS = ["tenant"];--export const PRESET_DB_NAME_TEMPLATE_PLACEHOLDERS = ["DB_NAME", "TENANT"];--export const PRESET_LABEL_KEY_PLACEHOLDERS = [["TENANT", "tenant"]];--export const hidePrefix = (key: string): string => {- return key.replace(/^bb\./, "");-};--export const validateLabelsWithTemplate = (- labels: Record<string, string>,- requiredLabelDict: Set<string>-) => {- for (const key of requiredLabelDict.values()) {- const value = labels[key];- if (!value) return false;- }- return true;-};--export const parseLabelListInTemplate = (template: string): string[] => {- const labelList: string[] = [];-- PRESET_LABEL_KEY_PLACEHOLDERS.forEach(([placeholder, labelKey]) => {- const pattern = `{{${placeholder}}}`;- if (template.includes(pattern)) {- labelList.push(labelKey);- }- });-- return labelList;-};-export const validateLabelKey = (key: string) => {if (key.length === 0) return false;if (key.length >= 64) return false;@@ -57,45 +15,6 @@ export const validateLabelKey = (key: string) => {);};-export const isReservedLabel = (key: string) => {- return RESERVED_LABEL_KEYS.includes(key);-};--export const isPresetLabel = (key: string) => {- return PRESET_LABEL_KEYS.includes(key);-};--export const getAvailableLabelKeyList = (- databaseList: ComposedDatabase[],- withReserved: boolean,- withPreset: boolean,- sort = true-) => {- const keys = uniq(databaseList.flatMap((db) => Object.keys(db.labels)));- if (withReserved) {- RESERVED_LABEL_KEYS.forEach((key) => {- if (!keys.includes(key)) keys.push(key);- });- }- if (withPreset) {- PRESET_LABEL_KEYS.forEach((key) => {- if (!keys.includes(key)) keys.push(key);- });- }- if (sort) {- return orderBy(- keys,- [- (key) => (isReservedLabel(key) ? -1 : 1),- (key) => (isPresetLabel(key) ? -1 : 1),- (key) => key,- ],- ["asc", "asc", "asc"]- );- }- return keys;-};-export const convertLabelsToKVList = (labels: Record<string, string>,sort = true@@ -106,19 +25,7 @@ export const convertLabelsToKVList = (}));if (sort) {- // 1. Preset- // 2. Others (lexicographical order)- // ...- // 3. Hidden- return orderBy(- list,- [- (kv) => (isReservedLabel(kv.key) ? 1 : -1),- (kv) => (isPresetLabel(kv.key) ? -1 : 1),- (kv) => kv.key,- ],- ["asc", "asc", "asc"]- );+ return orderBy(list, (kv) => kv.key, "asc");}return list;};@@ -136,36 +43,6 @@ export const convertKVListToLabels = (return labels;};-export const displayLabelKey = (key: string) => {- if (key === "environment") {- return "Environment ID";- }-- return key;-};--export const getPipelineFromDeploymentScheduleV1 = (- databaseList: ComposedDatabase[],- schedule: Schedule | undefined-): ComposedDatabase[][] => {- const stages: ComposedDatabase[][] = [];-- const collectedIds = new Set<string>();- schedule?.deployments.forEach((deployment) => {- const dbs: ComposedDatabase[] = [];- databaseList.forEach((db) => {- if (collectedIds.has(db.uid)) return;- if (isDatabaseMatchesSelectorV1(db, deployment.spec?.labelSelector)) {- dbs.push(db);- collectedIds.add(db.uid);- }- });- stages.push(dbs);- });-- return stages;-};-export const getLabelValuesFromDatabaseV1List = (key: string,databaseList: ComposedDatabase[],@@ -195,45 +72,9 @@ export const getLabelValuesFromDatabaseV1List = (return distinctValueList;};-export const isDatabaseMatchesSelectorV1 = (- database: ComposedDatabase,- selector: LabelSelector | undefined-): boolean => {- const rules = selector?.matchExpressions ?? [];- return rules.every((rule) => {- switch (rule.operator) {- case OperatorType.OPERATOR_TYPE_IN:- return checkLabelIn(database, rule);- case OperatorType.OPERATOR_TYPE_EXISTS:- return checkLabelExists(database, rule);- default:- // unknown operators are taken as mismatch- console.warn(`known operator "${rule.operator}"`);- return false;- }- });-};-export const getSemanticLabelValue = (db: ComposedDatabase, key: string) => {if (key === "environment") {return extractEnvironmentResourceName(db.effectiveEnvironment);}return db.labels[key] ?? "";};--const checkLabelIn = (- db: ComposedDatabase,- rule: LabelSelectorRequirement-): boolean => {- const value = getSemanticLabelValue(db, rule.key);- if (!value) return false;-- return rule.values.includes(value);-};--const checkLabelExists = (- db: ComposedDatabase,- rule: LabelSelectorRequirement-): boolean => {- return !!getSemanticLabelValue(db, rule.key);-};diff --git a/frontend/src/utils/v1/deploymentConfig.ts b/frontend/src/utils/v1/deploymentConfig.tsindex 2423527a09..9574186ea5 100644--- a/frontend/src/utils/v1/deploymentConfig.ts+++ b/frontend/src/utils/v1/deploymentConfig.ts@@ -1,8 +1,16 @@+import { orderBy, uniq } from "lodash-es";+import { ComposedDatabase } from "@/types";import {DeploymentConfig,DeploymentSpec,+ LabelSelector,+ LabelSelectorRequirement,OperatorType,+ Schedule,} from "@/types/proto/v1/project_service";+import { getSemanticLabelValue } from "../label";++export const VIRTUAL_LABEL_KEYS = ["environment"];export const extractDeploymentConfigName = (name: string) => {const pattern = /(?:^|\/)deploymentConfigs\/([^/]+)(?:$|\/)/;@@ -10,6 +18,10 @@ export const extractDeploymentConfigName = (name: string) => {return matches?.[1] ?? "";};+export const isVirtualLabelKey = (key: string) => {+ return VIRTUAL_LABEL_KEYS.includes(key);+};+export const validateDeploymentConfigV1 = (config: DeploymentConfig): string | undefined => {@@ -59,3 +71,90 @@ export const validateDeploymentSpecV1 = (}return undefined;};++export const getAvailableDeploymentConfigMatchSelectorKeyList = (+ databaseList: ComposedDatabase[],+ withVirtualLabelKeys: boolean,+ sort = true+) => {+ const keys = uniq(databaseList.flatMap((db) => Object.keys(db.labels)));+ if (withVirtualLabelKeys) {+ VIRTUAL_LABEL_KEYS.forEach((key) => {+ if (!keys.includes(key)) keys.push(key);+ });+ }+ if (sort) {+ return orderBy(+ keys,+ [(key) => (isVirtualLabelKey(key) ? -1 : 1), (key) => key],+ ["asc", "asc"]+ );+ }+ return keys;+};++export const getPipelineFromDeploymentScheduleV1 = (+ databaseList: ComposedDatabase[],+ schedule: Schedule | undefined+): ComposedDatabase[][] => {+ const stages: ComposedDatabase[][] = [];++ const collectedIds = new Set<string>();+ schedule?.deployments.forEach((deployment) => {+ const dbs: ComposedDatabase[] = [];+ databaseList.forEach((db) => {+ if (collectedIds.has(db.uid)) return;+ if (isDatabaseMatchesSelectorV1(db, deployment.spec?.labelSelector)) {+ dbs.push(db);+ collectedIds.add(db.uid);+ }+ });+ stages.push(dbs);+ });++ return stages;+};++export const isDatabaseMatchesSelectorV1 = (+ database: ComposedDatabase,+ selector: LabelSelector | undefined+): boolean => {+ const rules = selector?.matchExpressions ?? [];+ return rules.every((rule) => {+ switch (rule.operator) {+ case OperatorType.OPERATOR_TYPE_IN:+ return checkLabelIn(database, rule);+ case OperatorType.OPERATOR_TYPE_EXISTS:+ return checkLabelExists(database, rule);+ default:+ // unknown operators are taken as mismatch+ console.warn(`known operator "${rule.operator}"`);+ return false;+ }+ });+};++export const displayDeploymentMatchSelectorKey = (key: string) => {+ if (key === "environment") {+ return "Environment ID";+ }++ return key;+};++const checkLabelIn = (+ db: ComposedDatabase,+ rule: LabelSelectorRequirement+): boolean => {+ const value = getSemanticLabelValue(db, rule.key);+ if (!value) return false;++ return rule.values.includes(value);+};++const checkLabelExists = (+ db: ComposedDatabase,+ rule: LabelSelectorRequirement+): boolean => {+ return !!getSemanticLabelValue(db, rule.key);+};