[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,11 +205,23 @@ 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);
return this.createCardViewItemByType(paramDef, cardViewPropertiesModel, constraintsForDropdownBox, disabledTags, disabledCategories);
});
}
private getConstraintsForParameter(
paramDef: ActionParameterDefinition,
securityMarkOptions?: CardViewSelectItemOption<string>[]
): ActionParameterConstraint | { name: string; constraints: CardViewSelectItemOption<string>[] } | undefined {
return paramDef.name === 'securityMarkId'
? { name: paramDef.name, constraints: securityMarkOptions || [] } ? { name: paramDef.name, constraints: securityMarkOptions || [] }
: this._parameterConstraints.find((obj) => obj.name === paramDef.name); : this._parameterConstraints.find((obj) => obj.name === paramDef.name);
const cardViewPropertiesModel = { }
private buildBaseCardViewModel(paramDef: ActionParameterDefinition) {
return {
label: paramDef.displayLabel + (paramDef.mandatory ? ' *' : ''), label: paramDef.displayLabel + (paramDef.mandatory ? ' *' : ''),
key: paramDef.name, key: paramDef.name,
editable: true, editable: true,
@@ -225,14 +237,23 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
} }
: {}) : {})
}; };
switch (paramDef.type) { }
case 'd:boolean':
private createCardViewItemByType(
paramDef: ActionParameterDefinition,
cardViewPropertiesModel: any,
constraintsForDropdownBox: any,
disabledTags: boolean,
disabledCategories: boolean
): CardViewItem {
if (paramDef.type === 'd:boolean') {
return new CardViewBoolItemModel({ return new CardViewBoolItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
value: this.parameters[paramDef.name] ?? false value: this.parameters[paramDef.name] ?? false
}); });
case 'd:noderef': }
if (!constraintsForDropdownBox && !this.readOnly && paramDef.name !== 'category-value') {
if (paramDef.type === 'd:noderef' && !constraintsForDropdownBox && !this.readOnly && paramDef.name !== 'category-value') {
return new CardViewTextItemModel({ return new CardViewTextItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
icon: 'folder', icon: 'folder',
@@ -241,7 +262,9 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
clickCallBack: this.openSelectorDialog.bind(this, paramDef.name), clickCallBack: this.openSelectorDialog.bind(this, paramDef.name),
value: this.parameters[paramDef.name] value: this.parameters[paramDef.name]
}); });
} else if (paramDef.name === 'category-value' && !this.readOnly) { }
if (paramDef.type === 'd:noderef' && paramDef.name === 'category-value' && !this.readOnly) {
return new CardViewTextItemModel({ return new CardViewTextItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
icon: 'library_add', icon: 'library_add',
@@ -251,33 +274,33 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
value: this.parameters[paramDef.name] value: this.parameters[paramDef.name]
}); });
} }
// falls through
default:
if (constraintsForDropdownBox) { if (constraintsForDropdownBox) {
return new CardViewSelectItemModel({ return new CardViewSelectItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
value: (this.parameters[paramDef.name] as string) ?? '', value: this.parameters[paramDef.name] ?? (paramDef.multiValued ? [''] : ''),
options$: of(constraintsForDropdownBox.constraints).pipe( options$: of(constraintsForDropdownBox.constraints).pipe(
map((options) => { map((options) =>
return options.filter( options.filter(
(option) => (option) =>
!( !(
(disabledTags && this.tagsRelatedPropertiesAndAspects.includes(option.key)) || (disabledTags && this.tagsRelatedPropertiesAndAspects.includes(option.key)) ||
(disabledCategories && this.categoriesRelatedPropertiesAndAspects.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({ return new CardViewTextItemModel({
...cardViewPropertiesModel, ...cardViewPropertiesModel,
value: value: formattedValue
constraintsForDropdownBox && this.readOnly && this.paramsToFormatDisplayedValue.includes(paramDef.name)
? (constraintsForDropdownBox.constraints.find((constraint) => constraint.key === this.parameters[paramDef.name])?.label ?? '')
: (this.parameters[paramDef.name] ?? '')
});
}
}); });
} }