Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-8914] Fix error on manage rules page open #4228

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('FolderRuleSetsService', () => {
.and.returnValue(of(getOtherFolderEntryMock));
});

it('should have an initial value of null for selectedRuleSet$', async () => {
const selectedRuleSetPromise = folderRuleSetsService.selectedRuleSet$.pipe(take(1)).toPromise();
const selectedRuleSet = await selectedRuleSetPromise;
expect(selectedRuleSet).toBeNull();
});

it(`should load node info when loading the node's rule sets`, async () => {
// take(2), because: 1 = init of the BehaviourSubject, 2 = in subscribe
const folderInfoPromise = folderRuleSetsService.folderInfo$.pipe(take(2)).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { Injectable } from '@angular/core';
import { AlfrescoApiService } from '@alfresco/adf-content-services';
import { BehaviorSubject, combineLatest, from, Observable, of } from 'rxjs';
import { BehaviorSubject, combineLatest, from, Observable, of, startWith } from 'rxjs';
import { NodeInfo } from '@alfresco/aca-shared/store';
import { catchError, finalize, map, switchMap, tap } from 'rxjs/operators';
import { RuleSet } from '../model/rule-set.model';
Expand Down Expand Up @@ -68,20 +68,26 @@ export class FolderRuleSetsService {
hasMoreRuleSets$: Observable<boolean> = this.hasMoreRuleSetsSource.asObservable();
folderInfo$: Observable<NodeInfo> = this.folderInfoSource.asObservable();
isLoading$: Observable<boolean> = this.isLoadingSource.asObservable();
selectedRuleSet$: Observable<RuleSet>;

selectedRuleSet$ = this.folderRulesService.selectedRule$.pipe(
map((rule: Rule) => {
if (rule === null) {
return null;
}
if (this.mainRuleSet?.rules.findIndex((r: Rule) => r.id === rule.id) > -1) {
return this.mainRuleSet;
}
return this.inheritedRuleSets.find((ruleSet: RuleSet) => ruleSet.rules.findIndex((r: Rule) => r.id === rule.id) > -1) ?? null;
})
);

constructor(private apiService: AlfrescoApiService, private contentApi: ContentApiService, private folderRulesService: FolderRulesService) {}
constructor(
private readonly apiService: AlfrescoApiService,
private readonly contentApi: ContentApiService,
private readonly folderRulesService: FolderRulesService
) {
this.selectedRuleSet$ = this.folderRulesService.selectedRule$.pipe(
startWith(null),
map((rule: Rule) => {
if (rule === null) {
return null;
}
if (this.mainRuleSet?.rules.findIndex((r: Rule) => r.id === rule.id) > -1) {
return this.mainRuleSet;
}
return this.inheritedRuleSets.find((ruleSet: RuleSet) => ruleSet.rules.findIndex((r: Rule) => r.id === rule.id) > -1) ?? null;
})
);
}

private callApi(path: string, httpMethod: string, body: object = {}): Promise<any> {
// APIs used by this service are still private and not yet available for public use
Expand Down
Loading