@gisce/react-ooui 1.2.0-rc.39 → 1.2.0-rc.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.2.0-rc.39",
3
+ "version": "1.2.0-rc.41",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -343,9 +343,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
343
343
  if (!action) {
344
344
  return;
345
345
  }
346
- const savedSucceed = await onFormSave?.();
347
346
 
348
- if (!savedSucceed) {
347
+ const result = await saveNewDocumentIfNeeded({
348
+ onFormSave,
349
+ currentId,
350
+ });
351
+
352
+ if (!result.succeed) {
349
353
  return;
350
354
  }
351
355
 
@@ -361,15 +365,21 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
361
365
  if (!report) {
362
366
  return;
363
367
  }
364
- const savedSucceed = await onFormSave?.();
368
+ const result = await saveNewDocumentIfNeeded({
369
+ onFormSave,
370
+ currentId,
371
+ });
365
372
 
366
- if (!savedSucceed) {
373
+ if (!result.succeed) {
367
374
  return;
368
375
  }
369
376
 
370
377
  runAction({
371
378
  ...report,
372
- datas: { ...(report.datas || {}), ids: [currentId as number] },
379
+ datas: {
380
+ ...(report.datas || {}),
381
+ ids: [result.currentId as number],
382
+ },
373
383
  });
374
384
  }}
375
385
  />
@@ -383,9 +393,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
383
393
  return;
384
394
  }
385
395
 
386
- const savedSucceed = await onFormSave?.();
396
+ const result = await saveNewDocumentIfNeeded({
397
+ onFormSave,
398
+ currentId,
399
+ });
387
400
 
388
- if (!savedSucceed) {
401
+ if (!result.succeed) {
389
402
  return;
390
403
  }
391
404
 
@@ -402,13 +415,16 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
402
415
  disabled={mustDisableButtons}
403
416
  attachments={attachments}
404
417
  onAddNewAttachment={async () => {
405
- const savedSucceed = await onFormSave?.();
418
+ const result = await saveNewDocumentIfNeeded({
419
+ onFormSave,
420
+ currentId,
421
+ });
406
422
 
407
- if (!savedSucceed) {
423
+ if (!result.succeed) {
408
424
  return;
409
425
  }
410
426
 
411
- const res_id = currentId as number;
427
+ const res_id = result.currentId as number;
412
428
  const res_model = currentModel as string;
413
429
  openDefaultActionForModel({
414
430
  model: "ir.attachment",
@@ -423,13 +439,16 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
423
439
  });
424
440
  }}
425
441
  onListAllAttachments={async () => {
426
- const savedSucceed = await onFormSave?.();
442
+ const result = await saveNewDocumentIfNeeded({
443
+ onFormSave,
444
+ currentId,
445
+ });
427
446
 
428
- if (!savedSucceed) {
447
+ if (!result.succeed) {
429
448
  return;
430
449
  }
431
450
 
432
- const res_id = currentId as number;
451
+ const res_id = result.currentId as number;
433
452
  const res_model = currentModel as string;
434
453
  openDefaultActionForModel({
435
454
  model: "ir.attachment",
@@ -441,9 +460,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
441
460
  });
442
461
  }}
443
462
  onViewAttachmentDetails={async (attachment: Attachment) => {
444
- const savedSucceed = await onFormSave?.();
463
+ const result = await saveNewDocumentIfNeeded({
464
+ onFormSave,
465
+ currentId,
466
+ });
445
467
 
446
- if (!savedSucceed) {
468
+ if (!result.succeed) {
447
469
  return;
448
470
  }
449
471
 
@@ -462,4 +484,23 @@ function separator() {
462
484
  return <div className="inline-block w-2" />;
463
485
  }
464
486
 
487
+ async function saveNewDocumentIfNeeded({
488
+ onFormSave,
489
+ currentId,
490
+ }: {
491
+ onFormSave?: () => Promise<{ succeed: boolean; id: number }>;
492
+ currentId: number | undefined;
493
+ }): Promise<{ succeed: boolean; currentId?: number }> {
494
+ if (currentId !== undefined) {
495
+ return { succeed: true, currentId: currentId };
496
+ }
497
+ const result = await onFormSave?.();
498
+
499
+ if (result?.succeed) {
500
+ return { succeed: true, currentId: result.id };
501
+ } else {
502
+ return { succeed: false, currentId: undefined };
503
+ }
504
+ }
505
+
465
506
  export default FormActionBar;
@@ -11,7 +11,7 @@ export type ActionViewContextType = {
11
11
  setFormIsSaving?: (value: boolean) => void;
12
12
  formHasChanges?: boolean;
13
13
  setFormHasChanges?: (value: boolean) => void;
14
- onFormSave?: () => Promise<void>;
14
+ onFormSave?: () => Promise<{ succeed: boolean; id: number }>;
15
15
  formRef?: any;
16
16
  searchTreeRef?: any;
17
17
  onNewClicked: () => void;
@@ -142,7 +142,7 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
142
142
  }, [currentView]);
143
143
 
144
144
  const callOnFormSave = async () => {
145
- await (formRef.current as any)?.submitForm();
145
+ return await (formRef.current as any)?.submitForm();
146
146
  };
147
147
 
148
148
  return (
@@ -22,7 +22,7 @@ export type FormContextType = {
22
22
  domain: any[];
23
23
  submitForm?: (options?: {
24
24
  callOnSubmitSucceed?: boolean;
25
- }) => Promise<boolean>;
25
+ }) => Promise<{ succeed: boolean; id: number }>;
26
26
  fetchValues?: () => void;
27
27
  formHasChanges?: () => boolean;
28
28
  elementHasLostFocus?: () => void;
@@ -611,13 +611,13 @@ function Form(props: FormProps, ref: any) {
611
611
  formSubmitting.current = false;
612
612
  setFormHasChanges?.(false);
613
613
  onCancel?.();
614
- return true;
614
+ return { succeed: true, id: getCurrentId()! };
615
615
  }
616
616
 
617
617
  if (await checkIfFormHasErrors()) {
618
618
  formSubmitting.current = false;
619
619
  formErrorsDialog(lang);
620
- return false;
620
+ return { succeed: false, id: getCurrentId()! };
621
621
  }
622
622
 
623
623
  setIsSubmitting(true);
@@ -650,7 +650,7 @@ function Form(props: FormProps, ref: any) {
650
650
  setIsSubmitting(false);
651
651
  }
652
652
 
653
- return submitSucceed;
653
+ return { succeed: submitSucceed, id: getCurrentId()! };
654
654
  };
655
655
 
656
656
  const parseForm = ({