mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
[835] Auto-save in new Item Submission form breaks the form
Store additions: 1. Form AdditionalData: contains the list of the touched metadata 2. Submission metadata: contains the list of the metadata ids assignable for each section We keep also track whether a section ha focused fields or not.
This commit is contained in:
@@ -206,6 +206,7 @@ export class UpdateSectionDataAction implements Action {
|
||||
sectionId: string;
|
||||
data: WorkspaceitemSectionDataType;
|
||||
errors: SubmissionSectionError[];
|
||||
metadata: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -219,12 +220,15 @@ export class UpdateSectionDataAction implements Action {
|
||||
* the section's data
|
||||
* @param errors
|
||||
* the section's errors
|
||||
* @param metadata
|
||||
* the section's metadata
|
||||
*/
|
||||
constructor(submissionId: string,
|
||||
sectionId: string,
|
||||
data: WorkspaceitemSectionDataType,
|
||||
errors: SubmissionSectionError[]) {
|
||||
this.payload = { submissionId, sectionId, data, errors };
|
||||
errors: SubmissionSectionError[],
|
||||
metadata?: string[]) {
|
||||
this.payload = { submissionId, sectionId, data, errors, metadata };
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -292,7 +292,7 @@ export class SubmissionObjectEffects {
|
||||
return item$.pipe(
|
||||
map((item: Item) => item.metadata),
|
||||
filter((metadata) => !isEqual(action.payload.data, metadata)),
|
||||
map((metadata: any) => new UpdateSectionDataAction(action.payload.submissionId, action.payload.sectionId, metadata, action.payload.errors))
|
||||
map((metadata: any) => new UpdateSectionDataAction(action.payload.submissionId, action.payload.sectionId, metadata, action.payload.errors, action.payload.metadata))
|
||||
);
|
||||
} else {
|
||||
return observableOf(new UpdateSectionDataSuccessAction());
|
||||
|
@@ -85,6 +85,11 @@ export interface SubmissionSectionObject {
|
||||
*/
|
||||
enabled: boolean;
|
||||
|
||||
/**
|
||||
* The list of the metadata ids of the section.
|
||||
*/
|
||||
metadata: string[];
|
||||
|
||||
/**
|
||||
* The section data object
|
||||
*/
|
||||
@@ -660,7 +665,8 @@ function updateSectionData(state: SubmissionObjectState, action: UpdateSectionDa
|
||||
[ action.payload.sectionId ]: Object.assign({}, state[ action.payload.submissionId ].sections [ action.payload.sectionId ], {
|
||||
enabled: true,
|
||||
data: action.payload.data,
|
||||
errors: action.payload.errors
|
||||
errors: action.payload.errors,
|
||||
metadata: reduceSectionMetadata(action.payload.metadata, state[ action.payload.submissionId ].sections [ action.payload.sectionId ].metadata)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -670,6 +676,22 @@ function updateSectionData(state: SubmissionObjectState, action: UpdateSectionDa
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of the section metadata only when a new value is provided.
|
||||
* Keep the existent otherwise.
|
||||
* @param newMetadata
|
||||
* @param oldMetadata
|
||||
*/
|
||||
function reduceSectionMetadata(newMetadata: string[], oldMetadata: string[]) {
|
||||
if (newMetadata) {
|
||||
return newMetadata;
|
||||
}
|
||||
if (oldMetadata) {
|
||||
return [...oldMetadata];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a section state.
|
||||
*
|
||||
|
Reference in New Issue
Block a user