@gisce/react-ooui 0.8.7 → 0.9.2
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.
- package/dist/actionbar/TreeActionBar.d.ts +1 -0
- package/dist/actionbar/TreeActionBar.d.ts.map +1 -1
- package/dist/actionbar/TreeActionBar.js +25 -22
- package/dist/actionbar/TreeActionBar.js.map +1 -1
- package/dist/helpers/treeHelper.d.ts.map +1 -1
- package/dist/helpers/treeHelper.js +3 -0
- package/dist/helpers/treeHelper.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/types/index.d.ts +9 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/views/ActionView.d.ts +1 -0
- package/dist/views/ActionView.d.ts.map +1 -1
- package/dist/views/ActionView.js +31 -20
- package/dist/views/ActionView.js.map +1 -1
- package/dist/views/RootView.d.ts.map +1 -1
- package/dist/views/RootView.js +14 -10
- package/dist/views/RootView.js.map +1 -1
- package/dist/widgets/views/Dashboard/dashboardHelper.d.ts.map +1 -1
- package/dist/widgets/views/Dashboard/dashboardHelper.js +4 -2
- package/dist/widgets/views/Dashboard/dashboardHelper.js.map +1 -1
- package/dist/widgets/views/SearchTree.d.ts.map +1 -1
- package/dist/widgets/views/SearchTree.js +105 -19
- package/dist/widgets/views/SearchTree.js.map +1 -1
- package/dist/widgets/views/Tree.d.ts +2 -0
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/dist/widgets/views/Tree.js +17 -9
- package/dist/widgets/views/Tree.js.map +1 -1
- package/package.json +2 -2
- package/src/actionbar/TreeActionBar.tsx +71 -55
- package/src/helpers/treeHelper.ts +2 -0
- package/src/types/index.ts +10 -0
- package/src/views/ActionView.tsx +7 -2
- package/src/views/RootView.tsx +22 -2
- package/src/widgets/views/Dashboard/dashboardHelper.ts +9 -1
- package/src/widgets/views/SearchTree.tsx +78 -3
- package/src/widgets/views/Tree.tsx +36 -19
package/src/views/ActionView.tsx
CHANGED
|
@@ -45,6 +45,7 @@ type Props = {
|
|
|
45
45
|
res_id?: number | boolean;
|
|
46
46
|
action_id: number;
|
|
47
47
|
action_type: string;
|
|
48
|
+
treeExpandable?: boolean;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
export type View = {
|
|
@@ -67,6 +68,7 @@ function ActionView(props: Props, ref: any) {
|
|
|
67
68
|
res_id = false,
|
|
68
69
|
action_id,
|
|
69
70
|
action_type,
|
|
71
|
+
treeExpandable = false,
|
|
70
72
|
} = props;
|
|
71
73
|
const [currentView, setCurrentViewInternal] = useState<View>();
|
|
72
74
|
const [availableViews, setAvailableViews] = useState<View[]>([]);
|
|
@@ -183,7 +185,7 @@ function ActionView(props: Props, ref: any) {
|
|
|
183
185
|
});
|
|
184
186
|
|
|
185
187
|
if (viewType === "tree") {
|
|
186
|
-
setTreeView(viewData);
|
|
188
|
+
setTreeView({ ...viewData, isExpandable: treeExpandable });
|
|
187
189
|
} else if (viewType === "form") {
|
|
188
190
|
setFormView(viewData);
|
|
189
191
|
setToolbar((viewData as any)?.toolbar);
|
|
@@ -404,7 +406,10 @@ function ActionView(props: Props, ref: any) {
|
|
|
404
406
|
{currentView!.type === "form" ? (
|
|
405
407
|
<FormActionBar />
|
|
406
408
|
) : (
|
|
407
|
-
<TreeActionBar
|
|
409
|
+
<TreeActionBar
|
|
410
|
+
parentContext={context}
|
|
411
|
+
treeExpandable={treeView?.isExpandable || false}
|
|
412
|
+
/>
|
|
408
413
|
)}
|
|
409
414
|
</TitleHeader>
|
|
410
415
|
{content()}
|
package/src/views/RootView.tsx
CHANGED
|
@@ -116,7 +116,15 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
116
116
|
})
|
|
117
117
|
: [];
|
|
118
118
|
|
|
119
|
-
const {
|
|
119
|
+
const {
|
|
120
|
+
res_model: model,
|
|
121
|
+
views,
|
|
122
|
+
name: title,
|
|
123
|
+
target,
|
|
124
|
+
view_type,
|
|
125
|
+
} = dataForAction;
|
|
126
|
+
|
|
127
|
+
const treeExpandable = view_type === "tree";
|
|
120
128
|
|
|
121
129
|
const finalViews = [];
|
|
122
130
|
|
|
@@ -165,6 +173,7 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
165
173
|
values,
|
|
166
174
|
forced_values,
|
|
167
175
|
res_id,
|
|
176
|
+
treeExpandable,
|
|
168
177
|
});
|
|
169
178
|
}
|
|
170
179
|
|
|
@@ -273,7 +282,14 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
273
282
|
})
|
|
274
283
|
: [];
|
|
275
284
|
|
|
276
|
-
const {
|
|
285
|
+
const {
|
|
286
|
+
res_model: model,
|
|
287
|
+
views,
|
|
288
|
+
name: title,
|
|
289
|
+
target,
|
|
290
|
+
view_type,
|
|
291
|
+
} = dataForAction;
|
|
292
|
+
const treeExpandable = view_type === "tree";
|
|
277
293
|
|
|
278
294
|
const finalViews = [];
|
|
279
295
|
|
|
@@ -326,6 +342,7 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
326
342
|
action_id,
|
|
327
343
|
action_type,
|
|
328
344
|
res_id,
|
|
345
|
+
treeExpandable,
|
|
329
346
|
});
|
|
330
347
|
}
|
|
331
348
|
|
|
@@ -370,6 +387,7 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
370
387
|
res_id,
|
|
371
388
|
values,
|
|
372
389
|
forced_values,
|
|
390
|
+
treeExpandable = false,
|
|
373
391
|
}: {
|
|
374
392
|
domain: any;
|
|
375
393
|
context: any;
|
|
@@ -383,6 +401,7 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
383
401
|
res_id?: number | boolean;
|
|
384
402
|
values?: any;
|
|
385
403
|
forced_values?: any;
|
|
404
|
+
treeExpandable?: boolean;
|
|
386
405
|
}) {
|
|
387
406
|
const key = uuidv4();
|
|
388
407
|
|
|
@@ -428,6 +447,7 @@ function RootView(props: RootViewProps, ref: any) {
|
|
|
428
447
|
res_id={res_id}
|
|
429
448
|
formDefaultValues={values}
|
|
430
449
|
formForcedValues={forced_values}
|
|
450
|
+
treeExpandable={treeExpandable}
|
|
431
451
|
/>
|
|
432
452
|
),
|
|
433
453
|
key,
|
|
@@ -33,7 +33,14 @@ export async function fetchAction({
|
|
|
33
33
|
})
|
|
34
34
|
: [];
|
|
35
35
|
|
|
36
|
-
const {
|
|
36
|
+
const {
|
|
37
|
+
res_model: model,
|
|
38
|
+
views,
|
|
39
|
+
name: title,
|
|
40
|
+
limit,
|
|
41
|
+
view_type,
|
|
42
|
+
} = dataForAction;
|
|
43
|
+
const treeExpandable = view_type === "tree";
|
|
37
44
|
|
|
38
45
|
const finalViews = [];
|
|
39
46
|
|
|
@@ -67,5 +74,6 @@ export async function fetchAction({
|
|
|
67
74
|
domain: parsedDomain,
|
|
68
75
|
initialView,
|
|
69
76
|
limit,
|
|
77
|
+
treeExpandable,
|
|
70
78
|
};
|
|
71
79
|
}
|
|
@@ -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:
|
|
182
|
+
fields: treeView!.field_parent
|
|
183
|
+
? { ...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!.
|
|
270
|
+
fields: treeView!.field_parent
|
|
271
|
+
? { ...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
|
+
? { ...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
|
|
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
|
|
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 => {
|
|
@@ -38,7 +44,7 @@ const booleanComponentFn = (value: boolean): React.ReactElement => {
|
|
|
38
44
|
alignContent: "center",
|
|
39
45
|
}}
|
|
40
46
|
>
|
|
41
|
-
<Checkbox
|
|
47
|
+
<Checkbox checked={value} disabled />
|
|
42
48
|
</div>
|
|
43
49
|
);
|
|
44
50
|
};
|
|
@@ -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
|
-
<
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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>
|