@gisce/react-ooui 2.0.0-rc.3 → 2.0.0-rc.5

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.
Files changed (39) hide show
  1. package/dist/helpers/dynamicColumnsHelper.d.ts +9 -1
  2. package/dist/helpers/dynamicColumnsHelper.d.ts.map +1 -1
  3. package/dist/helpers/treeHelper.d.ts +2 -1
  4. package/dist/helpers/treeHelper.d.ts.map +1 -1
  5. package/dist/hooks/useSearch.d.ts.map +1 -1
  6. package/dist/react-ooui.es.js +4202 -4156
  7. package/dist/react-ooui.es.js.map +1 -1
  8. package/dist/react-ooui.umd.js +11 -11
  9. package/dist/react-ooui.umd.js.map +1 -1
  10. package/dist/types/index.d.ts +29 -29
  11. package/dist/types/index.d.ts.map +1 -1
  12. package/dist/views/actionViews/GraphActionView.d.ts.map +1 -1
  13. package/dist/widgets/base/Integer.d.ts.map +1 -1
  14. package/dist/widgets/base/many2one/Many2oneSuffix.d.ts.map +1 -1
  15. package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
  16. package/dist/widgets/views/Form.d.ts +2 -2
  17. package/dist/widgets/views/Form.d.ts.map +1 -1
  18. package/dist/widgets/views/SearchTree.d.ts.map +1 -1
  19. package/dist/widgets/views/Tree.d.ts.map +1 -1
  20. package/dist/widgets/views/searchFilter/SearchFilter.d.ts +0 -1
  21. package/dist/widgets/views/searchFilter/SearchFilter.d.ts.map +1 -1
  22. package/package.json +3 -3
  23. package/src/actionbar/FormActionBar.tsx +1 -1
  24. package/src/actionbar/TreeActionBar.tsx +1 -1
  25. package/src/context/ContentRootContext.tsx +1 -1
  26. package/src/helpers/dynamicColumnsHelper.ts +1 -1
  27. package/src/helpers/treeHelper.ts +14 -3
  28. package/src/hooks/useExport.ts +2 -3
  29. package/src/hooks/useSearch.ts +1 -0
  30. package/src/stories/mocks/models/cups.ts +16 -3
  31. package/src/types/index.ts +91 -41
  32. package/src/views/actionViews/GraphActionView.tsx +0 -1
  33. package/src/widgets/base/Integer.tsx +14 -1
  34. package/src/widgets/base/many2one/Many2oneSuffix.tsx +24 -12
  35. package/src/widgets/base/one2many/One2manyInput.tsx +11 -3
  36. package/src/widgets/views/Form.tsx +65 -8
  37. package/src/widgets/views/SearchTree.tsx +2 -3
  38. package/src/widgets/views/Tree.tsx +20 -8
  39. package/src/widgets/views/searchFilter/SearchFilter.tsx +1 -3
@@ -20,6 +20,7 @@ import ConnectionProvider from "@/ConnectionProvider";
20
20
  import { processValues } from "@/helpers/formHelper";
21
21
  import showErrorDialog from "@/ui/ActionErrorDialog";
22
22
  import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
23
+ import { parseContextFields, parseDomainFields } from "@gisce/ooui";
23
24
 
24
25
  type Props = {
25
26
  id: number;
@@ -60,18 +61,29 @@ export const Many2oneSuffix = (props: Props) => {
60
61
  context,
61
62
  }) as FormView;
62
63
  setFormView(formView);
