Enhancement: use patch instead of put for frontend document changes (#9744)

This commit is contained in:
shamoon
2025-04-22 12:58:28 -07:00
committed by GitHub
parent 2abf38f98e
commit cbaceb95af
4 changed files with 54 additions and 31 deletions

View File

@@ -784,6 +784,7 @@ export class DocumentDetailComponent
this.title = doc.title
this.updateFormForCustomFields()
this.documentForm.patchValue(doc)
this.documentForm.markAsPristine()
this.openDocumentService.setDirty(doc, false)
},
error: () => {
@@ -794,11 +795,30 @@ export class DocumentDetailComponent
})
}
private getChangedFields(): any {
const changes = {
id: this.document.id,
}
Object.keys(this.documentForm.controls).forEach((key) => {
if (this.documentForm.get(key).dirty) {
if (key === 'permissions_form') {
changes['owner'] =
this.documentForm.get('permissions_form').value['owner']
changes['set_permissions'] =
this.documentForm.get('permissions_form').value['set_permissions']
} else {
changes[key] = this.documentForm.get(key).value
}
}
})
return changes
}
save(close: boolean = false) {
this.networkActive = true
;(document.activeElement as HTMLElement)?.dispatchEvent(new Event('change'))
this.documentsService
.update(this.document)
.patch(this.getChangedFields())
.pipe(first())
.subscribe({
next: (docValues) => {
@@ -852,7 +872,7 @@ export class DocumentDetailComponent
this.networkActive = true
this.store.next(this.documentForm.value)
this.documentsService
.update(this.document)
.patch(this.getChangedFields())
.pipe(
switchMap((updateResult) => {
return this.documentListViewService
@@ -1303,6 +1323,8 @@ export class DocumentDetailComponent
created: new Date(),
})
this.updateFormForCustomFields(true)
this.documentForm.get('custom_fields').markAsDirty()
this.documentForm.updateValueAndValidity()
}
public removeField(fieldInstance: CustomFieldInstance) {
@@ -1311,6 +1333,7 @@ export class DocumentDetailComponent
1
)
this.updateFormForCustomFields(true)
this.documentForm.get('custom_fields').markAsDirty()
this.documentForm.updateValueAndValidity()
}