diff --git a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.spec.ts b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.spec.ts index 623237606..d9b98ee46 100644 --- a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.spec.ts +++ b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.spec.ts @@ -30,6 +30,7 @@ import { By } from '@angular/platform-browser'; import { dummyCategoriesConstraints, dummyConstraints, dummyTagsConstraints } from '../../mock/action-parameter-constraints.mock'; import { CategoryService, TagService } from '@alfresco/adf-content-services'; import { MatSelect } from '@angular/material/select'; +import { MatDialog } from '@angular/material/dialog'; describe('RuleActionUiComponent', () => { let fixture: ComponentFixture; @@ -124,11 +125,25 @@ describe('RuleActionUiComponent', () => { const cardView = getPropertiesCardView(); expect(cardView.properties.length).toBe(1); - expect(cardView.properties[0].icon).toBeFalsy(); + expect(cardView.properties[0].icon).toBe('library_add'); expect(cardView.properties[0].value).toBeFalsy(); expect(cardView.properties[0]).toBeInstanceOf(CardViewTextItemModel); }); + it('should open category selector dialog on category-value action parameter clicked', () => { + const dialog = fixture.debugElement.injector.get(MatDialog); + component.actionDefinitions = [actionLinkToCategoryTransformedMock]; + component.parameterConstraints = dummyConstraints; + spyOn(dialog, 'open'); + fixture.detectChanges(); + + changeMatSelectValue('mock-action-3-definition'); + fixture.debugElement.query(By.css('.adf-textitem-action')).nativeElement.click(); + + expect(dialog.open).toHaveBeenCalledTimes(1); + expect(dialog.open['calls'].argsFor(0)[0].name).toBe('CategorySelectorDialogComponent'); + }); + describe('Select options', () => { beforeEach(() => { component.actionDefinitions = actionsTransformedListMock; diff --git a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts index d490c6e6a..6d15eebbc 100644 --- a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts +++ b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts @@ -35,7 +35,7 @@ import { CardViewUpdateService, UpdateNotification } from '@alfresco/adf-core'; -import { ActionParameterDefinition, Node } from '@alfresco/js-api'; +import { ActionParameterDefinition, Category, Node } from '@alfresco/js-api'; import { of, Subject } from 'rxjs'; import { map, takeUntil } from 'rxjs/operators'; import { ActionParameterConstraint, ConstraintValue } from '../../model/action-parameter-constraint.model'; @@ -44,7 +44,9 @@ import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction, - TagService + TagService, + CategorySelectorDialogComponent, + CategorySelectorDialogOptions } from '@alfresco/adf-content-services'; import { MatDialog } from '@angular/material/dialog'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; @@ -220,6 +222,15 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh 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: @@ -288,6 +299,35 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh ); } + private openCatDialog(paramDefName) { + const data: CategorySelectorDialogOptions = { + select: new Subject(), + multiSelect: false + }; + + this.dialog.open(CategorySelectorDialogComponent, { + data, + width: '630px' + }); + + data.select.pipe(takeUntil(this.onDestroy$)).subscribe((selections: Category[]) => { + if (selections[0].id) { + this.writeValue({ + actionDefinitionId: this.selectedActionDefinitionId, + params: { + ...this.parameters, + [paramDefName]: selections[0].id + } + }); + this.onChange({ + actionDefinitionId: this.selectedActionDefinitionId, + params: this.parameters + }); + this.onTouch(); + } + }); + } + setDefaultParameters() { this.parameters = {}; (this.selectedActionDefinition?.parameterDefinitions ?? []).forEach((paramDef: ActionParameterDefinition) => {