Merge pull request #2243 from 4Science/DURACOM-145

Handled collection step visibility on a submission form
This commit is contained in:
Tim Donohue
2023-06-01 11:32:08 -05:00
committed by GitHub
8 changed files with 91 additions and 3 deletions

View File

@@ -25,7 +25,7 @@
class="btn btn-outline-primary"
(blur)="onClose()"
(click)="onClose()"
[disabled]="(processingChange$ | async) || collectionModifiable == false"
[disabled]="(processingChange$ | async) || collectionModifiable == false || isReadonly"
ngbDropdownToggle>
<span *ngIf="(processingChange$ | async)"><i class='fas fa-circle-notch fa-spin'></i></span>
<span *ngIf="!(processingChange$ | async)">{{ selectedCollectionName$ | async }}</span>

View File

@@ -252,6 +252,12 @@ describe('SubmissionFormCollectionComponent Component', () => {
expect(dropDown).toBeFalsy();
});
it('the dropdown button should be disabled when isReadonly is true', () => {
comp.isReadonly = true;
fixture.detectChanges();
expect(dropdowBtn.nativeNode.attributes.disabled).toBeDefined();
});
it('should be simulated when the drop-down menu is closed', () => {
spyOn(comp, 'onClose');
comp.onClose();

View File

@@ -65,6 +65,11 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
*/
@Input() submissionId;
/**
* Flag to indicate if the submission dropdown is read only
*/
@Input() isReadonly = false;
/**
* An event fired when a different collection is selected.
* Event's payload equals to new SubmissionObject.

View File

@@ -8,12 +8,15 @@
</div>
<div class="submission-form-header-item mb-3 mb-sm-0 flex-sm-grow-1 flex-md-grow-0">
<ng-container *ngIf="!isSectionHidden">
<ds-submission-form-collection [currentCollectionId]="collectionId"
[currentDefinition]="definitionId"
[submissionId]="submissionId"
[collectionModifiable]="collectionModifiable"
[isReadonly]="isSectionReadonly"
(collectionChange)="onCollectionChange($event)">
</ds-submission-form-collection>
</ng-container>
</div>
<div class="submission-form-header-item text-right">
<ds-submission-form-section-add [collectionId]="collectionId"

View File

@@ -25,6 +25,7 @@ import { createTestComponent } from '../../shared/testing/utils.test';
import { Item } from '../../core/shared/item.model';
import { TestScheduler } from 'rxjs/testing';
import { SectionsService } from '../sections/sections.service';
import { VisibilityType } from '../sections/visibility-type';
describe('SubmissionFormComponent Component', () => {
@@ -156,6 +157,32 @@ describe('SubmissionFormComponent Component', () => {
done();
});
it('should return the visibility object of the collection section', () => {
comp.submissionDefinition = submissionDefinition;
fixture.detectChanges();
const result = compAsAny.getCollectionVisibility();
expect(result).toEqual({
main: VisibilityType.HIDDEN,
other: VisibilityType.HIDDEN,
});
});
it('should return true if collection section visibility is hidden', () => {
comp.submissionDefinition = submissionDefinition;
fixture.detectChanges();
expect(comp.isSectionHidden).toBe(true);
});
it('should return false for isSectionReadonly when collection section visibility is not READONLY', () => {
const visibility = {
main: VisibilityType.READONLY,
other: VisibilityType.READONLY,
};
comp.submissionDefinition = Object.assign({}, submissionDefinition, { visibility: visibility });
fixture.detectChanges();
expect(comp.isSectionReadonly).toBe(false);
});
it('should update properly on collection change', (done) => {
comp.collectionId = collectionId;
comp.submissionId = submissionId;

View File

@@ -9,7 +9,7 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
import { WorkspaceitemSectionsObject } from '../../core/submission/models/workspaceitem-sections.model';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
import { UploaderOptions } from '../../shared/upload/uploader/uploader-options.model';
import { SubmissionObjectEntry } from '../objects/submission-objects.reducer';
import { SectionDataObject } from '../sections/models/section-data.model';
@@ -18,6 +18,10 @@ import { Item } from '../../core/shared/item.model';
import { SectionsType } from '../sections/sections-type';
import { SectionsService } from '../sections/sections.service';
import { SubmissionError } from '../objects/submission-error.model';
import { SubmissionSectionVisibility } from './../../core/config/models/config-submission-section.model';
import { SubmissionSectionModel } from './../../core/config/models/config-submission-section.model';
import { VisibilityType } from '../sections/visibility-type';
import isEqual from 'lodash/isEqual';
/**
* This component represents the submission form.
@@ -188,6 +192,42 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
}
}
/**
* Returns the visibility object of the collection section
*/
private getCollectionVisibility(): SubmissionSectionVisibility {
const submissionSectionModel: SubmissionSectionModel =
this.submissionDefinition.sections.page.find(
(section) => isEqual(section.sectionType, SectionsType.Collection)
);
return isNotUndefined(submissionSectionModel.visibility) ? submissionSectionModel.visibility : null;
}
/**
* Getter to see if the collection section visibility is hidden
*/
get isSectionHidden(): boolean {
const visibility = this.getCollectionVisibility();
return (
hasValue(visibility) &&
isEqual(visibility.main, VisibilityType.HIDDEN) &&
isEqual(visibility.other, VisibilityType.HIDDEN)
);
}
/**
* Getter to see if the collection section visibility is readonly
*/
get isSectionReadonly(): boolean {
const visibility = this.getCollectionVisibility();
return (
hasValue(visibility) &&
isEqual(visibility.main, VisibilityType.READONLY) &&
isEqual(visibility.other, VisibilityType.READONLY)
);
}
/**
* Unsubscribe from all subscriptions, destroy instance variables
* and reset submission state
@@ -239,6 +279,8 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
protected getSectionsList(): Observable<any> {
return this.submissionService.getSubmissionSections(this.submissionId).pipe(
filter((sections: SectionDataObject[]) => isNotEmpty(sections)),
map((sections: SectionDataObject[]) => sections));
map((sections: SectionDataObject[]) =>
sections.filter((section: SectionDataObject) => !isEqual(section.sectionType,SectionsType.Collection))),
);
}
}

View File

@@ -8,4 +8,5 @@ export enum SectionsType {
AccessesCondition = 'accessCondition',
SherpaPolicies = 'sherpaPolicy',
Identifiers = 'identifiers',
Collection = 'collection',
}

View File

@@ -0,0 +1,4 @@
export enum VisibilityType {
HIDDEN = 'HIDDEN',
READONLY = 'READONLY',
}