[ACS-4538] Make folder-rules secondary entry point of aca-content (#3181)

* [ACS-4538] Make folder-rules secondary entry point of aca-content

* [ACA-4538] Fix folder rules imports

* [ACS-4538] Fix folder-rules unit tests

* [ACS-4538] Fix package.json after folder rules transition

* [ACS-4538] Remove duplicated peerDependency

* [ACS-4538] Import fix
This commit is contained in:
MichalKinas
2023-06-16 14:55:04 +02:00
committed by GitHub
parent 9916ecb98b
commit e0a74d7fb9
122 changed files with 111 additions and 296 deletions

View File

@@ -0,0 +1,59 @@
<div mat-dialog-title class="aca-rule-set-picker__header">
<div class="aca-rule-set-picker__header__title">
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.TITLE' | translate }}
</div>
<button mat-icon-button mat-dialog-close class="aca-rule-set-picker__header__close" tabindex="-1">
<mat-icon>close</mat-icon>
</button>
</div>
<mat-dialog-content class="aca-rule-set-picker__content">
<adf-content-node-selector-panel
class="aca-rule-set-picker__content__node-selector"
[currentFolderId]="defaultNodeId"
(select)="onNodeSelect($event)"
(folderLoaded)="setFolderLoading(false)"
(navigationChange)="setFolderLoading(true)"
(siteChange)="setFolderLoading(true)">
</adf-content-node-selector-panel>
<div class="aca-rule-set-picker__content__rule-list" [ngClass]="{ justify: rulesLoading$ | async }">
<ng-container *ngIf="rulesLoading$ | async; else rulesLoaded">
<mat-progress-spinner color="primary" mode="indeterminate"></mat-progress-spinner>
</ng-container>
<ng-template #rulesLoaded>
<ng-container *ngIf="hasOwnedRules; else noOwnedRules">
<div class="aca-rule-set-picker__content__rule-list__header">
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.LIST_OF_RULES_TO_LINK' | translate }}
</div>
<aca-rule-list-item
*ngFor="let rule of (mainRuleSet$ | async).rules"
[rule]="rule">
</aca-rule-list-item>
</ng-container>
<ng-template #noOwnedRules>
<adf-empty-content
icon="library_books"
[title]="'ACA_FOLDER_RULES.LINK_RULES_DIALOG.EMPTY_RULES_LIST.TITLE' | translate"
[subtitle]="'ACA_FOLDER_RULES.LINK_RULES_DIALOG.EMPTY_RULES_LIST.SUBTITLE' | translate">
</adf-empty-content>
</ng-template>
</ng-template>
</div>
</mat-dialog-content>
<mat-dialog-actions align="end" class="aca-rule-set-picker__footer">
<button mat-flat-button mat-dialog-close>
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.CANCEL' | translate }}
</button>
<button
mat-flat-button color="primary"
[disabled]="!hasOwnedRules || isBusy"
(click)="onSubmit()">
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.SUBMIT' | translate }}
</button>
</mat-dialog-actions>

View File

@@ -0,0 +1,76 @@
.aca-rule-set-picker-container {
--rule-set-picker-padding: 8px 20px;
.mat-dialog-container {
padding: 0;
}
}
.aca-rule-set-picker {
&__header {
display: flex;
align-items: center;
margin: 0;
padding: var(--rule-set-picker-padding);
box-sizing: border-box;
border-bottom: 1px solid var(--theme-border-color);
&__title {
font-size: 16px;
font-weight: bold;
flex-grow: 1;
}
&__close {
& mat-icon {
font-size: 18px;
}
}
}
&__content {
position: relative;
height: 80vh;
margin: 0;
padding: 0;
display: grid;
grid-template-columns: 2fr minmax(250px, 1fr);
&__node-selector {
padding: 0 20px;
box-sizing: border-box;
}
&__rule-list {
padding: 0 20px 0 0;
display: flex;
align-items: stretch;
flex-direction: column;
max-height: 100%;
overflow-y: auto;
overflow-x: hidden;
&.justify {
align-items: center;
justify-content: center;
}
&__header {
color: var(--theme-text-color);
font-size: 0.9em;
margin: 8px 0;
}
.aca-rule-list-item {
cursor: default;
}
}
}
&__footer {
margin: 0;
padding: var(--rule-set-picker-padding);
box-sizing: border-box;
border-top: 1px solid var(--theme-border-color);
}
}

View File

@@ -0,0 +1,140 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RuleSetPickerOptions, RuleSetPickerSmartComponent } from './rule-set-picker.smart-component';
import { CoreTestingModule } from '@alfresco/adf-core';
import { folderToLinkMock, otherFolderMock } from '../mock/node.mock';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
import { of } from 'rxjs';
import { ownedRuleSetMock, ruleSetWithLinkMock, ruleSetWithNoRulesToLinkMock, ruleSetWithOwnedRulesToLinkMock } from '../mock/rule-sets.mock';
import { ContentApiService } from '@alfresco/aca-shared';
import { By } from '@angular/platform-browser';
describe('RuleSetPickerSmartComponent', () => {
let fixture: ComponentFixture<RuleSetPickerSmartComponent>;
let component: RuleSetPickerSmartComponent;
let folderRuleSetsService: FolderRuleSetsService;
let loadRuleSetsSpy: jasmine.Spy;
let callApiSpy: jasmine.Spy;
const dialogRef = {
close: jasmine.createSpy('close'),
open: jasmine.createSpy('open')
};
const dialogOptions: RuleSetPickerOptions = {
nodeId: 'folder-1-id',
defaultNodeId: 'folder-1-id'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreTestingModule],
providers: [
{ provide: MatDialogRef, useValue: dialogRef },
{ provide: MAT_DIALOG_DATA, useValue: dialogOptions },
{
provide: ContentApiService,
useValue: {
getNode: () => {
return of({ entry: folderToLinkMock });
},
getNodeInfo: () => {
return of(otherFolderMock);
}
}
}
]
});
folderRuleSetsService = TestBed.inject(FolderRuleSetsService);
fixture = TestBed.createComponent(RuleSetPickerSmartComponent);
component = fixture.componentInstance;
component['folderRuleSetsService'] = folderRuleSetsService;
loadRuleSetsSpy = spyOn(folderRuleSetsService, 'loadRuleSets').and.callThrough();
callApiSpy = spyOn<any>(folderRuleSetsService, 'callApi');
callApiSpy
.withArgs(`/nodes/${dialogOptions.nodeId}/rule-sets?include=isLinkedTo,owningFolder,linkedToBy&skipCount=0&maxItems=100`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${dialogOptions.nodeId}/rule-sets/-default-?include=isLinkedTo,owningFolder,linkedToBy`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${folderToLinkMock.id}?include=path%2Cproperties%2CallowableOperations%2Cpermissions`, 'GET')
.and.returnValue(Promise.resolve({ entry: folderToLinkMock }));
});
afterEach(() => {
fixture.destroy();
});
it('should load the rule sets of a node once it has been selected', () => {
expect(loadRuleSetsSpy).not.toHaveBeenCalled();
component.onNodeSelect([folderToLinkMock]);
expect(loadRuleSetsSpy).toHaveBeenCalledWith(folderToLinkMock.id, false);
component.onNodeSelect([folderToLinkMock]);
expect(loadRuleSetsSpy).toHaveBeenCalledTimes(1);
});
it('should show an empty list message if a selected folder has no rules', () => {
component.mainRuleSet$ = of(ruleSetWithNoRulesToLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(0);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).not.toBeNull();
});
it('should show an empty list message if a selected folder has linked rules', () => {
component.mainRuleSet$ = of(ruleSetWithLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(0);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).not.toBeNull();
});
it('should show a list of items if a selected folder has owned rules', () => {
component.mainRuleSet$ = of(ruleSetWithOwnedRulesToLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(2);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).toBeNull();
});
});

