Skip to content

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

chore: optimize resource selector in expr editor (#15298)

ecmadaoc7bbc516db1a
diff --git a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
index ddcd0a3662..fbed83257f 100644
--- a/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
+++ b/frontend/src/components/CustomApproval/Settings/components/common/utils.ts
@@ -1,5 +1,7 @@
import { uniq, without } from "lodash-es";
+import { CheckIcon } from "lucide-vue-next";
import type { SelectOption } from "naive-ui";
+import { h, type VNode } from "vue";
import { type Factor, SQLTypeList } from "@/plugins/cel";
import { t } from "@/plugins/i18n";
import { useEnvironmentV1Store, useProjectV1List } from "@/store";
@@ -166,26 +168,51 @@ export const getFactorList = (source: Risk_Source) => {
return RiskSourceFactorMap.get(source) ?? [];
};
-const getEnvironmentIdOptions = () => {
+export const getRenderOptionFunc = (resource: {
+ title: string;
+ name: string;
+}): ((info: { node: VNode; selected: boolean }) => VNode) => {
+ return (info: { node: VNode; selected: boolean }) => {
+ return h(
+ info.node,
+ { class: "flex items-center justify-between space-x-4" },
+ [
+ h("div", { class: "flex flex-col px-1 py-1 z-10" }, [
+ h(
+ "div",
+ { class: `textlabel ${info.selected ? "!text-accent" : ""}` },
+ resource.title
+ ),
+ h("div", { class: "opacity-60 textinfolabel" }, resource.name),
+ ]),
+ info.selected ? h(CheckIcon, { class: "w-4 z-10" }) : undefined,
+ ]
+ );
+ };
+};
+
+export const getEnvironmentIdOptions = () => {
const environmentList = useEnvironmentV1Store().getEnvironmentList();
return environmentList.map<SelectOption>((env) => {
- const environmentName = extractEnvironmentResourceName(env.name);
+ const environmentId = extractEnvironmentResourceName(env.name);
return {
- label: environmentName,
- value: environmentName,
+ label: `${env.title} (${environmentId})`,
+ value: environmentId,
+ render: getRenderOptionFunc(env),
};
});
};
-const getProjectIdOptions = () => {
+export const getProjectIdOptions = () => {
const { projectList } = useProjectV1List();
return projectList.value
.filter((proj) => proj.name != DEFAULT_PROJECT_NAME)
.map<SelectOption>((proj) => {
const projectId = extractProjectResourceName(proj.name);
return {
- label: `${projectId} (${proj.title})`,
+ label: `${proj.title} (${projectId})`,
value: projectId,
+ render: getRenderOptionFunc(proj),
};
});
};
diff --git a/frontend/src/components/ExprEditor/components/MultiSelect.vue b/frontend/src/components/ExprEditor/components/MultiSelect.vue
index 0669e03488..e98db018ef 100644
--- a/frontend/src/components/ExprEditor/components/MultiSelect.vue
+++ b/frontend/src/components/ExprEditor/components/MultiSelect.vue
@@ -8,10 +8,7 @@
:disabled="!allowAdmin"
max-tag-count="responsive"
size="small"
- style="min-width: 12rem; width: auto; overflow-x: hidden"
- :menu-props="{
- style: 'width: 14rem',
- }"
+ style="min-width: 12rem; width: auto; max-width: 20rem; overflow-x: hidden"
@update:value="$emit('update:value', $event)"
>
<template #action>
diff --git a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
index 337ba1eb51..a0eec47122 100644
--- a/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
+++ b/frontend/src/components/SensitiveData/GlobalMaskingRulesView.vue
@@ -120,9 +120,18 @@ import { NButton, type SelectOption } from "naive-ui";
import { v4 as uuidv4 } from "uuid";
import { computed, reactive, nextTick, onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
+import {
+ getEnvironmentIdOptions,
+ getProjectIdOptions,
+} from "@/components/CustomApproval/Settings/components/common";
import { useBodyLayoutContext } from "@/layouts/common";
import type { Factor } from "@/plugins/cel";
-import { featureToRef, pushNotification, usePolicyV1Store } from "@/store";
+import {
+ featureToRef,
+ pushNotification,
+ usePolicyV1Store,
+ useInstanceV1List,
+} from "@/store";
import type { Policy } from "@/types/proto/v1/org_policy_service";
import {
PolicyType,
@@ -136,9 +145,7 @@ import { MiniActionButton } from "../v2";
import MaskingRuleConfig from "./components/MaskingRuleConfig.vue";
import {
getClassificationLevelOptions,
- getEnvironmentIdOptions,
getInstanceIdOptions,
- getProjectIdOptions,
} from "./components/utils";
type MaskingRuleMode = "NORMAL" | "EDIT" | "CREATE";
@@ -163,6 +170,7 @@ const state = reactive<LocalState>({
reorderRules: false,
});
+useInstanceV1List();
const policyStore = usePolicyV1Store();
const hasPermission = computed(() => {
return hasWorkspacePermissionV2("bb.policies.update");
diff --git a/frontend/src/components/SensitiveData/components/utils.ts b/frontend/src/components/SensitiveData/components/utils.ts
index 0f893c6296..bfa17c902e 100644
--- a/frontend/src/components/SensitiveData/components/utils.ts
+++ b/frontend/src/components/SensitiveData/components/utils.ts
@@ -1,20 +1,11 @@
import { uniq } from "lodash-es";
import type { SelectOption } from "naive-ui";
+import { getRenderOptionFunc } from "@/components/CustomApproval/Settings/components/common";
import type { Factor, Operator } from "@/plugins/cel";
import { EqualityOperatorList, CollectionOperatorList } from "@/plugins/cel";
-import {
- useInstanceResourceList,
- useEnvironmentV1Store,
- useProjectV1List,
- useSettingV1Store,
-} from "@/store";
-import { DEFAULT_PROJECT_NAME } from "@/types";
+import { useInstanceResourceList, useSettingV1Store } from "@/store";
import type { Algorithm } from "@/types/proto/v1/setting_service";
-import {
- extractEnvironmentResourceName,
- extractInstanceResourceName,
- extractProjectResourceName,
-} from "@/utils";
+import { extractInstanceResourceName } from "@/utils";
export const getClassificationLevelOptions = () => {
const settingStore = useSettingV1Store();
@@ -35,41 +26,18 @@ export const getClassificationLevelOptions = () => {
}));
};
-export const getEnvironmentIdOptions = () => {
- const environmentList = useEnvironmentV1Store().getEnvironmentList();
- return environmentList.map<SelectOption>((env) => {
- const environmentName = extractEnvironmentResourceName(env.name);
- return {
- label: environmentName,
- value: environmentName,
- };
- });
-};
-
export const getInstanceIdOptions = () => {
const instanceList = useInstanceResourceList();
return instanceList.value.map<SelectOption>((ins) => {
const instanceId = extractInstanceResourceName(ins.name);
return {
- label: instanceId,
+ label: `${ins.title} (${instanceId})`,
value: instanceId,
+ render: getRenderOptionFunc(ins),
};
});
};
-export const getProjectIdOptions = () => {
- const { projectList } = useProjectV1List();
- return projectList.value
- .filter((proj) => proj.name != DEFAULT_PROJECT_NAME)
- .map<SelectOption>((proj) => {
- const projectId = extractProjectResourceName(proj.name);
- return {
- label: `${projectId} (${proj.title})`,
- value: projectId,
- };
- });
-};
-
export const factorSupportDropdown: Factor[] = [
"environment_id",
"instance_id",