@gisce/react-ooui 0.8.7 → 0.9.0

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 (36) hide show
  1. package/dist/actionbar/TreeActionBar.d.ts +1 -0
  2. package/dist/actionbar/TreeActionBar.d.ts.map +1 -1
  3. package/dist/actionbar/TreeActionBar.js +25 -22
  4. package/dist/actionbar/TreeActionBar.js.map +1 -1
  5. package/dist/helpers/treeHelper.d.ts.map +1 -1
  6. package/dist/helpers/treeHelper.js +3 -0
  7. package/dist/helpers/treeHelper.js.map +1 -1
  8. package/dist/index.js +2 -2
  9. package/dist/types/index.d.ts +9 -1
  10. package/dist/types/index.d.ts.map +1 -1
  11. package/dist/views/ActionView.d.ts +1 -0
  12. package/dist/views/ActionView.d.ts.map +1 -1
  13. package/dist/views/ActionView.js +31 -20
  14. package/dist/views/ActionView.js.map +1 -1
  15. package/dist/views/RootView.d.ts.map +1 -1
  16. package/dist/views/RootView.js +14 -10
  17. package/dist/views/RootView.js.map +1 -1
  18. package/dist/widgets/views/Dashboard/dashboardHelper.d.ts.map +1 -1
  19. package/dist/widgets/views/Dashboard/dashboardHelper.js +4 -2
  20. package/dist/widgets/views/Dashboard/dashboardHelper.js.map +1 -1
  21. package/dist/widgets/views/SearchTree.d.ts.map +1 -1
  22. package/dist/widgets/views/SearchTree.js +94 -11
  23. package/dist/widgets/views/SearchTree.js.map +1 -1
  24. package/dist/widgets/views/Tree.d.ts +2 -0
  25. package/dist/widgets/views/Tree.d.ts.map +1 -1
  26. package/dist/widgets/views/Tree.js +16 -8
  27. package/dist/widgets/views/Tree.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/actionbar/TreeActionBar.tsx +71 -55
  30. package/src/helpers/treeHelper.ts +2 -0
  31. package/src/types/index.ts +10 -0
  32. package/src/views/ActionView.tsx +7 -2
  33. package/src/views/RootView.tsx +22 -2
  34. package/src/widgets/views/Dashboard/dashboardHelper.ts +9 -1
  35. package/src/widgets/views/SearchTree.tsx +78 -3
  36. package/src/widgets/views/Tree.tsx +35 -18
@@ -22,6 +22,11 @@ import { getColorMap, getTree, sortResults } from "@/helpers/treeHelper";
22
22
  import useWindowDimensions from "@/hooks/useWindowDimensions";
23
23
  import Measure from "react-measure";
24
24
  import { mergeSearchFields } from "@/helpers/formHelper";
25
+ import {
26
+ ContentRootContext,
27
+ ContentRootContextType,
28
+ } from "@/context/ContentRootContext";
29
+ import showErrorDialog from "@/ui/ActionErrorDialog";
25
30
 
26
31
  const DEFAULT_SEARCH_LIMIT = 80;
27
32
 