View File

@@ -0,0 +1,120 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
import { Node } from '@alfresco/js-api';
import { RuleSet } from '../model/rule-set.model';
import { BehaviorSubject, combineLatest, from, of, Subject } from 'rxjs';
import { finalize, map, switchMap, takeUntil } from 'rxjs/operators';
import { NotificationService } from '@alfresco/adf-core';
export interface RuleSetPickerOptions {
nodeId: string;
defaultNodeId: string;
existingRuleSet?: RuleSet;
}
@Component({
selector: 'aca-rule-set-picker',
templateUrl: './rule-set-picker.smart-component.html',
styleUrls: ['./rule-set-picker.smart-component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'aca-rule-set-picker' },
providers: [FolderRuleSetsService]
})
export class RuleSetPickerSmartComponent implements OnInit, OnDestroy {
nodeId = '-root-';
defaultNodeId = '-root-';
isBusy = false;
existingRuleSet: RuleSet = null;
hasOwnedRules = false;
private selectedNodeId = '';
private folderLoading$ = new BehaviorSubject<boolean>(true);
mainRuleSet$ = this.folderRuleSetsService.mainRuleSet$;
rulesLoading$ = combineLatest(this.folderRuleSetsService.isLoading$, this.folderLoading$).pipe(
map(([rulesLoading, folderLoading]) => rulesLoading || folderLoading)
);
onDestroy$ = new Subject<void>();
constructor(
@Inject(MAT_DIALOG_DATA) public data: RuleSetPickerOptions,
private folderRuleSetsService: FolderRuleSetsService,
private dialogRef: MatDialogRef<RuleSetPickerSmartComponent>,
private notificationService: NotificationService
) {
this.nodeId = this.data?.nodeId ?? '-root-';
this.defaultNodeId = this.data?.defaultNodeId ?? '-root-';
this.existingRuleSet = this.data?.existingRuleSet ?? null;
}
ngOnInit(): void {
this.mainRuleSet$.pipe(takeUntil(this.onDestroy$)).subscribe((mainRuleSet) => {
this.hasOwnedRules = mainRuleSet?.rules.length > 0 && FolderRuleSetsService.isOwnedRuleSet(mainRuleSet, this.selectedNodeId);
});
}
ngOnDestroy(): void {
this.onDestroy$.next();
this.onDestroy$.complete();
}
onNodeSelect(nodes: Node[]) {
if (nodes?.length && nodes[0].isFolder && nodes[0].id !== this.selectedNodeId) {
this.selectedNodeId = nodes[0].id;
this.folderRuleSetsService.loadRuleSets(this.selectedNodeId, false);
}
}
setFolderLoading(isLoading: boolean) {
this.folderLoading$.next(isLoading);
}
onSubmit() {
this.isBusy = true;
from(this.existingRuleSet ? this.folderRuleSetsService.deleteRuleSetLink(this.nodeId, this.existingRuleSet.id) : of(null))
.pipe(
switchMap(() => from(this.folderRuleSetsService.createRuleSetLink(this.nodeId, this.selectedNodeId))),
finalize(() => {
this.isBusy = false;
})
)
.subscribe(
() => {
this.dialogRef.close(true);
},
() => {
this.handleError();
}
);
}
private handleError() {
this.notificationService.showError('ACA_FOLDER_RULES.LINK_RULES_DIALOG.ERRORS.REQUEST_FAILED');
}
}