63
- const { fields, arch } = formView;
64
-
65
- const values = (
66
- await ConnectionProvider.getHandler().readObjects({
67
- model,
68
- ids: [id],
69
- fields,
70
- context,
71
- })
72
- )[0];
73
-
74
- setTargetValues({ ...processValues(values, fields), active_id: id });
64
+ let fields: string[] = [];
65
+ const { toolbar } = formView;
66
+ toolbar.action?.filter((item: any) => item.hasOwnProperty('context')).map((item: any) => fields.push(...parseContextFields(item.context)));
67
+ toolbar.action?.filter((item: any) => item.hasOwnProperty('domain')).map((item: any) => fields.push(...parseDomainFields(item.domain)));
68
+ toolbar.relate?.filter((item: any) => item.hasOwnProperty('context')).map((item: any) => fields.push(...parseContextFields(item.context)));
69
+ toolbar.relate?.filter((item: any) => item.hasOwnProperty('domain')).map((item: any) => fields.push(...parseDomainFields(item.domain)));
70
+ toolbar.print?.filter((item: any) => item.hasOwnProperty('context')).map((item: any) => fields.push(...parseContextFields(item.context)));
71
+ fields = fields.filter((i) => Object.keys(formView.fields).indexOf(i) > -1)
72
+
73
+ let values = {}
74
+
75
+ if (fields.length > 0) {
76
+ values = (
77
+ await ConnectionProvider.getHandler().readObjects({
78
+ model,
79
+ ids: [id],
80
+ fieldsToRetrieve: fields,
81
+ context,
82
+ })
83
+ )[0];
84
+ }
85
+ values = { ...processValues(values, fields), active_id: id };
86
+ setTargetValues(values);
75
87
 
76
88
  setIsLoading(false);
