@gisce/react-ooui 1.1.40 → 1.1.42

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":"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"}
1
+ {"version":3,"file":"One2manyInput.d.ts","sourceRoot":"","sources":["One2manyInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;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AE,KAAK,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,aAAa,gBAsD5C,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,kBAAkB,gBA+GtD,CAAC"}
1
+ {"version":3,"file":"Timeline.d.ts","sourceRoot":"","sources":["Timeline.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAgB,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAY,MAAM,SAAS,CAAC;AAO1C,aAAK,aAAa,GAAG;IACnB,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,aAAK,kBAAkB,GAAG,aAAa,GAAG;IACxC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,QAAQ,UAAW,aAAa,gBAsD5C,CAAC;AAEF,eAAO,MAAM,aAAa,UAAW,kBAAkB,gBAgHtD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["Dashboard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAGf,OAAO,gCAAgC,CAAC;AACxC,OAAO,kCAAkC,CAAC;AAI1C,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;;AAsWnD,wBAAqC"}
1
+ {"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["Dashboard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAGf,OAAO,gCAAgC,CAAC;AACxC,OAAO,kCAAkC,CAAC;AAI1C,OAAO,EAAE,cAAc,EAAY,MAAM,SAAS,CAAC;;AAwWnD,wBAAqC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.1.40",
3
+ "version": "1.1.42",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -1,5 +1,6 @@
1
1
  import { One2manyItem } from "@/widgets/base/one2many/One2manyInput";
2
2
  import ConnectionProvider from "@/ConnectionProvider";
3
+ import { ViewType } from "@/types";
3
4
 
4
5
  type ReadObjectValuesOptions = {
5
6
  items: One2manyItem[];
@@ -7,12 +8,20 @@ type ReadObjectValuesOptions = {
7
8
  treeFields: any;
8
9
  formFields: any;
9
10
  context?: any;
11
+ currentView: ViewType;
10
12
  };
11
13
 
12
14
  const readObjectValues = async (
13
15
  options: ReadObjectValuesOptions
14
16
  ): Promise<One2manyItem[]> => {
15
- const { items, model, formFields, treeFields, context = {} } = options;
17
+ const {
18
+ items,
19
+ model,
20
+ formFields,
21
+ treeFields,
22
+ context,
23
+ currentView = {},
24
+ } = options;
16
25
 
17
26
  const temporalItems: One2manyItem = items.filter(
18
27
  (item) => item.operation !== "original"
@@ -23,47 +32,47 @@ const readObjectValues = async (
23
32
  .filter((item) => item.operation === "original")
24
33
  .map((item) => item.id) as number[];
25
34
 
35
+ const fieldsToRetrieve: { [key: string]: any } = {
36
+ form: formFields,
37
+ tree: treeFields,
38
+ };
39
+
26
40
  const values = await ConnectionProvider.getHandler().readObjects({
27
41
  model,
28
42
  ids: idsToFetch,
29
- fields: { ...formFields, ...treeFields },
43
+ fields: fieldsToRetrieve[currentView as string],
30
44
  context,
31
45
  });
32
46
 
33
- const formValues = values.map((result: any) => {
47
+ const filteredValues = values.map((result: any) => {
34
48
  const resultFormValues: any = {};
35
49
  Object.keys(result).forEach((key) => {
36
- if (formFields.hasOwnProperty(key) || key === "id") {
50
+ if (
51
+ fieldsToRetrieve[currentView as string].hasOwnProperty(key) ||
52
+ key === "id"
53
+ ) {
37
54
  resultFormValues[key] = result[key];
38
55
  }
39
56
  });
40
57
  return resultFormValues;
41
58
  });
42
59
 
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
-
53
60
  // We fill the values property of the One2manyItem with the retrieved values from the API
54
61
  const originalItemsWithFetchedValues: One2manyItem[] = items.map((item) => {
55
- const fetchedFormItemValues = formValues.find(
56
- (itemValues: any) => itemValues.id === item.id
57
- );
58
- const fetchedTreeItemValues = treeValues.find(
62
+ const fetchedItemValues = filteredValues.find(
59
63
  (itemValues: any) => itemValues.id === item.id
60
64
  );
61
65
 
62
- return {
66
+ const itemWithFetchedValues = {
63
67
  ...item,
64
- values: fetchedFormItemValues,
65
- treeValues: fetchedTreeItemValues,
66
68
  };
69
+
70
+ if (currentView === "form") {
71
+ itemWithFetchedValues["values"] = fetchedItemValues;
72
+ } else if (currentView === "tree") {
73
+ itemWithFetchedValues["treeValues"] = fetchedItemValues;
74
+ }
75
+ return itemWithFetchedValues;
67
76
  });
68
77
 
69
78
  return originalItemsWithFetchedValues.concat(temporalItems);
@@ -79,14 +88,8 @@ type RemoveItemOptions = {
79
88
  };
80
89
 
81
90
  const removeItems = async (options: RemoveItemOptions) => {
82
- const {
83
- model,
84
- activeId,
85
- fieldName,
86
- idsToRemove,
87
- fields,
88
- isMany2many,
89
- } = options;
91
+ const { model, activeId, fieldName, idsToRemove, fields, isMany2many } =
92
+ options;
90
93
 
91
94
  const values: any = {};
92
95
  values[fieldName] = [];
@@ -1,4 +1,10 @@
1
- import React, { useState, useRef, useContext, useEffect } from "react";
1
+ import React, {
2
+ useState,
3
+ useRef,
4
+ useContext,
5
+ useEffect,
6
+ useCallback,
7
+ } from "react";
2
8
  import { One2many as One2manyOoui } from "@gisce/ooui";
3
9
  import { Alert, Spin } from "antd";
4
10
  import { Form } from "@/index";
@@ -83,7 +89,6 @@ const One2manyInput: React.FC<One2manyInputProps> = (
83
89
  formContext || {};
84
90
  const { lang, t } = useContext(LocaleContext) as LocaleContextType;
85
91
 
86
- const formRef = useRef();
87
92
  const [formHasChanges, setFormHasChanges] = useState<boolean>(false);
88
93
  const [isLoading, setIsLoading] = useState<boolean>(false);
89
94
  const [error, setError] = useState<string>();
@@ -106,14 +111,31 @@ const One2manyInput: React.FC<One2manyInputProps> = (
106
111
  const isMany2many = ooui.type === "many2many";
107
112
  const { id: fieldName } = ooui;
108
113
  const itemsToShow = items.filter(
109
- (item) => item.values && item.operation !== "pendingRemove"
114
+ (item) =>
115
+ (item.values || item.treeValues) && item.operation !== "pendingRemove"
110
116
  );
117
+ const previousCurrentView = useRef<ViewType>();
111
118
 
112
119
  useEffect(() => {
113
- if (items.some((item) => !item.values)) {
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
+ ) {
114
136
  fetchData();
115
137
  }
116
- }, [items]);
138
+ }, [items, currentView]);
117
139
 
118
140
  useEffect(() => {
119
141
  parseDomain();
@@ -133,7 +155,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
133
155
  }
134
156
  };
135
157
 
136
- const fetchOriginalItemsFromApi = async () => {
158
+ const fetchOriginalItemsFromApi = async (mode?: ViewType) => {
137
159
  setIsLoading(true);
138
160
  setFormHasChanges(false);
139
161
  setError(undefined);
@@ -145,6 +167,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
145
167
  model: relation,
146
168
  items,
147
169
  context: { ...getContext?.(), ...context },
170
+ currentView: mode || currentView,
148
171
  });
149
172
 
150
173
  if (!originalSortItemIds.current) {
@@ -152,6 +175,7 @@ const One2manyInput: React.FC<One2manyInputProps> = (
152
175
  }
153
176
 
154
177
  triggerChange(itemsWithValues);
178
+ return itemsWithValues;
155
179
  } catch (err) {
156
180
  setError(err as any);
157
181
  } finally {
@@ -438,10 +462,19 @@ const One2manyInput: React.FC<One2manyInputProps> = (
438
462
  }
439
463
  };
440
464
 
441
- const onTreeRowClicked = (record: any) => {
465
+ const onTreeRowClicked = async (record: any) => {
442
466
  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
+
443
476
  // We show the detail for the clicked item in a Form modal
444
- setModalItem(items.find((item) => item.id === itemId));
477
+ setModalItem(itemsToLoadFrom!.find((item) => item.id === itemId));
445
478
  setContinuousEntryMode(false);
446
479
  setShowFormModal(true);
447
480
  };
@@ -507,12 +540,18 @@ const One2manyInput: React.FC<One2manyInputProps> = (
507
540
  return t("noCurrentEntries");
508
541
  }
509
542
 
543
+ if (
544
+ currentView !== previousCurrentView.current &&
545
+ items.some((item) => !item.values)
546
+ ) {
547
+ return <Spin />;
548
+ }
549
+
510
550
  return (
511
551
  <Form
512
552
  formView={views.get("form")}
513
553
  values={itemsToShow[itemIndex]?.values}
514
554
  parentContext={{ ...getContext?.(), ...context }}
515
- ref={formRef}
516
555
  model={relation}
517
556
  id={itemsToShow[itemIndex]?.id}
518
557
  submitMode={"values"}
@@ -111,6 +111,7 @@ export const TimelineInput = (props: TimelineInputProps) => {
111
111
  model: relation,
112
112
  items,
113
113
  context: { ...getContext?.(), ...context },
114
+ currentView: "form",
114
115
  });
115
116
 
116
117
  triggerChange(itemsWithValues);
@@ -111,6 +111,7 @@ function Dashboard(props: DashboardProps, ref: any) {
111
111
  model,
112
112
  items,
113
113
  context,
114
+ currentView: "form",
114
115
  });
115
116
  }
116
117
 
@@ -214,6 +215,7 @@ function Dashboard(props: DashboardProps, ref: any) {
214
215
  }
215
216
 
216
217
  if (error) {
218
+ console.log(error);
217
219
  return (
218
220
  <Alert className="mt-10 mb-20" message={error} type="error" banner />
219
221
  );