diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index b90ce2b28..fa42d83cc 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@gisce/react-ooui", - "version": "1.1.33", + "version": "1.1.34", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/react-ooui", - "version": "1.1.33", + "version": "1.1.34", "dependencies": { "@ant-design/plots": "^1.0.9", "@gisce/ooui": "^0.17.13", diff --git a/package.json b/package.json index 6803c9c21..d30c69898 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/react-ooui", - "version": "1.1.33", + "version": "1.1.34", "files": [ "dist", "src", diff --git a/src/actionbar/FormActionBar.tsx b/src/actionbar/FormActionBar.tsx index a6c0f51aa..83a54fb2a 100644 --- a/src/actionbar/FormActionBar.tsx +++ b/src/actionbar/FormActionBar.tsx @@ -343,9 +343,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) { if (!action) { return; } - const savedSucceed = await onFormSave?.(); - if (!savedSucceed) { + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); + + if (!result.succeed) { return; } @@ -361,15 +365,21 @@ function FormActionBar({ toolbar }: { toolbar: any }) { if (!report) { return; } - const savedSucceed = await onFormSave?.(); + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); - if (!savedSucceed) { + if (!result.succeed) { return; } runAction({ ...report, - datas: { ...(report.datas || {}), ids: [currentId as number] }, + datas: { + ...(report.datas || {}), + ids: [result.currentId as number], + }, }); }} /> @@ -383,9 +393,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) { return; } - const savedSucceed = await onFormSave?.(); + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); - if (!savedSucceed) { + if (!result.succeed) { return; } @@ -402,13 +415,16 @@ function FormActionBar({ toolbar }: { toolbar: any }) { disabled={mustDisableButtons} attachments={attachments} onAddNewAttachment={async () => { - const savedSucceed = await onFormSave?.(); + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); - if (!savedSucceed) { + if (!result.succeed) { return; } - const res_id = currentId as number; + const res_id = result.currentId as number; const res_model = currentModel as string; openDefaultActionForModel({ model: "ir.attachment", @@ -423,13 +439,16 @@ function FormActionBar({ toolbar }: { toolbar: any }) { }); }} onListAllAttachments={async () => { - const savedSucceed = await onFormSave?.(); + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); - if (!savedSucceed) { + if (!result.succeed) { return; } - const res_id = currentId as number; + const res_id = result.currentId as number; const res_model = currentModel as string; openDefaultActionForModel({ model: "ir.attachment", @@ -441,9 +460,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) { }); }} onViewAttachmentDetails={async (attachment: Attachment) => { - const savedSucceed = await onFormSave?.(); + const result = await saveNewDocumentIfNeeded({ + onFormSave, + currentId, + }); - if (!savedSucceed) { + if (!result.succeed) { return; } @@ -462,4 +484,23 @@ function separator() { return
; } +async function saveNewDocumentIfNeeded({ + onFormSave, + currentId, +}: { + onFormSave?: () => Promise<{ succeed: boolean; id: number }>; + currentId: number | undefined; +}): Promise<{ succeed: boolean; currentId?: number }> { + if (currentId !== undefined) { + return { succeed: true, currentId: currentId }; + } + const result = await onFormSave?.(); + + if (result?.succeed) { + return { succeed: true, currentId: result.id }; + } else { + return { succeed: false, currentId: undefined }; + } +} + export default FormActionBar; diff --git a/src/context/ActionViewContext.tsx b/src/context/ActionViewContext.tsx index bbc6a0c6e..d52822c88 100644 --- a/src/context/ActionViewContext.tsx +++ b/src/context/ActionViewContext.tsx @@ -11,7 +11,7 @@ export type ActionViewContextType = { setFormIsSaving?: (value: boolean) => void; formHasChanges?: boolean; setFormHasChanges?: (value: boolean) => void; - onFormSave?: () => Promise