mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[835] Auto-save in new Item Submission form breaks the form
Minor fixes and method computeSectionConfiguredMetadata tested
This commit is contained in:
@@ -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')]"
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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];
|
||||
}
|
||||
})
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user