@gisce/react-ooui 1.0.18 → 1.1.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 (112) hide show
  1. package/dist/actionbar/ChangeViewButton.d.ts +3 -2
  2. package/dist/actionbar/ChangeViewButton.d.ts.map +1 -1
  3. package/dist/actionbar/FormActionBar.d.ts +3 -1
  4. package/dist/actionbar/FormActionBar.d.ts.map +1 -1
  5. package/dist/actionbar/GraphActionBar.d.ts +6 -0
  6. package/dist/actionbar/GraphActionBar.d.ts.map +1 -0
  7. package/dist/actionbar/TreeActionBar.d.ts +2 -1
  8. package/dist/actionbar/TreeActionBar.d.ts.map +1 -1
  9. package/dist/context/ActionViewContext.d.ts +7 -3
  10. package/dist/context/ActionViewContext.d.ts.map +1 -1
  11. package/dist/context/One2manyContext.d.ts +4 -4
  12. package/dist/context/One2manyContext.d.ts.map +1 -1
  13. package/dist/context/TabManagerContext.d.ts +2 -3
  14. package/dist/context/TabManagerContext.d.ts.map +1 -1
  15. package/dist/helpers/searchHelper.d.ts +6 -0
  16. package/dist/helpers/searchHelper.d.ts.map +1 -0
  17. package/dist/hooks/useSearch.d.ts +52 -0
  18. package/dist/hooks/useSearch.d.ts.map +1 -0
  19. package/dist/locales/ca_ES.d.ts +1 -0
  20. package/dist/locales/ca_ES.d.ts.map +1 -1
  21. package/dist/locales/en_US.d.ts +1 -0
  22. package/dist/locales/en_US.d.ts.map +1 -1
  23. package/dist/locales/es_ES.d.ts +1 -0
  24. package/dist/locales/es_ES.d.ts.map +1 -1
  25. package/dist/react-ooui.es.js +4915 -4469
  26. package/dist/react-ooui.es.js.map +1 -1
  27. package/dist/react-ooui.umd.js +14 -14
  28. package/dist/react-ooui.umd.js.map +1 -1
  29. package/dist/types/index.d.ts +29 -3
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/ui/TitleHeader.d.ts +1 -0
  32. package/dist/ui/TitleHeader.d.ts.map +1 -1
  33. package/dist/views/ActionView.d.ts +3 -7
  34. package/dist/views/ActionView.d.ts.map +1 -1
  35. package/dist/views/RootView.d.ts.map +1 -1
  36. package/dist/views/actionViews/DashboardActionView.d.ts +7 -0
  37. package/dist/views/actionViews/DashboardActionView.d.ts.map +1 -0
  38. package/dist/views/actionViews/FormActionView.d.ts +18 -0
  39. package/dist/views/actionViews/FormActionView.d.ts.map +1 -0
  40. package/dist/views/actionViews/GraphActionView.d.ts +13 -0
  41. package/dist/views/actionViews/GraphActionView.d.ts.map +1 -0
  42. package/dist/views/actionViews/TreeActionView.d.ts +19 -0
  43. package/dist/views/actionViews/TreeActionView.d.ts.map +1 -0
  44. package/dist/widgets/base/one2many/One2many.d.ts +0 -1
  45. package/dist/widgets/base/one2many/One2many.d.ts.map +1 -1
  46. package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
  47. package/dist/widgets/base/one2many/One2manyTopBar.d.ts +2 -2
  48. package/dist/widgets/base/one2many/One2manyTopBar.d.ts.map +1 -1
  49. package/dist/widgets/containers/Container.d.ts.map +1 -1
  50. package/dist/widgets/custom/ButtonGroup.d.ts.map +1 -1
  51. package/dist/widgets/views/Dashboard/Dashboard.d.ts +1 -1
  52. package/dist/widgets/views/Dashboard/Dashboard.d.ts.map +1 -1
  53. package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
  54. package/dist/widgets/views/Form.d.ts.map +1 -1
  55. package/dist/widgets/views/Graph/Graph.d.ts +3 -3
  56. package/dist/widgets/views/Graph/Graph.d.ts.map +1 -1
  57. package/dist/widgets/views/Graph/GraphChart.d.ts +1 -1
  58. package/dist/widgets/views/Graph/GraphChart.d.ts.map +1 -1
  59. package/dist/widgets/views/Graph/useGraphData.d.ts +1 -1
  60. package/dist/widgets/views/Graph/useGraphData.d.ts.map +1 -1
  61. package/dist/widgets/views/SearchTree.d.ts.map +1 -1
  62. package/dist/widgets/views/searchFilter/SearchFilter.d.ts +4 -0
  63. package/dist/widgets/views/searchFilter/SearchFilter.d.ts.map +1 -1
  64. package/package.json +3 -3
  65. package/src/actionbar/ChangeViewButton.tsx +34 -39
  66. package/src/actionbar/FormActionBar.tsx +6 -6
  67. package/src/actionbar/GraphActionBar.tsx +67 -0
  68. package/src/actionbar/TreeActionBar.tsx +10 -11
  69. package/src/context/ActionViewContext.tsx +27 -8
  70. package/src/context/One2manyContext.tsx +5 -5
  71. package/src/context/TabManagerContext.tsx +2 -3
  72. package/src/helpers/{searchFilterHelper.ts → searchHelper.ts} +32 -7
  73. package/src/hooks/useFetchViews.ts +0 -0
  74. package/src/hooks/useSearch.ts +404 -0
  75. package/src/locales/ca_ES.tsx +1 -0
  76. package/src/locales/en_US.tsx +1 -0
  77. package/src/locales/es_ES.tsx +1 -0
  78. package/src/stories/forms/ActivacioContracteForm.stories.tsx +25 -0
  79. package/src/stories/mocks/index.ts +2 -0
  80. package/src/stories/mocks/models/activacioContracte.ts +112 -0
  81. package/src/types/index.ts +37 -3
  82. package/src/ui/FavouriteButton.tsx +2 -2
  83. package/src/ui/TitleHeader.tsx +4 -3
  84. package/src/views/ActionView.tsx +185 -171
  85. package/src/views/RootView.tsx +5 -6
  86. package/src/views/actionViews/DashboardActionView.tsx +47 -0
  87. package/src/views/actionViews/FormActionView.tsx +70 -0
  88. package/src/views/actionViews/GraphActionView.tsx +136 -0
  89. package/src/views/actionViews/TreeActionView.tsx +77 -0
  90. package/src/widgets/base/Button.tsx +1 -1
  91. package/src/widgets/base/Image.tsx +1 -1
  92. package/src/widgets/base/many2one/Many2oneSuffix.tsx +1 -1
  93. package/src/widgets/base/one2many/One2many.tsx +5 -7
  94. package/src/widgets/base/one2many/One2manyInput.tsx +5 -7
  95. package/src/widgets/base/one2many/One2manyTopBar.tsx +5 -5
  96. package/src/widgets/containers/Container.tsx +2 -4
  97. package/src/widgets/containers/Notebook.tsx +1 -1
  98. package/src/widgets/custom/ButtonGroup.tsx +15 -14
  99. package/src/widgets/custom/Indicator.tsx +2 -2
  100. package/src/widgets/views/Dashboard/Dashboard.tsx +4 -5
  101. package/src/widgets/views/Dashboard/DashboardTree.tsx +15 -18
  102. package/src/widgets/views/Form.tsx +0 -1
  103. package/src/widgets/views/Graph/Graph.tsx +40 -6
  104. package/src/widgets/views/Graph/GraphChart.tsx +1 -1
  105. package/src/widgets/views/Graph/useGraphData.tsx +2 -2
  106. package/src/widgets/views/SearchTree.tsx +81 -331
  107. package/src/widgets/views/searchFilter/SearchFilter.tsx +58 -23
  108. package/dist/helpers/searchFilterHelper.d.ts +0 -5
  109. package/dist/helpers/searchFilterHelper.d.ts.map +0 -1
  110. package/dist/widgets/views/Dashboard/Dashboard.types.d.ts +0 -8
  111. package/dist/widgets/views/Dashboard/Dashboard.types.d.ts.map +0 -1
  112. package/src/widgets/views/Dashboard/Dashboard.types.ts +0 -8
