diff --git a/libs/cmdb-instances/src/instance-list-table/AdvancedSearch.tsx b/libs/cmdb-instances/src/instance-list-table/AdvancedSearch.tsx index d8fa4a449..51d3ae49e 100644 --- a/libs/cmdb-instances/src/instance-list-table/AdvancedSearch.tsx +++ b/libs/cmdb-instances/src/instance-list-table/AdvancedSearch.tsx @@ -957,7 +957,8 @@ export class AdvancedSearchForm extends React.Component< if (multiValueSearchOperator) { let values: any[]; if ( - field.attrValue.type === ModelAttributeValueType.ENUM || + (field.attrValue.type === ModelAttributeValueType.ENUM && + (field.attrValue.mode as any) !== "cascade") || field.attrValue.type === ModelAttributeValueType.ARR ) { values = value; diff --git a/libs/cmdb-instances/src/model-attribute-form-control/ModelAttributeFormControl.tsx b/libs/cmdb-instances/src/model-attribute-form-control/ModelAttributeFormControl.tsx index 0bbe9939e..92efd24e1 100644 --- a/libs/cmdb-instances/src/model-attribute-form-control/ModelAttributeFormControl.tsx +++ b/libs/cmdb-instances/src/model-attribute-form-control/ModelAttributeFormControl.tsx @@ -272,6 +272,12 @@ export class ModelAttributeFormControl extends Component< ) { return FormControlTypeEnum.RADIO; } + if ( + getRuntime().getFeatureFlags()["cmdb-use-tree-enum-attr"] && + (attribute.value.mode as any) === ModelAttributeValueModeType.CASCADE + ) { + return FormControlTypeEnum.TREESELECT; + } return FormControlTypeEnum.SELECT; case ModelAttributeValueType.INTEGER: case ModelAttributeValueType.FLOAT: @@ -707,7 +713,13 @@ export class ModelAttributeFormControl extends Component< const { readOnly, placeholder } = restProps; const newValue = typeof value === "boolean" ? value : value ? value : []; - const treeData: any = treeEnumFormat(attribute.value.regex || []); + const isMultiple = + attribute.value.type === "enums" && + (attribute.value.mode as any) === "cascade"; + const treeData: any = treeEnumFormat( + attribute.value.regex || [], + isMultiple + ); return ( this.onChange(e)} /> ); diff --git a/libs/cmdb-utils/src/cmdbUtil.spec.ts b/libs/cmdb-utils/src/cmdbUtil.spec.ts index f29f3a2d2..8ef23578a 100644 --- a/libs/cmdb-utils/src/cmdbUtil.spec.ts +++ b/libs/cmdb-utils/src/cmdbUtil.spec.ts @@ -595,7 +595,7 @@ describe("util", () => { describe("treeEnumFormat", () => { const value = ["A1/B1/C1", "A1/B1", "A1/B1/C2", "A1"]; it("treeEnumFormat", () => { - const result = treeEnumFormat(value); + const result = treeEnumFormat(value, true); expect(result).toEqual([ { children: [ @@ -606,6 +606,7 @@ describe("treeEnumFormat", () => { id: "A1/B1/C1", isLeaf: true, parentId: "A1/B1", + selectable: true, title: "C1", value: "A1/B1/C1", }, @@ -614,6 +615,7 @@ describe("treeEnumFormat", () => { id: "A1/B1/C2", isLeaf: true, parentId: "A1/B1", + selectable: true, title: "C2", value: "A1/B1/C2", }, @@ -621,6 +623,7 @@ describe("treeEnumFormat", () => { id: "A1/B1", isLeaf: false, parentId: "A1", + selectable: true, title: "B1", value: "A1/B1", }, @@ -628,11 +631,12 @@ describe("treeEnumFormat", () => { id: "A1", isLeaf: false, parentId: "", + selectable: true, title: "A1", value: "A1", }, ]); - const result2 = treeEnumFormat("A1/B1/C1\nA1/B1\nA1/B1/C2\nA1"); + const result2 = treeEnumFormat("A1/B1/C1\nA1/B1\nA1/B1/C2\nA1", true); expect(result2).toEqual([ { children: [ @@ -643,6 +647,7 @@ describe("treeEnumFormat", () => { id: "A1/B1/C1", isLeaf: true, parentId: "A1/B1", + selectable: true, title: "C1", value: "A1/B1/C1", }, @@ -651,6 +656,7 @@ describe("treeEnumFormat", () => { id: "A1/B1/C2", isLeaf: true, parentId: "A1/B1", + selectable: true, title: "C2", value: "A1/B1/C2", }, @@ -658,6 +664,7 @@ describe("treeEnumFormat", () => { id: "A1/B1", isLeaf: false, parentId: "A1", + selectable: true, title: "B1", value: "A1/B1", }, @@ -665,28 +672,28 @@ describe("treeEnumFormat", () => { id: "A1", isLeaf: false, parentId: "", + selectable: true, title: "A1", value: "A1", }, ]); - const result3 = treeEnumFormat([ - "A1/B1/C1", - "A1/B1", - "A1/B1/C", - "A1/B1/C23", - "A1", - ]); + const result3 = treeEnumFormat( + ["A1/B1/C1", "A1/B1", "A1/B1/C", "A1/B1/C23", "A1"], + true + ); expect(result3).toEqual([ { id: "A1", parentId: "", + selectable: true, title: "A1", value: "A1", children: [ { id: "A1/B1", parentId: "A1", + selectable: true, title: "B1", value: "A1/B1", children: [ @@ -695,6 +702,7 @@ describe("treeEnumFormat", () => { parentId: "A1/B1", title: "C", value: "A1/B1/C", + selectable: true, children: null, isLeaf: true, }, @@ -703,6 +711,7 @@ describe("treeEnumFormat", () => { parentId: "A1/B1", title: "C1", value: "A1/B1/C1", + selectable: true, children: null, isLeaf: true, }, @@ -711,6 +720,7 @@ describe("treeEnumFormat", () => { parentId: "A1/B1", title: "C23", value: "A1/B1/C23", + selectable: true, children: null, isLeaf: true, }, diff --git a/libs/cmdb-utils/src/cmdbUtil.ts b/libs/cmdb-utils/src/cmdbUtil.ts index 9263e3fee..552f5617f 100644 --- a/libs/cmdb-utils/src/cmdbUtil.ts +++ b/libs/cmdb-utils/src/cmdbUtil.ts @@ -342,6 +342,7 @@ export function getFixedStyle( interface TreeItem { title: string; value: string; + selectable?: boolean; isLeaf?: boolean; parentId?: string; key?: string; @@ -349,7 +350,10 @@ interface TreeItem { children?: TreeItem[]; } -export function treeEnumFormat(value: string | string[]): TreeItem[] { +export function treeEnumFormat( + value: string | string[], + isMultiple = true +): TreeItem[] { const root: TreeItem[] = []; const arr = _.compact( _.uniq((_.isString(value) ? value?.split("\n") : value) || []) @@ -373,8 +377,10 @@ export function treeEnumFormat(value: string | string[]): TreeItem[] { } if (index === parts.length - 1) { + existingNode.selectable = true; existingNode.isLeaf = true; } else { + existingNode.selectable = isMultiple; existingNode.isLeaf = false; } @@ -395,6 +401,7 @@ export function treeEnumFormat(value: string | string[]): TreeItem[] { root.forEach((node) => { if (node.children?.length === 0) { + node.selectable = true; node.isLeaf = true; } else { node.isLeaf = false;