@gisce/react-ooui 1.1.40-rc.2 → 1.1.40

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.
@@ -1 +1 @@
1
- {"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,SAAS,IAAI,aAAa,EAG3B,MAAM,aAAa,CAAC;AAKrB,aAAK,KAAK,GAAG;IACX,IAAI,EAAE,aAAa,CAAC;IACpB,iBAAiB,CAAC,EACd,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC,GAC5D,SAAS,CAAC;IACd,aAAa,CAAC,EACV,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC,GAC5D,SAAS,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,KAAK,gBASrC,CAAC;AAEF,UAAU,mBAAmB;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;CAChD;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA0ExD,CAAC"}
1
+ {"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EACL,SAAS,IAAI,aAAa,EAG3B,MAAM,aAAa,CAAC;AAKrB,aAAK,KAAK,GAAG;IACX,IAAI,EAAE,aAAa,CAAC;IACpB,iBAAiB,CAAC,EACd,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAA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AAE,aAAa,KAAK,IAAI,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd;AAWD,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA+mB/C,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"One2manyInput.d.ts","sourceRoot":"","sources":["One2manyInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAWvD,OAAO,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAkB1C,aAAK,aAAa,GAAG;IACnB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC5B,CAAC;AAQF,aAAK,YAAY,GAAG;IAClB,SAAS,CAAC,EACN,UAAU,GACV,eAAe,GACf,eAAe,GACf,eAAe,GACf,aAAa,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,aAAa,CAAC,EAAE,GAAG,CAAC;CACrB,CAAC;AAEF,UAAU,kBAAkB;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd;AAWD,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA8kB/C,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.1.40-rc.2",
3
+ "version": "1.1.40",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ant-design/plots": "^1.0.9",
39
- "@gisce/ooui": "^0.17.14-rc.1",
39
+ "@gisce/ooui": "^0.18.0",
40
40
  "@gisce/react-formiga-table": "^0.5.0",
41
41
  "@monaco-editor/react": "^4.4.5",
42
42
  "@tabler/icons-react": "^2.11.0",
@@ -1,6 +1,5 @@
1
1
  import { One2manyItem } from "@/widgets/base/one2many/One2manyInput";
2
2
  import ConnectionProvider from "@/ConnectionProvider";
3
- import { ViewType } from "@/types";
4
3
 
5
4
  type ReadObjectValuesOptions = {
6
5
  items: One2manyItem[];
@@ -8,20 +7,12 @@ type ReadObjectValuesOptions = {
8
7
  treeFields: any;
9
8
  formFields: any;
10
9
  context?: any;
11
- currentView: ViewType;
12
10
  };
13
11
 
14
12
  const readObjectValues = async (
15
13
  options: ReadObjectValuesOptions
16
14
  ): Promise<One2manyItem[]> => {
17
- const {
18
- items,
19
- model,
20
- formFields,
21
- treeFields,
22
- context,
23
- currentView = {},
24
- } = options;
15
+ const { items, model, formFields, treeFields, context = {} } = options;
25
16
 
26
17
  const temporalItems: One2manyItem = items.filter(
27
18
  (item) => item.operation !== "original"
@@ -32,47 +23,47 @@ const readObjectValues = async (
32
23
  .filter((item) => item.operation === "original")
33
24
  .map((item) => item.id) as number[];
34
25
 
35
- const fieldsToRetrieve: { [key: string]: any } = {
36
- form: formFields,
37
- tree: treeFields,
38
- };
39
-
40
26
  const values = await ConnectionProvider.getHandler().readObjects({
41
27
  model,
42
28
  ids: idsToFetch,
43
- fields: fieldsToRetrieve[currentView as string],
29
+ fields: { ...formFields, ...treeFields },
44
30
  context,
45
31
  });
46
32
 
47
- const filteredValues = values.map((result: any) => {
33
+ const formValues = values.map((result: any) => {
48
34
  const resultFormValues: any = {};
49
35
  Object.keys(result).forEach((key) => {
50
- if (
51
- fieldsToRetrieve[currentView as string].hasOwnProperty(key) ||
52
- key === "id"
53
- ) {
36
+ if (formFields.hasOwnProperty(key) || key === "id") {
54
37
  resultFormValues[key] = result[key];
55
38
  }
56
39
  });
57
40
  return resultFormValues;
58
41
  });
59
42
 
43
+ const treeValues = values.map((result: any) => {
44
+ const resultTreeValues: any = {};
45
+ Object.keys(result).forEach((key) => {
46
+ if (treeFields.hasOwnProperty(key) || key === "id") {
47
+ resultTreeValues[key] = result[key];
48
+ }
49
+ });
50
+ return resultTreeValues;
51
+ });
52
+
60
53
  // We fill the values property of the One2manyItem with the retrieved values from the API
61
54
  const originalItemsWithFetchedValues: One2manyItem[] = items.map((item) => {
62
- const fetchedItemValues = filteredValues.find(
55
+ const fetchedFormItemValues = formValues.find(
56
+ (itemValues: any) => itemValues.id === item.id
57
+ );
58
+ const fetchedTreeItemValues = treeValues.find(
63
59
  (itemValues: any) => itemValues.id === item.id
64
60
  );
65
61
 
66
- const itemWithFetchedValues = {
62
+ return {
67
63
  ...item,
64
+ values: fetchedFormItemValues,
65
+ treeValues: fetchedTreeItemValues,
68
66
  };
69
-
70
- if (currentView === "form") {
71
- itemWithFetchedValues["values"] = fetchedItemValues;
72
- } else if (currentView === "tree") {
73
- itemWithFetchedValues["treeValues"] = fetchedItemValues;
74
- }
75
- return itemWithFetchedValues;
76
67
  });
77
68
 
78
69
  return originalItemsWithFetchedValues.concat(temporalItems);
@@ -88,8 +79,14 @@ type RemoveItemOptions = {
88
79
  };
89
80
 
90
81
  const removeItems = async (options: RemoveItemOptions) => {
91
- const { model, activeId, fieldName, idsToRemove, fields, isMany2many } =
92
- options;
82
+ const {
83
+ model,
84
+ activeId,
85
+ fieldName,
86
+ idsToRemove,
87
+ fields,
88
+ isMany2many,
89
+ } = options;
93
90
 
94
91
  const values: any = {};
95
92
  values[fieldName] = [];
@@ -73,16 +73,8 @@ export const ReferenceInput: React.FC<ReferenceInputProps> = (
73
73
  }
74
74
  onChange={(changedValue: string) => {
75
75
  setSelectionValue(changedValue);
76
- let m2oValue = many2oneValue[0] || 0;
77
- if (changedValue !== selectionValue) {
78
- setMany2oneValue([]);
79
- m2oValue = 0;
80
- }
81
- const referenceValue = `${changedValue},${m2oValue}`;
82
- if (referenceValue === value) {
83
- return;
84
- }
85
- onChange?.(referenceValue);
76
+ setMany2oneValue([]);
77
+ onChange?.(undefined);
86
78
  }}
87
79
  value={selectionValue}
88
80
  />
@@ -100,7 +92,7 @@ export const ReferenceInput: React.FC<ReferenceInputProps> = (
100
92
  value={many2oneValue}
101
93
  onChange={(changedValue: any[]) => {
102
94
  setMany2oneValue(changedValue);
103
- const referenceValue = `${selectionValue},${changedValue[0] || 0}`;
95
+ const referenceValue = `${selectionValue},${changedValue[0]}`;
104
96
  if (referenceValue === value) {
105
97
  return;
106
98
  }
@@ -1,10 +1,4 @@
1
- import React, {
2
- useState,
3
- useRef,
4
- useContext,
5
- useEffect,
6
- useCallback,
7
- } from "react";
1
+ import React, { useState, useRef, useContext, useEffect } from "react";
8
2
  import { One2many as One2manyOoui } from "@gisce/ooui";
9
3
  import { Alert, Spin } from "antd";
10
4
  import { Form } from "@/index";
@@ -89,6 +83,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
89
83
  formContext || {};
90
84
  const { lang, t } = useContext(LocaleContext) as LocaleContextType;
91
85
 
86
+ const formRef = useRef();
92
87
  const [formHasChanges, setFormHasChanges] = useState<boolean>(false);
93
88
  const [isLoading, setIsLoading] = useState<boolean>(false);
94
89
  const [error, setError] = useState<string>();
@@ -111,31 +106,14 @@ const One2manyInput: React.FC<One2manyInputProps> = (
111
106
  const isMany2many = ooui.type === "many2many";
112
107
  const { id: fieldName } = ooui;
113
108
  const itemsToShow = items.filter(
114
- (item) =>
115
- (item.values || item.treeValues) && item.operation !== "pendingRemove"
109
+ (item) => item.values && item.operation !== "pendingRemove"
116
110
  );
117
- const previousCurrentView = useRef<ViewType>();
118
111
 
119
112
  useEffect(() => {
120
- if (previousCurrentView.current !== currentView) {
121
- previousCurrentView.current = currentView;
122
- fetchDataIfNeeded();
123
- return;
124
- }
125
-
126
- fetchDataIfNeeded();
127
- }, [items, currentView]);
128
-
129
- const fetchDataIfNeeded = useCallback(() => {
130
- if (currentView === "form" && items.some((item) => !item.values)) {
131
- fetchData();
132
- } else if (
133
- currentView === "tree" &&
134
- items.some((item) => !item.treeValues)
135
- ) {
113
+ if (items.some((item) => !item.values)) {
136
114
  fetchData();
137
115
  }
138
- }, [items, currentView]);
116
+ }, [items]);
139
117
 
140
118
  useEffect(() => {
141
119
  parseDomain();
@@ -155,7 +133,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
155
133
  }
156
134
  };
157
135
 
158
- const fetchOriginalItemsFromApi = async (mode?: ViewType) => {
136
+ const fetchOriginalItemsFromApi = async () => {
159
137
  setIsLoading(true);
160
138
  setFormHasChanges(false);
161
139
  setError(undefined);
@@ -167,7 +145,6 @@ const One2manyInput: React.FC<One2manyInputProps> = (
167
145
  model: relation,
168
146
  items,
169
147
  context: { ...getContext?.(), ...context },
170
- currentView: mode || currentView,
171
148
  });
172
149
 
173
150
  if (!originalSortItemIds.current) {
@@ -175,7 +152,6 @@ const One2manyInput: React.FC<One2manyInputProps> = (
175
152
  }
176
153
 
177
154
  triggerChange(itemsWithValues);
178
- return itemsWithValues;
179
155
  } catch (err) {
180
156
  setError(err as any);
181
157
  } finally {
@@ -462,19 +438,10 @@ const One2manyInput: React.FC<One2manyInputProps> = (
462
438
  }
463
439
  };
464
440
 
465
- const onTreeRowClicked = async (record: any) => {
441
+ const onTreeRowClicked = (record: any) => {
466
442
  const { id: itemId } = record;
467
-
468
- let itemsToLoadFrom: One2manyItem[] | undefined = items;
469
-
470
- // We should fetch the form data if needed in order to get the form values
471
- const modalItem = items.find((item) => item.id === itemId);
472
- if (modalItem?.values === undefined) {
473
- itemsToLoadFrom = await fetchOriginalItemsFromApi("form");
474
- }
475
-
476
443
  // We show the detail for the clicked item in a Form modal
477
- setModalItem(itemsToLoadFrom!.find((item) => item.id === itemId));
444
+ setModalItem(items.find((item) => item.id === itemId));
478
445
  setContinuousEntryMode(false);
479
446
  setShowFormModal(true);
480
447
  };
@@ -540,18 +507,12 @@ const One2manyInput: React.FC<One2manyInputProps> = (
540
507
  return t("noCurrentEntries");
541
508
  }
542
509
 
543
- if (
544
- currentView !== previousCurrentView.current &&
545
- items.some((item) => !item.values)
546
- ) {
547
- return <Spin />;
548
- }
549
-
550
510
  return (
551
511
  <Form
552
512
  formView={views.get("form")}
553
513
  values={itemsToShow[itemIndex]?.values}
554
514
  parentContext={{ ...getContext?.(), ...context }}
515
+ ref={formRef}
555
516
  model={relation}
556
517
  id={itemsToShow[itemIndex]?.id}
557
518
  submitMode={"values"}