Skip to content

Commit

Permalink
HOTFIX: Psp 9505 - ensure document metadata reset when document type …
Browse files Browse the repository at this point in the history
…changed. (#4477)

* psp-9436 - remove restriction on take date such that db layer logic corresponds to api logic.

* psp-9505 reset the current documents metadata when the metadata type is changed.

---------

Co-authored-by: Alejandro Sanchez <emailforasr@gmail.com>
  • Loading branch information
devinleighsmith and asanchezr authored Nov 14, 2024
1 parent c7c4cd6 commit fc4af60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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

0 comments on commit fc4af60

Please sign in to comment.