Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOTFIX: Psp 9505 - ensure document metadata reset when document type changed. #4477

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions source/frontend/src/features/documents/ComposedDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,13 @@ export class DocumentUpdateFormData {
return model;
}

public toRequestApi(): ApiGen_Requests_DocumentUpdateRequest {
public static toRequestApi(
formData: DocumentUpdateFormData,
): ApiGen_Requests_DocumentUpdateRequest {
const metadata: ApiGen_Concepts_DocumentMetadataUpdate[] = [];

for (const key in this.documentMetadata) {
const value = this.documentMetadata[key];
for (const key in formData.documentMetadata) {
const value = formData.documentMetadata[key];
const metadataTypeId = Number(key);
metadata.push({
value: value,
Expand All @@ -235,10 +237,10 @@ export class DocumentUpdateFormData {
}

return {
documentId: this.documentId,
mayanDocumentId: this.mayanDocumentId,
documentTypeId: stringToNumber(this.documentTypeId),
documentStatusCode: this.documentStatusCode,
documentId: formData.documentId,
mayanDocumentId: formData.mayanDocumentId,
documentTypeId: stringToNumber(formData.documentTypeId),
documentStatusCode: formData.documentStatusCode,
documentMetadata: metadata,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const DocumentDetailContainer: React.FunctionComponent<
if (documentTypeId !== props.pimsDocument.documentType.id) {
await updateDocumentType(documentTypes.find(x => x.id === documentTypeId));
setDocumentTypeUpdated(true);
formikRef?.current?.setValues({ ...formikRef?.current?.values, documentMetadata: {} });
} else {
setDocumentTypeUpdated(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const DocumentDetailForm: React.FunctionComponent<
props.document?.pimsDocumentRelationship?.id &&
values.documentStatusCode !== undefined
) {
const request = values.toRequestApi();
const request = DocumentUpdateFormData.toRequestApi(values);
await props.onUpdate(request);
setSubmitting(false);
} else {
Expand Down
Loading