Skip to content

Commit

Permalink
[ACS-8914] Fix error on manage rules page open (#4228)
Browse files Browse the repository at this point in the history
* [ACS-8914] fix error on manage rules page open

* [ACS-8914] sonar issue
  • Loading branch information
nikita-web-ua authored Nov 7, 2024
1 parent 8d78a40 commit df6fdb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
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

0 comments on commit df6fdb3

Please sign in to comment.