77
89
  } catch (err) {
@@ -437,11 +437,19 @@ const One2manyInput: React.FC<One2manyInputProps> = (
437
437
  const onFormModalSubmitSucceed = (
438
438
  id: number | undefined,
439
439
  _: any,
440
- values: any
440
+ values: any,
441
+ x2manyPendingLink: boolean = false
441
442
  ) => {
442
443
  let updatedItems: One2manyItem[];
443
444
 
444
- if (id) {
445
+ if (x2manyPendingLink) {
446
+ updatedItems = items.concat({
447
+ id,
448
+ operation: "pendingLink",
449
+ values: { ...values, id },
450
+ treeValues: { ...values, id },
451
+ });
452
+ } else if (id) {
445
453
  updatedItems = items.map((item: One2manyItem) => {
446
454
  if (item.id === id) {
447
455
  return {
@@ -683,7 +691,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
683
691
  formView={views.get("form")}
684
692
  model={relation}
685
693
  id={modalItem?.id}
686
- submitMode={"values"}
694
+ submitMode={"2many"}
687
695
  values={modalItem?.values}
688
696
  defaultValues={modalItem?.defaultValues}
689
697
  visible={showFormModal}
@@ -67,8 +67,13 @@ export type FormProps = {
67
67
  showFooter?: boolean;
68
68
  getDataFromAction?: boolean;
69
69
  mustClearAfterSave?: boolean;
70
- submitMode?: "api" | "values";
71
- onSubmitSucceed?: (id?: number, values?: any, formValues?: any) => void;
70
+ submitMode?: "api" | "values" | "2many";
71
+ onSubmitSucceed?: (
72
+ id?: number,
73
+ values?: any,
74
+ formValues?: any,
75
+ x2manyPendingLink?: boolean
76
+ ) => void;
72
77
  onSubmitError?: (error: any) => void;
73
78
  onCancel?: () => void;
74
79
  onFieldsChange?: (values: any) => void;
@@ -127,6 +132,7 @@ function Form(props: FormProps, ref: any) {
127
132
  const lastAssignedValues = useRef<any>({});
128
133
  const warningIsShown = useRef<boolean>(false);
129
134
  const formSubmitting = useRef<boolean>(false);
135
+ const x2manyPendingLink = useRef<boolean>(false);
130
136
 
131
137
  const widthToEvaluate =
132
138
  parentWidth !== undefined ? parentWidth : containerWidth;
@@ -203,10 +209,15 @@ function Form(props: FormProps, ref: any) {
203
209
  }
204
210
  }, [defaultGetCalled]);
205
211
 
206
- const onSubmitSucceed = (id?: number, values?: any, formValues?: any) => {
212
+ const onSubmitSucceed = (
213
+ id?: number,
214
+ values?: any,
215
+ formValues?: any,
216
+ x2manyPendingLink?: boolean
217
+ ) => {
207
218
  setFormHasChanges?.(false);
208
219
  setFormIsSaving?.(false);
209
- propsOnSubmitSucceed?.(id, values, formValues);
220
+ propsOnSubmitSucceed?.(id, values, formValues, x2manyPendingLink);
210
221
  setCurrentId?.(id);
211
222
  };
212
223
 
@@ -294,6 +305,15 @@ function Form(props: FormProps, ref: any) {
294
305
  return { ...parentContext, ...formOoui?.context };
295
306
  }
296
307
 
308
+ function getActiveIdsContext() {
309
+ const currentId = getCurrentId()!;
310
+
311
+ if (!currentId) {
312
+ return {};
313
+ }
314
+ return { active_id: getCurrentId()!, active_ids: [getCurrentId()!] };
315
+ }
316
+
297
317
  function getAdditionalValues() {
298
318
  return {
299
319
  id: getCurrentId()!,
@@ -608,6 +628,32 @@ function Form(props: FormProps, ref: any) {
608
628
  formSubmitting.current = true;
609
629
 
610
630
  setError(undefined);
631
+
632
+ if (
633
+ x2manyPendingLink.current &&
634
+ !formHasChanges() &&
635
+ getCurrentId()! &&
636
+ callOnSubmitSucceed
637
+ ) {
638
+ formSubmitting.current = false;
639
+ setFormHasChanges?.(false);
640
+ onSubmitSucceed?.(
641
+ getCurrentId(),
642
+ getValues(),
643
+ getFormValues(),
644
+ x2manyPendingLink.current
645
+ );
646
+ x2manyPendingLink.current = false;
647
+ const currentId = getCurrentId()!;
648
+
649
+ if (mustClearAfterSave) {
650
+ createdId.current = undefined;
651
+ assignNewValuesToForm({ values: {}, fields, reset: true });
652
+ }
653
+
654
+ return { succeed: true, id: currentId };
655
+ }
656
+
611
657
  if (!formHasChanges() && getCurrentId()! && callOnSubmitSucceed) {
612
658
  formSubmitting.current = false;
613
659
  setFormHasChanges?.(false);
@@ -833,9 +879,9 @@ function Form(props: FormProps, ref: any) {
833
879
  action,
834
880
  payload: [getCurrentId()!],
835
881
  context: {
836
- ...context,
837
882
  ...formOoui?.context,
838
883
  ...parentContext,
884
+ ...context,
839
885
  },
840
886
  });
841
887
 
@@ -957,15 +1003,26 @@ function Form(props: FormProps, ref: any) {
957
1003
 
958
1004
  try {
959
1005
  if (formHasChanges() || getCurrentId() === undefined) {
960
- await submitForm({ callOnSubmitSucceed: false });
1006
+ if (submitMode === "2many") {
1007
+ await submitApi({ callOnSubmitSucceed: false });
1008
+ x2manyPendingLink.current = true;
1009
+ } else {
1010
+ await submitForm({ callOnSubmitSucceed: false });
1011
+ }
961
1012
  }
962
1013
 
1014
+ const additionalContext = x2manyPendingLink.current
1015
+ ? getActiveIdsContext()
1016
+ : {};
1017
+
1018
+ const updatedContext = { ...context, ...additionalContext };
1019
+
963
1020
  if (type === "object") {
964
- await runObjectButton({ action, context });
1021
+ await runObjectButton({ action, context: updatedContext });
965
1022
  } else if (type === "workflow") {
966
1023
  await runWorkflowButton({ action });
967
1024
  } else if (type === "action") {
968
- await runActionButton({ action, context });
1025
+ await runActionButton({ action, context: updatedContext });
969
1026
  }
970
1027
  } catch (err) {
971
1028
  showErrorDialog(err);
@@ -128,7 +128,7 @@ function SearchTree(props: Props, ref: any) {
128
128
  } = useSearch({
129
129
  model: currentModel!,
130
130
  setSearchTreeNameSearch,
131
- setSelectedRowItems,
131
+ setSelectedRowItems: changeSelectedRowKeys,
132
132
  setSearchParams,
133
133
  setSearchValues,
134
134
  searchParams,
@@ -291,12 +291,11 @@ function SearchTree(props: Props, ref: any) {
291
291
  return (
292
292
  <>
293
293
  <SearchFilter
294
- fields={{ ...treeView.fields, ...formView.fields }}
294
+ fields={{ ...formView.fields, ...treeView.fields }}
295
295
  searchFields={mergeSearchFields([
296
296
  formView.search_fields,
297
297
  treeView.search_fields,
298
298
  ])}
299
- formXml={formView.arch}
300
299
  onClear={clear}
301
300
  limit={limit}
302
301
  offset={offset}
@@ -1,6 +1,11 @@
1
1
  import React, { useContext, useEffect, useRef, useState } from "react";
2
2
  import { Pagination, Checkbox, Space, Row, Col, Spin, Tag, Badge } from "antd";
3
- import { getTree, getTableColumns, getTableItems } from "@/helpers/treeHelper";
3
+ import {
4
+ getTree,
5
+ getTableColumns,
6
+ getTableItems,
7
+ hasActualValues,
8
+ } from "@/helpers/treeHelper";
4
9
  import { Tree as TreeOoui } from "@gisce/ooui";
5
10
 
6
11
  import { TreeView, Column } from "@/types";
@@ -331,7 +336,9 @@ function Tree(props: Props): React.ReactElement {
331
336
  }
332
337
  }
333
338
 
334
- return treeOoui.current === null ? (
339
+ return treeOoui.current === null ||
340
+ !dataTable ||
341
+ dataTable.columns?.length === 0 ? (
335
342
  <Spin style={{ padding: "2rem" }} />
336
343
  ) : (
337
344
  <div>
@@ -348,13 +355,18 @@ function Tree(props: Props): React.ReactElement {
348
355
  }
349
356
  return undefined;
350
357
  }}
351
- onRowStatus={(record: any) => {
352
- if (statusForResults![record.id]) {
353
- return <Badge color={statusForResults[record.id]} />;
354
- }
355
- return undefined;
356
- }}
358
+ onRowStatus={
359
+ hasActualValues(statusForResults)
360
+ ? (record: any) => {
361
+ if (statusForResults![record.id]) {
362
+ return <Badge color={statusForResults[record.id]} />;
363
+ }
364
+ return undefined;
365
+ }
366
+ : undefined
367
+ }
357
368
  onRowDoubleClick={onRowClicked}
369
+ selectionRowKeys={rowSelection?.selectedRowKeys}
358
370
  onRowSelectionChange={rowSelection?.onChange}
359
371
  onChangeSort={onChangeSort}
360
372
  sorter={sorter}
@@ -31,7 +31,6 @@ type Props = {
31
31
  searchError?: string;
32
32
  searchValues?: any;
33
33
  showLimitOptions?: boolean;
34
- formXml: string;
35
34
  };
36
35
 
37
36
  function SearchFilter(props: Props) {
@@ -49,7 +48,6 @@ function SearchFilter(props: Props) {
49
48
  searchError,
50
49
  searchValues,
51
50
  showLimitOptions = true,
52
- formXml,
53
51
  } = props;
54
52
 
55
53
  const [simpleSearchFields, setSimpleSearchFields] = useState<Container>();
@@ -89,7 +87,7 @@ function SearchFilter(props: Props) {
89
87
 
90
88
  useDeepCompareEffect(() => {
91
89
  setAdvancedFilter(false);
92
- sfo.current = new SearchFilterOoui(searchFields, fields, formXml);
90
+ sfo.current = new SearchFilterOoui(searchFields, fields);
93
91
  sfo.current.parse();
94
92
  setSimpleSearchFields(sfo.current._simpleSearchContainer);
95
93
  setAdvancedSearchFields(sfo.current._advancedSearchContainer);