@@ -96,6 +101,7 @@ function SearchTree(props: Props, ref: any) {
96
101
  const [searchFilterHeight, setSearchFilterHeight] = useState<number>(200);
97
102
 
98
103
  const originalResults = useRef<any[]>([]);
104
+ const expandableClickActionData = useRef<any>();
99
105
 
100
106
  const { height } = useWindowDimensions();
101
107
 
@@ -119,6 +125,11 @@ function SearchTree(props: Props, ref: any) {
119
125
  setTreeIsLoading = undefined,
120
126
  } = (rootTree ? actionViewContext : {}) || {};
121
127
 
128
+ const contentRootContext = useContext(
129
+ ContentRootContext
130
+ ) as ContentRootContextType;
131
+ const { processAction } = contentRootContext || {};
132
+
122
133
  useImperativeHandle(ref, () => ({
123
134
  refreshResults: () => {
124
135
  searchNameGetDoneRef.current = false;
@@ -168,7 +179,9 @@ function SearchTree(props: Props, ref: any) {
168
179
  model: currentModel!,
169
180
  ids: resultsIds,
170
181
  arch: treeView?.arch!,
171
- fields: Object.keys(treeView?.fields!),
182
+ fields: treeView!.field_parent
183
+ ? [...Object.keys(treeView!.fields), treeView!.field_parent]
184
+ : treeView!.fields,
172
185
  context: parentContext,
173
186
  attrs: colors && {
174
187
  colors,
@@ -254,7 +267,9 @@ function SearchTree(props: Props, ref: any) {
254
267
  limit,
255
268
  offset,
256
269
  model: currentModel!,
257
- fields: treeView!.fields,
270
+ fields: treeView!.field_parent
271
+ ? [...Object.keys(treeView!.fields), treeView!.field_parent]
272
+ : treeView!.fields,
258
273
  context: parentContext,
259
274
  attrs: colors && { colors },
260
275
  });
@@ -308,6 +323,23 @@ function SearchTree(props: Props, ref: any) {
308
323
  }
309
324
  };
310
325
 
326
+ async function onFetchChildrenForRecord(record: any) {
327
+ const child_id = record[treeView?.field_parent || "child_id"];
328
+
329
+ const children = await ConnectionProvider.getHandler().readObjects({
330
+ model: currentModel!,
331
+ ids: child_id,
332
+ fields: treeView!.field_parent
333
+ ? [...Object.keys(treeView!.fields), treeView!.field_parent]
334
+ : treeView!.fields,
335
+ context: parentContext,
336
+ });
337
+
338
+ setResults([...getResults(), ...children]);
339
+
340
+ return children;
341
+ }
342
+
311
343
  useEffect(() => {
312
344
  if (!initialFetchDone) {
313
345
  return;
@@ -430,8 +462,44 @@ function SearchTree(props: Props, ref: any) {
430
462
  internalLimit.current = newLimit;
431
463
  };
432
464
 
433
- const onRowClickedHandler = (record: any) => {
465
+ const treeButOpen = async (record: any) => {
466
+ const { id } = record;
467
+
468
+ if (!expandableClickActionData.current) {
469
+ expandableClickActionData.current = await ConnectionProvider.getHandler().treeButOpen(
470
+ {
471
+ id: treeView!.view_id,
472
+ model: currentModel!,
473
+ context: parentContext,
474
+ }
475
+ );
476
+ }
477
+
478
+ const actionData: any = expandableClickActionData.current[0][2];
479
+
480
+ await processAction?.({
481
+ actionData,
482
+ fields: treeView!.fields,
483
+ values: {
484
+ active_id: id,
485
+ ...record,
486
+ },
487
+ context: parentContext,
488
+ });
489
+ };
490
+
491
+ const onRowClickedHandler = async (record: any) => {
434
492
  const { id } = record;
493
+
494
+ if (treeView?.isExpandable) {
495
+ try {
496
+ await treeButOpen(record);
497
+ } catch (err) {
498
+ showErrorDialog(err);
499
+ }
500
+ return;
501
+ }
502
+
435
503
  onRowClicked({
436
504
  id,
437
505
  model: currentModel!,
@@ -449,6 +517,9 @@ function SearchTree(props: Props, ref: any) {
449
517
  }
450
518
 
451
519
  function calculateTableHeight() {
520
+ if (treeView?.isExpandable) {
521
+ return height - 160;
522
+ }
452
523
  return height - (searchFilterHeight + 210);
453
524
  }
454
525
 
@@ -522,6 +593,10 @@ function SearchTree(props: Props, ref: any) {
522
593
  : [...originalResults.current];
523
594
  setResults(sortedResults);
524
595
  }}
596
+ onFetchChildrenForRecord={
597
+ treeView.isExpandable ? onFetchChildrenForRecord : undefined
598
+ }
599
+ childField={treeView.field_parent}
525
600
  />
526
601
  </>
527
602
  );
@@ -10,7 +10,11 @@ import { calculateColumnsWidth } from "@/helpers/dynamicColumnsHelper";
10
10
  import { parseFloatToString } from "@/helpers/timeHelper";
11
11
  import { ProgressBarInput } from "../base/ProgressBar";
12
12
  import { Table as GisceTable } from "@gisce/react-formiga-table";
13
- import useDeepCompareEffect from "use-deep-compare-effect";
13
+ import {
14
+ PlusSquareOutlined,
15
+ MinusSquareOutlined,
16
+ LoadingOutlined,
17
+ } from "@ant-design/icons";
14
18
 
15
19
  type Props = {
16
20
  total: number;
@@ -27,6 +31,8 @@ type Props = {
27
31
  colorsForResults?: { [key: number]: string };
28
32
  onChangeSort?: (results: any) => void;
29
33
  sorter?: any;
34
+ onFetchChildrenForRecord?: (item: any) => Promise<any[]>;
35
+ childField?: string;
30
36
  };
31
37
 
32
38
  const booleanComponentFn = (value: boolean): React.ReactElement => {
@@ -100,6 +106,8 @@ function Tree(props: Props): React.ReactElement {
100
106
  colorsForResults = {},
101
107
  onChangeSort,
102
108
  sorter,
109
+ onFetchChildrenForRecord,
110
+ childField,
103
111
  } = props;
104
112
 
105
113
  const [items, setItems] = useState<Array<any>>([]);
@@ -148,27 +156,25 @@ function Tree(props: Props): React.ReactElement {
148
156
  .replace("{total}", total?.toString());
149
157
 
150
158
  const pagination = () => {
151
- if (!showPagination) {
159
+ if (!showPagination || treeView.isExpandable) {
152
160
  return null;
153
161
  }
154
162
 
155
163
  return loading ? null : (
156
- <>
157
- <Row align="bottom" className="pb-4">
158
- <Col span={12}>
159
- <Pagination
160
- total={total}
161
- pageSize={limit}
162
- current={page}
163
- showSizeChanger={false}
164
- onChange={onRequestPageChange}
165
- />
166
- </Col>
167
- <Col span={12} className="text-right">
168
- {summary}
169
- </Col>
170
- </Row>
171
- </>
164
+ <Row align="bottom" className="pb-4">
165
+ <Col span={12}>
166
+ <Pagination
167
+ total={total}
168
+ pageSize={limit}
169
+ current={page}
170
+ showSizeChanger={false}
171
+ onChange={onRequestPageChange}
172
+ />
173
+ </Col>
174
+ <Col span={12} className="text-right">
175
+ {summary}
176
+ </Col>
177
+ </Row>
172
178
  );
173
179
  };
174
180
 
@@ -244,6 +250,17 @@ function Tree(props: Props): React.ReactElement {
244
250
  onRowSelectionChange={rowSelection?.onChange}
245
251
  onChangeSort={onChangeSort}
246
252
  sorter={sorter}
253
+ expandableOpts={
254
+ onFetchChildrenForRecord
255
+ ? {
256
+ expandIcon: PlusSquareOutlined,
257
+ collapseIcon: MinusSquareOutlined,
258
+ loadingIcon: LoadingOutlined,
259
+ onFetchChildrenForRecord,
260
+ childField: childField!,
261
+ }
262
+ : undefined
263
+ }
247
264
  />
248
265
  {getSums()}
249
266
  </div>