Fix hardcoded submission section IDs

This commit is contained in:
Yura Bondarenko
2021-06-18 11:57:36 +02:00
parent 0ee451f3d3
commit 32003a72fd
4 changed files with 29 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ import { CollectionDataService } from '../../../core/data/collection-data.servic
import { CollectionDropdownComponent } from '../../../shared/collection-dropdown/collection-dropdown.component'; import { CollectionDropdownComponent } from '../../../shared/collection-dropdown/collection-dropdown.component';
import { SectionsService } from '../../sections/sections.service'; import { SectionsService } from '../../sections/sections.service';
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
import { SectionsType } from '../../sections/sections-type';
/** /**
* This component allows to show the current collection the submission belonging to and to change it. * This component allows to show the current collection the submission belonging to and to change it.
@@ -142,7 +143,7 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
*/ */
ngOnInit() { ngOnInit() {
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', 'collection'); this.pathCombiner = new JsonPatchOperationPathCombiner('sections', 'collection');
this.available$ = this.sectionsService.isSectionAvailable(this.submissionId, 'collection'); this.available$ = this.sectionsService.isSectionTypeAvailable(this.submissionId, SectionsType.collection);
} }
/** /**

View File

@@ -3,7 +3,6 @@
<div *ngIf="(uploadEnabled$ | async)" class="w-100"> <div *ngIf="(uploadEnabled$ | async)" class="w-100">
<ds-submission-upload-files [submissionId]="submissionId" <ds-submission-upload-files [submissionId]="submissionId"
[collectionId]="collectionId" [collectionId]="collectionId"
[sectionId]="'upload'"
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files> [uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>

View File

@@ -13,6 +13,7 @@ import { UploaderOptions } from '../../../shared/uploader/uploader-options.model
import parseSectionErrors from '../../utils/parseSectionErrors'; import parseSectionErrors from '../../utils/parseSectionErrors';
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service'; import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model'; import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
import { SectionsType } from '../../sections/sections-type';
/** /**
* This component represents the drop zone that provides to add files to the submission. * This component represents the drop zone that provides to add files to the submission.
@@ -35,12 +36,6 @@ export class SubmissionUploadFilesComponent implements OnChanges {
*/ */
@Input() submissionId: string; @Input() submissionId: string;
/**
* The upload section id
* @type {string}
*/
@Input() sectionId: string;
/** /**
* The uploader configuration options * The uploader configuration options
* @type {UploaderOptions} * @type {UploaderOptions}
@@ -110,7 +105,7 @@ export class SubmissionUploadFilesComponent implements OnChanges {
* Check if upload functionality is enabled * Check if upload functionality is enabled
*/ */
ngOnChanges() { ngOnChanges() {
this.uploadEnabled = this.sectionService.isSectionAvailable(this.submissionId, this.sectionId); this.uploadEnabled = this.sectionService.isSectionTypeAvailable(this.submissionId, SectionsType.Upload);
} }
/** /**
@@ -136,14 +131,16 @@ export class SubmissionUploadFilesComponent implements OnChanges {
.forEach((sectionId) => { .forEach((sectionId) => {
const sectionData = normalizeSectionData(sections[sectionId]); const sectionData = normalizeSectionData(sections[sectionId]);
const sectionErrors = errorsList[sectionId]; const sectionErrors = errorsList[sectionId];
if (sectionId === 'upload') { this.sectionService.isSectionType(this.submissionId, sectionId, SectionsType.Upload).subscribe((isUpload) => {
// Look for errors on upload if (isUpload) {
if ((isEmpty(sectionErrors))) { // Look for errors on upload
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful')); if ((isEmpty(sectionErrors))) {
} else { this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed')); } else {
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
}
} }
} });
this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors); this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors);
}); });
} }

View File

@@ -328,6 +328,22 @@ export class SectionsService {
distinctUntilChanged()); distinctUntilChanged());
} }
/**
* Check if given section id is of a given section type
* @param submissionId
* @param sectionId
* @param sectionType
*/
public isSectionType(submissionId: string, sectionId: 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(submissionState.sections[sectionId]
&& submissionState.sections[sectionId].sectionType === sectionType );
}),
distinctUntilChanged());
}
/** /**
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it * Dispatch a new [EnableSectionAction] to add a new section and move page target to it
* *