[MNT-25149] Adapt rule property to multivalue scenario (#5191)

* [MNT-25149] Adapt rule property to multivalue scenario

* [MNT-25149] CR fix

* [MNT-25149] CR fixes
This commit is contained in:
Michal Kinas
2026-05-29 13:46:51 +02:00
committed by GitHub
parent e94dd3f50c
commit a23d808e92
@@ -205,79 +205,102 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
const disabledTags = !this.tagService.areTagsEnabled(); const disabledTags = !this.tagService.areTagsEnabled();
const disabledCategories = !this.categoryService.areCategoriesEnabled(); const disabledCategories = !this.categoryService.areCategoriesEnabled();
this.cardViewItems = (this.selectedActionDefinition?.parameterDefinitions ?? []).map((paramDef) => { this.cardViewItems = (this.selectedActionDefinition?.parameterDefinitions ?? []).map((paramDef) => {
const constraintsForDropdownBox = const constraintsForDropdownBox = this.getConstraintsForParameter(paramDef, securityMarkOptions);
paramDef.name === 'securityMarkId' const cardViewPropertiesModel = this.buildBaseCardViewModel(paramDef);
? { name: paramDef.name, constraints: securityMarkOptions || [] } return this.createCardViewItemByType(paramDef, cardViewPropertiesModel, constraintsForDropdownBox, disabledTags, disabledCategories);
: this._parameterConstraints.find((obj) => obj.name === paramDef.name); });
const cardViewPropertiesModel = { }
label: paramDef.displayLabel + (paramDef.mandatory ? ' *' : ''),
key: paramDef.name, private getConstraintsForParameter(
editable: true, paramDef: ActionParameterDefinition,
multivalued: paramDef.multiValued, securityMarkOptions?: CardViewSelectItemOption<string>[]
...(paramDef.mandatory ): ActionParameterConstraint | { name: string; constraints: CardViewSelectItemOption<string>[] } | undefined {
? { return paramDef.name === 'securityMarkId'
validators: [ ? { name: paramDef.name, constraints: securityMarkOptions || [] }
{ : this._parameterConstraints.find((obj) => obj.name === paramDef.name);
message: 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.REQUIRED', }
isValid: (value: unknown) => !!value
} private buildBaseCardViewModel(paramDef: ActionParameterDefinition) {
] return {
} label: paramDef.displayLabel + (paramDef.mandatory ? ' *' : ''),
: {}) key: paramDef.name,
}; editable: true,
switch (paramDef.type) { multivalued: paramDef.multiValued,
case 'd:boolean': ...(paramDef.mandatory
return new CardViewBoolItemModel({ ? {
...cardViewPropertiesModel, validators: [
value: this.parameters[paramDef.name] ?? false {
}); message: 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.REQUIRED',
case 'd:noderef': isValid: (value: unknown) => !!value
if (!constraintsForDropdownBox && !this.readOnly && paramDef.name !== 'category-value') { }
return new CardViewTextItemModel({ ]
...cardViewPropertiesModel,
icon: 'folder',
default: '',
clickable: true,
clickCallBack: this.openSelectorDialog.bind(this, paramDef.name),
value: this.parameters[paramDef.name]
});
} else if (paramDef.name === 'category-value' && !this.readOnly) {
return new CardViewTextItemModel({
...cardViewPropertiesModel,
icon: 'library_add',
default: '',
clickable: true,
clickCallBack: this.openCatDialog.bind(this, paramDef.name),
value: this.parameters[paramDef.name]
});
} }
// falls through : {})
default: };
if (constraintsForDropdownBox) { }
return new CardViewSelectItemModel({
...cardViewPropertiesModel, private createCardViewItemByType(
value: (this.parameters[paramDef.name] as string) ?? '', paramDef: ActionParameterDefinition,
options$: of(constraintsForDropdownBox.constraints).pipe( cardViewPropertiesModel: any,
map((options) => { constraintsForDropdownBox: any,
return options.filter( disabledTags: boolean,
(option) => disabledCategories: boolean
!( ): CardViewItem {
(disabledTags && this.tagsRelatedPropertiesAndAspects.includes(option.key)) || if (paramDef.type === 'd:boolean') {
(disabledCategories && this.categoriesRelatedPropertiesAndAspects.includes(option.key)) return new CardViewBoolItemModel({
) ...cardViewPropertiesModel,
); value: this.parameters[paramDef.name] ?? false
}) });
) }
});
} if (paramDef.type === 'd:noderef' && !constraintsForDropdownBox && !this.readOnly && paramDef.name !== 'category-value') {
return new CardViewTextItemModel({ return new CardViewTextItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
value: icon: 'folder',
constraintsForDropdownBox && this.readOnly && this.paramsToFormatDisplayedValue.includes(paramDef.name) default: '',
? (constraintsForDropdownBox.constraints.find((constraint) => constraint.key === this.parameters[paramDef.name])?.label ?? '') clickable: true,
: (this.parameters[paramDef.name] ?? '') clickCallBack: this.openSelectorDialog.bind(this, paramDef.name),
}); value: this.parameters[paramDef.name]
} });
}
if (paramDef.type === 'd:noderef' && paramDef.name === 'category-value' && !this.readOnly) {
return new CardViewTextItemModel({
...cardViewPropertiesModel,
icon: 'library_add',
default: '',
clickable: true,
clickCallBack: this.openCatDialog.bind(this, paramDef.name),
value: this.parameters[paramDef.name]
});
}
if (constraintsForDropdownBox) {
return new CardViewSelectItemModel({
...cardViewPropertiesModel,
value: this.parameters[paramDef.name] ?? (paramDef.multiValued ? [''] : ''),
options$: of(constraintsForDropdownBox.constraints).pipe(
map((options) =>
options.filter(
(option) =>
!(
(disabledTags && this.tagsRelatedPropertiesAndAspects.includes(option.key)) ||
(disabledCategories && this.categoriesRelatedPropertiesAndAspects.includes(option.key))
)
)
)
)
});
}
const shouldFormatValue = constraintsForDropdownBox && this.readOnly && this.paramsToFormatDisplayedValue.includes(paramDef.name);
const formattedValue = shouldFormatValue
? (constraintsForDropdownBox.constraints.find((constraint) => constraint.key === this.parameters[paramDef.name])?.label ?? '')
: (this.parameters[paramDef.name] ?? '');
return new CardViewTextItemModel({
...cardViewPropertiesModel,
value: formattedValue
}); });
} }