[835] Auto-save in new Item Submission form breaks the form

Minor fixes and method computeSectionConfiguredMetadata tested
This commit is contained in:
Alessandro Martelli
2020-12-21 19:21:49 +01:00
parent 042d2e71f0
commit 8e77fac638
6 changed files with 29 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
[formId]="formId"
[group]="formGroup"
[hasErrorMessaging]="model.hasErrorMessages"
[hidden]="model.hidden"linke
[hidden]="model.hidden"
[layout]="formLayout"
[model]="model"
[ngClass]="[getClass(model, 'element', 'host'), getClass(model, 'grid', 'host')]"

View File

@@ -235,7 +235,7 @@ function changeTouchedState(state: FormState, action: FormAddTouchedAction): For
newState[action.payload.formId] = newForm;
newForm.touched = { ... newForm.touched};
action.payload.touched.forEach((field) => newForm[field] = true);
action.payload.touched.forEach((field) => newForm.touched[field] = true);
return newState;
} else {

View File

@@ -443,7 +443,7 @@ function getForm(forms, currentState, sectionId) {
* @param notify
* Whether notifications are enabled
*/
function filterErrors(sectionForm: FormState, sectionErrors: SubmissionSectionError[], sectionType: string, notify: boolean): any {
function filterErrors(sectionForm: FormState, sectionErrors: SubmissionSectionError[], sectionType: string, notify: boolean): SubmissionSectionError[] {
if (notify || sectionType !== SectionsType.SubmissionForm) {
return sectionErrors;
}

View File

@@ -695,7 +695,7 @@ function setSectionFormId(state: SubmissionObjectState, action: SetSectionFormId
*/
function updateSectionData(state: SubmissionObjectState, action: UpdateSectionDataAction): SubmissionObjectState {
if (isNotEmpty(state[ action.payload.submissionId ])
&& isNotEmpty(state[ action.payload.submissionId ].sections[ action.payload.sectionId])) {
&& isNotEmpty(state[ action.payload.submissionId ].sections[ action.payload.sectionId])) {
return Object.assign({}, state, {
[ action.payload.submissionId ]: Object.assign({}, state[ action.payload.submissionId ], {
sections: Object.assign({}, state[ action.payload.submissionId ].sections, {
@@ -718,8 +718,10 @@ function updateSectionData(state: SubmissionObjectState, action: UpdateSectionDa
* Keep the existent otherwise.
* @param newMetadata
* @param oldMetadata
* @return
* new sectionMetadata value
*/
function reduceSectionMetadata(newMetadata: string[], oldMetadata: string[]) {
function reduceSectionMetadata(newMetadata: string[], oldMetadata: string[]): string[] {
if (newMetadata) {
return newMetadata;
}

View File

@@ -240,7 +240,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
const sectionDataToCheck = {};
Object.keys(sectionData).forEach((key) => {
if (this.sectionMetadata.includes(key)) {
if (this.sectionMetadata && this.sectionMetadata.includes(key)) {
sectionDataToCheck[key] = sectionData[key];
}
})

View File

@@ -380,4 +380,25 @@ describe('SectionsService test suite', () => {
expect(store.dispatch).toHaveBeenCalledWith(new UpdateSectionDataAction(submissionId, sectionId, data, []));
});
});
describe('computeSectionConfiguredMetadata', () => {
it('should return the configured metadata of the section from the form configuration', () => {
const formConfig = {
rows: [{
fields: [{
selectableMetadata: [{
metadata: 'dc.contributor.author'
}]
}]
}]
}
const expectedConfiguredMetadata = [ 'dc.contributor.author' ];
const configuredMetadata = service.computeSectionConfiguredMetadata(formConfig as any);
expect(configuredMetadata).toEqual(expectedConfiguredMetadata);
});
});
});