Add isSectionTypeAvailable method and use it to check if upload section is available

This commit is contained in:
Giuseppe Digilio
2021-04-02 15:22:17 +02:00
committed by lotte
parent d3763ea642
commit 13c239cbc3
5 changed files with 136 additions and 12 deletions

View File

@@ -5,7 +5,7 @@ import { distinctUntilChanged, filter, map, take } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { ScrollToConfigOptions, ScrollToService } from '@nicky-lenaers/ngx-scroll-to';
import { isEqual } from 'lodash';
import { findKey, isEqual } from 'lodash';
import { SubmissionState } from '../submission.reducers';
import { hasValue, isEmpty, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
@@ -291,14 +291,14 @@ export class SectionsService {
}
/**
* Check if a given section is a read only available
* Check if a given section id is present in the list of sections
*
* @param submissionId
* The submission id
* @param sectionId
* The section id
* @return Observable<boolean>
* Emits true whenever a given section should be available
* Emits true whenever a given section id should be available
*/
public isSectionAvailable(submissionId: string, sectionId: string): Observable<boolean> {
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
@@ -309,6 +309,25 @@ export class SectionsService {
distinctUntilChanged());
}
/**
* Check if a given section type is present in the list of sections
*
* @param submissionId
* The submission id
* @param sectionType
* The section type
* @return Observable<boolean>
* Emits true whenever a given section type should be available
*/
public isSectionTypeAvailable(submissionId: string, sectionType: SectionsType): Observable<boolean> {
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
filter((submissionState: SubmissionObjectEntry) => isNotUndefined(submissionState)),
map((submissionState: SubmissionObjectEntry) => {
return isNotUndefined(submissionState.sections) && isNotUndefined(findKey(submissionState.sections, {sectionType: sectionType}));
}),
distinctUntilChanged());
}
/**
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it
*