@@ -1,4 +1,10 @@
1
- import React, { useState, useEffect } from "react";
1
+ import React, {
2
+ useState,
3
+ useEffect,
4
+ useContext,
5
+ forwardRef,
6
+ useImperativeHandle,
7
+ } from "react";
2
8
  import {
3
9
  Graph as GraphOoui,
4
10
  parseGraph,
@@ -9,20 +15,35 @@ import { LoadingOutlined } from "@ant-design/icons";
9
15
  import ConnectionProvider from "@/ConnectionProvider";
10
16
  import { GraphIndicator } from "./GraphIndicator";
11
17
  import { GraphChart } from "./GraphChart";
18
+ import { GraphView } from "@/types";
19
+ import {
20
+ ActionViewContext,
21
+ ActionViewContextType,
22
+ } from "@/context/ActionViewContext";
12
23
 
13
24
  export type GraphProps = {
14
25
  view_id: number;
15
26
  model: string;
16
27
  domain: any;
17
28
  context: any;
18
- limit: number;
29
+ limit?: number;
19
30
  };
20
31
 
21
- export const Graph = (props: GraphProps) => {
32
+ const GraphComp = (props: GraphProps, ref: any) => {
22
33
  const { view_id, model, context, domain, limit } = props;
23
34
  const [loading, setLoading] = useState(false);
24
35
  const [graphOoui, setGraphOoui] = useState<GraphOoui>();
25
36
  const [graphXml, setGraphXml] = useState<string>();
37
+ const actionViewContext = useContext(
38
+ ActionViewContext
39
+ ) as ActionViewContextType;
40
+ const { setGraphIsLoading = undefined } = actionViewContext || {};
41
+
42
+ useImperativeHandle(ref, () => ({
43
+ refresh: () => {
44
+ fetchData();
45
+ },
46
+ }));
26
47
 
27
48
  useEffect(() => {
28
49
  fetchData();
@@ -30,14 +51,15 @@ export const Graph = (props: GraphProps) => {
30
51
 
31
52
  async function fetchData() {
32
53
  setLoading(true);
54
+ setGraphIsLoading?.(true);
33
55
 
34
56
  try {
35
- const viewData = await ConnectionProvider.getHandler().getView({
57
+ const viewData = (await ConnectionProvider.getHandler().getView({
36
58
  model,
37
59
  id: view_id,
38
60
  type: "graph",
39
61
  context,
40
- });
62
+ })) as GraphView;
41
63
 
42
64
  setGraphXml(viewData.arch);
43
65
  const graph = parseGraph(viewData.arch);
@@ -48,11 +70,21 @@ export const Graph = (props: GraphProps) => {
48
70
  }
49
71
 
50
72
  setLoading(false);
73
+ setGraphIsLoading?.(false);
51
74
  }
52
75
 
53
76
  if (loading) {
54
77
  return (
55
- <div style={{ padding: "1rem" }}>
78
+ <div
79
+ style={{
80
+ width: "100%",
81
+ display: "flex",
82
+ height: "20%",
83
+ justifyContent: "center",
84
+ alignContent: "center",
85
+ padding: "1rem",
86
+ }}
87
+ >
56
88
  <LoadingOutlined style={{ height: "12px" }} />
57
89
  </div>
58
90
  );
@@ -106,3 +138,5 @@ export const Graph = (props: GraphProps) => {
106
138
  }
107
139
  }
108
140
  };
141
+
142
+ export const Graph = forwardRef(GraphComp);
@@ -16,7 +16,7 @@ export type GraphChartProps = {
16
16
  domain: any;
17
17
  context: any;
18
18
  xml: string;
19
- limit: number;
19
+ limit?: number;
20
20
  };
21
21
 
22
22
  export const GraphChart = (props: GraphChartProps) => {
@@ -16,7 +16,7 @@ export type GraphDataQueryOpts = {
16
16
  model: string;
17
17
  domain?: any;
18
18
  context?: any;
19
- limit: number;
19
+ limit?: number;
20
20
  };
21
21
 
22
22
  export type GraphDataOpts = GraphDataQueryOpts & {
@@ -126,7 +126,7 @@ async function retrieveData({
126
126
  domain: any;
127
127
  context: any;
128
128
  order: string | null;
129
- limit: number;
129
+ limit?: number;
130
130
  }) {
131
131
  const values: any[] = (await ConnectionProvider.getHandler().search({
132
132
  model,
@@ -5,7 +5,6 @@ import React, {
5
5
  useContext,
6
6
  forwardRef,
7
7
  useImperativeHandle,
8
- useCallback,
9
8
  } from "react";
10
9
  import { Alert, Spin } from "antd";
11
10
 
@@ -18,22 +17,14 @@ import {
18
17
  ActionViewContext,
19
18
  ActionViewContextType,
20
19
  } from "@/context/ActionViewContext";
21
- import {
22
- getColorMap,
23
- getTableItems,
24
- getTree,
25
- sortResults,
26
- } from "@/helpers/treeHelper";
27
20
  import useWindowDimensions from "@/hooks/useWindowDimensions";
28
- import Measure from "react-measure";
29
21
  import { mergeSearchFields } from "@/helpers/formHelper";
30
22
  import {
31
23
  ContentRootContext,
32
24
  ContentRootContextType,
33
25
  } from "@/context/ContentRootContext";
34
26
  import showErrorDialog from "@/ui/ActionErrorDialog";
35
-
36
- const DEFAULT_SEARCH_LIMIT = 80;
27
+ import { DEFAULT_SEARCH_LIMIT, useSearch } from "@/hooks/useSearch";
37
28
 
38
29
  type OnRowClickedData = {
39
30
  id: number;
@@ -83,33 +74,23 @@ function SearchTree(props: Props, ref: any) {
83
74
  const [treeView, setTreeView] = useState<TreeView>();
84
75
  const [formView, setFormView] = useState<FormView>();
85
76
 
86
- const [page, setPage] = useState<number>(1);
87
- const [offset, setOffset] = useState<number>(0);
88
- const [limit, setLimit] = useState<number>(DEFAULT_SEARCH_LIMIT);
89
77
  const [limitFromAction, setLimitFromAction] = useState<number>();
78
+ const [limit, setLimit] = useState<number>(DEFAULT_SEARCH_LIMIT);
90
79
 
91
- const paramsRef = useRef<Array<any>>([]);
92
-
93
- const [totalItems, setTotalItems] = useState<number>();
94
- const [resultsInternal, setResultsInternal] = useState<any>([]);
95
- const [colorsForResults, setColorsForResults] = useState<any>(undefined);
96
-
97
- const [searchFilterLoading, setSearchFilterLoading] = useState<boolean>(
98
- false
99
- );
100
- const [searchError, setSearchError] = useState<string>();
101
80
  const [initialError, setInitialError] = useState<string>();
102
81
 
103
- const [tableRefreshing, setTableRefreshing] = useState<boolean>(false);
104
-
105
82
  const actionDomain = useRef<any>([]);
106
83
  const [searchFilterHeight, setSearchFilterHeight] = useState<number>(200);
107
84
 
108
- const originalResults = useRef<any[]>([]);
109
85
  const expandableClickActionData = useRef<any>();
110
86
 
111
87
  const { height } = useWindowDimensions();
112
88
 
89
+ const contentRootContext = useContext(
90
+ ContentRootContext
91
+ ) as ContentRootContextType;
92
+ const { processAction } = contentRootContext || {};
93
+
113
94
  const actionViewContext = useContext(
114
95
  ActionViewContext
115
96
  ) as ActionViewContextType;
@@ -120,6 +101,7 @@ function SearchTree(props: Props, ref: any) {
120
101
  results: resultsActionView = undefined,
121
102
  selectedRowItems = undefined,
122
103
  setSelectedRowItems = undefined,
104
+ searchParams = [],
123
105
  setSearchParams = undefined,
124
106
  searchVisible = true,
125
107
  setSearchVisible = undefined,
@@ -128,12 +110,51 @@ function SearchTree(props: Props, ref: any) {
128
110
  setTotalItems: setActionViewTotalItems = undefined,
129
111
  setSearchTreeNameSearch = undefined,
130
112
  setTreeIsLoading = undefined,
113
+ searchValues = {},
114
+ setSearchValues = undefined,
131
115
  } = (rootTree ? actionViewContext : {}) || {};
132
116
 
133
- const contentRootContext = useContext(
134
- ContentRootContext
135
- ) as ContentRootContextType;
136
- const { processAction } = contentRootContext || {};
117
+ const {
118
+ submit,
119
+ clear,
120
+ fetchResults,
121
+ tableRefreshing,
122
+ searchFilterLoading,
123
+ searchError,
124
+ page,
125
+ offset,
126
+ getResults,
127
+ requestPageChange,
128
+ changeSort,
129
+ fetchChildrenForRecord,
130
+ colorsForResults,
131
+ totalItems,
132
+ } = useSearch({
133
+ model: currentModel!,
134
+ setSearchTreeNameSearch,
135
+ setSelectedRowItems,
136
+ setSearchParams,
137
+ setSearchValues,
138
+ searchParams,
139
+ setSearchVisible,
140
+ setTreeIsLoading,
141
+ nameSearch,
142
+ searchNameGetDoneRef,
143
+ context: parentContext,
144
+ formView: formView!,
145
+ treeView: treeView!,
146
+ sorter,
147
+ setSorter,
148
+ setCurrentItemIndex,
149
+ setResultsActionView,
150
+ resultsActionView,
151
+ domain,
152
+ currentId,
153
+ setActionViewTotalItems,
154
+ limitFromAction,
155
+ setLimit,
156
+ limit,
157
+ });
137
158
 
138
159
  useImperativeHandle(ref, () => ({
139
160
  refreshResults: () => {
@@ -142,212 +163,6 @@ function SearchTree(props: Props, ref: any) {
142
163
  },
143
164
  }));
144
165
 
145
- const onRequestPageChange = (page: number) => {
146
- setTableRefreshing(true);
147
- setPage(page);
148
- setOffset((page - 1) * limit!);
149
- };
150
-
151
- function setResults(results: any) {
152
- setResultsActionView?.([...results]);
153
- setResultsInternal([...results]);
154
- }
155
-
156
- const getResults = useCallback(() => {
157
- if (!resultsActionView) {
158
- return resultsInternal;
159
- }
160
- return resultsActionView;
161
- }, [resultsActionView, resultsInternal]);
162
-
163
- const searchByNameSearch = async () => {
164
- const searchResults = await ConnectionProvider.getHandler().nameSearch({
165
- model: currentModel!,
166
- payload: nameSearch,
167
- limit: internalLimit.current,
168
- attrs: actionDomain.current.length > 0 ? actionDomain.current : domain,
169
- context: parentContext,
170
- });
171
-
172
- setTotalItems(searchResults.length);
173
- setActionViewTotalItems?.(searchResults.length);
174
-
175
- if (searchResults.length > 0) {
176
- const resultsIds = searchResults.map((item: any) => {
177
- return item?.[0];
178
- });
179
-
180
- const { colors } = getTree(treeView!);
181
-
182
- const resultsWithData = await ConnectionProvider.getHandler().readEvalUiObjects(
183
- {
184
- model: currentModel!,
185
- ids: resultsIds,
186
- arch: treeView?.arch!,
187
- fields: treeView!.field_parent
188
- ? { ...treeView!.fields, [treeView!.field_parent]: {} }
189
- : treeView!.fields,
190
- context: parentContext,
191
- attrs: colors && {
192
- colors,
193
- },
194
- }
195
- );
196
- const resultsData = resultsWithData[0];
197
-
198
- originalResults.current = [...resultsData];
199
-
200
- setColorsForResults(getColorMap(resultsWithData[1]));
201
-
202
- const newResultIds = resultsData.map((item: any) => item.id);
203
-
204
- const resultsSorted =
205
- sorter !== undefined
206
- ? sortResults({
207
- resultsToSort: resultsData,
208
- sorter,
209
- fields: { ...treeView!.fields, ...formView!.fields },
210
- })
211
- : [...originalResults.current];
212
-
213
- setResults(resultsSorted);
214
-
215
- if (newResultIds.length > 0) {
216
- setCurrentItemIndex?.(0);
217
- } else {
218
- setCurrentItemIndex?.(undefined);
219
- }
220
- } else {
221
- setResults([]);
222
- setCurrentItemIndex?.(undefined);
223
- }
224
-
225
- searchNameGetDoneRef.current = true;
226
- };
227
-
228
- const getUniqueFieldsForParams = (params: any[]) => {
229
- const uniqueFields: any = {};
230
-
231
- params.forEach((param) => {
232
- if (Array.isArray(param) && param[0]) {
233
- uniqueFields[param[0]] = true;
234
- } else {
235
- uniqueFields[param] = true;
236
- }
237
- });
238
-
239
- return Object.keys(uniqueFields);
240
- };
241
-
242
- const mergeParams = (searchParams: any[], domainParams: any[]) => {
243
- const finalParams = searchParams;
244
- const uniqueParams = getUniqueFieldsForParams(searchParams);
245
-
246
- domainParams.forEach((element) => {
247
- if (Array.isArray(element) && element[0]) {
248
- if (!uniqueParams.includes(element[0])) {
249
- finalParams.push(element);
250
- }
251
- } else if (!uniqueParams.includes(element)) {
252
- finalParams.push(element);
253
- }
254
- });
255
-
256
- return finalParams;
257
- };
258
-
259
- const searchResults = async () => {
260
- const domainParams =
261
- actionDomain.current.length > 0 ? actionDomain.current : domain;
262
-
263
- const searchParams = mergeParams(paramsRef.current, domainParams);
264
- const { colors } = getTree(treeView!);
265
-
266
- const {
267
- totalItems,
268
- results,
269
- attrsEvaluated,
270
- } = await ConnectionProvider.getHandler().searchForTree({
271
- params: searchParams,
272
- limit,
273
- offset,
274
- model: currentModel!,
275
- fields: treeView!.field_parent
276
- ? { ...treeView!.fields, [treeView!.field_parent]: {} }
277
- : treeView!.fields,
278
- context: parentContext,
279
- attrs: colors && { colors },
280
- });
281
- setColorsForResults(getColorMap(attrsEvaluated));
282
-
283
- originalResults.current = [...results];
284
-
285
- const resultsSorted =
286
- sorter !== undefined
287
- ? sortResults({
288
- resultsToSort: results,
289
- sorter: sorter,
290
- fields: { ...treeView!.fields, ...formView!.fields },
291
- })
292
- : [...originalResults.current];
293
-
294
- totalItems.then((value) => {
295
- setTotalItems(value);
296
- setActionViewTotalItems?.(value);
297
- });
298
-
299
- setResults(resultsSorted);
300
-
301
- if (resultsActionView && resultsSorted.length > 0) {
302
- const newCurrentItemIndex = resultsSorted.findIndex(
303
- (item) => currentId === item.id
304
- );
305
-
306
- if (newCurrentItemIndex === -1) {
307
- setCurrentItemIndex?.(0);
308
- } else {
309
- setCurrentItemIndex?.(newCurrentItemIndex);
310
- }
311
- } else {
312
- setCurrentItemIndex?.(undefined);
313
- }
314
- };
315
-
316
- const fetchResults = async () => {
317
- try {
318
- setTableRefreshing(true);
319
- setTreeIsLoading?.(true);
320
- if (nameSearch && !searchNameGetDoneRef.current) {
321
- await searchByNameSearch();
322
- } else {
323
- await searchResults();
324
- }
325
- } catch (error) {
326
- setSearchError(error);
327
- } finally {
328
- setTableRefreshing(false);
329
- setSearchFilterLoading(false);
330
- setTreeIsLoading?.(false);
331
- }
332
- };
333
-
334
- async function onFetchChildrenForRecord(record: any) {
335
- const child_id = record[treeView?.field_parent || "child_id"];
336
-
337
- const children = await ConnectionProvider.getHandler().readObjects({
338
- model: currentModel!,
339
- ids: child_id,
340
- fields: treeView!.field_parent
341
- ? { ...treeView!.fields, [treeView!.field_parent]: {} }
342
- : treeView!.fields,
343
- context: parentContext,
344
- });
345
-
346
- setResults([...getResults(), ...children]);
347
-
348
- return getTableItems(getTree(treeView!), children);
349
- }
350
-
351
166
  useEffect(() => {
352
167
  if (!initialFetchDone) {
353
168
  return;
@@ -381,12 +196,11 @@ function SearchTree(props: Props, ref: any) {
381
196
  };
382
197
 
383
198
  const fetchActionData = async () => {
384
- const dataForAction = await ConnectionProvider.getHandler().getViewsForAction(
385
- {
199
+ const dataForAction =
200
+ await ConnectionProvider.getHandler().getViewsForAction({
386
201
  action: action!,
387
202
  context: parentContext,
388
- }
389
- );
203
+ });
390
204
  actionDomain.current = dataForAction.domain;
391
205
  setFormView(dataForAction.views.get("form"));
392
206
  setTreeView(dataForAction.views.get("tree"));
@@ -432,40 +246,6 @@ function SearchTree(props: Props, ref: any) {
432
246
  }
433
247
  }, [action, model]);
434
248
 
435
- const onClear = () => {
436
- if (tableRefreshing) return;
437
- setSearchTreeNameSearch?.(undefined);
438
- paramsRef.current = [];
439
- setSearchParams?.([]);
440
- setSearchError(undefined);
441
- setOffset(0);
442
- setPage(1);
443
- setLimit(limitFromAction || DEFAULT_SEARCH_LIMIT);
444
- };
445
-
446
- const onSubmit = ({
447
- params: newParams,
448
- limit: newLimit,
449
- offset: newOffset,
450
- }: {
451
- params: any;
452
- limit: number;
453
- offset: number;
454
- }) => {
455
- if (tableRefreshing) return;
456
- paramsRef.current = newParams;
457
- setSearchTreeNameSearch?.(undefined);
458
- setSelectedRowItems?.([]);
459
- setSearchParams?.(newParams);
460
- setSearchVisible?.(false);
461
- setSearchFilterLoading(true);
462
- setSearchError(undefined);
463
- setPage(1);
464
- if (newLimit) setLimit(newLimit);
465
- if (newOffset) setOffset(newOffset);
466
- fetchResults();
467
- };
468
-
469
249
  const onSearchTreeLimitChange = (newLimit: number) => {
470
250
  internalLimit.current = newLimit;
471
251
  };
@@ -474,13 +254,12 @@ function SearchTree(props: Props, ref: any) {
474
254
  const { id } = record;
475
255
 
476
256
  if (!expandableClickActionData.current) {
477
- expandableClickActionData.current = await ConnectionProvider.getHandler().treeButOpen(
478
- {
257
+ expandableClickActionData.current =
258
+ await ConnectionProvider.getHandler().treeButOpen({
479
259
  id: treeView!.view_id,
480
260
  model: currentModel!,
481
261
  context: parentContext,
482
- }
483
- );
262
+ });
484
263
  }
485
264
 
486
265
  const actionData: any = expandableClickActionData.current[0][2];
@@ -538,48 +317,30 @@ function SearchTree(props: Props, ref: any) {
538
317
 
539
318
  return (
540
319
  <>
541
- <Measure
542
- bounds
543
- onResize={(contentRect) => {
544
- setSearchFilterHeight(contentRect.bounds?.height!);
545
- }}
546
- >
547
- {({ measureRef }) => (
548
- <div ref={measureRef}>
549
- <div style={{ display: searchVisible ? "block" : "none" }}>
550
- <SearchFilter
551
- fields={{ ...treeView.fields, ...formView.fields }}
552
- searchFields={mergeSearchFields([
553
- formView.search_fields,
554
- treeView.search_fields,
555
- ])}
556
- onClear={onClear}
557
- limit={limit}
558
- offset={offset}
559
- isSearching={searchFilterLoading}
560
- onSubmit={onSubmit}
561
- onLimitChange={onSearchTreeLimitChange}
562
- />
563
- {searchError && (
564
- <Alert
565
- className="mt-10"
566
- message={searchError}
567
- type="error"
568
- banner
569
- />
570
- )}
571
- <div className="pb-5" />
572
- </div>
573
- </div>
574
- )}
575
- </Measure>
320
+ <SearchFilter
321
+ fields={{ ...treeView.fields, ...formView.fields }}
322
+ searchFields={mergeSearchFields([
323
+ formView.search_fields,
324
+ treeView.search_fields,
325
+ ])}
326
+ onClear={clear}
327
+ limit={limit}
328
+ offset={offset}
329
+ isSearching={searchFilterLoading}
330
+ onSubmit={submit}
331
+ onLimitChange={onSearchTreeLimitChange}
332
+ setSearchFilterHeight={setSearchFilterHeight}
333
+ searchError={searchError}
334
+ searchVisible={searchVisible}
335
+ searchValues={searchValues}
336
+ />
576
337
  <Tree
577
338
  total={totalItems}
578
339
  limit={limit}
579
340
  page={page}
580
341
  treeView={treeView}
581
342
  results={getResults()}
582
- onRequestPageChange={onRequestPageChange}
343
+ onRequestPageChange={requestPageChange}
583
344
  loading={tableRefreshing}
584
345
  onRowClicked={onRowClickedHandler}
585
346
  scrollY={treeScrollY || calculateTableHeight()}
@@ -589,20 +350,9 @@ function SearchTree(props: Props, ref: any) {
589
350
  onChange: changeSelectedRowKeys,
590
351
  }}
591
352
  sorter={sorter}
592
- onChangeSort={(newSorter) => {
593
- setSorter?.(newSorter);
594
- const sortedResults =
595
- newSorter !== undefined
596
- ? sortResults({
597
- resultsToSort: getResults(),
598
- sorter: newSorter,
599
- fields: { ...treeView.fields, ...formView.fields },
600
- })
601
- : [...originalResults.current];
602
- setResults(sortedResults);
603
- }}
353
+ onChangeSort={changeSort}
604
354
  onFetchChildrenForRecord={
605
- treeView.isExpandable ? onFetchChildrenForRecord : undefined
355
+ treeView.isExpandable ? fetchChildrenForRecord : undefined
606
356
  }
607
357
  childField={treeView.field_parent}
608
358
  />
@@ -610,10 +360,10 @@ function SearchTree(props: Props, ref: any) {
610
360
  );
611
361
  };
612
362
 
613
- if (initialError) {
614
- return (
615
- <Alert className="mt-10" message={initialError} type="error" banner />
616
- );
363
+ const error = initialError || searchError;
364
+
365
+ if (error) {
366
+ return <Alert className="mt-10" message={error} type="error" banner />;
617
367
  }
618
368
 
619
369
  return (