@gisce/react-ooui 0.8.5 → 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.
- 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 +9 -0
- package/dist/helpers/treeHelper.js.map +1 -1
- package/dist/index.js +4 -4
- 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/base/one2many/One2manyInput.d.ts.map +1 -1
- package/dist/widgets/base/one2many/One2manyInput.js +6 -7
- package/dist/widgets/base/one2many/One2manyInput.js.map +1 -1
- package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
- package/dist/widgets/views/Dashboard/DashboardTree.js +2 -1
- package/dist/widgets/views/Dashboard/DashboardTree.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 +94 -10
- package/dist/widgets/views/SearchTree.js.map +1 -1
- package/dist/widgets/views/Tree.d.ts +3 -1
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/dist/widgets/views/Tree.js +19 -18
- 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 +9 -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/base/one2many/One2manyInput.tsx +7 -6
- package/src/widgets/views/Dashboard/DashboardTree.tsx +2 -1
- package/src/widgets/views/Dashboard/dashboardHelper.ts +9 -1
- package/src/widgets/views/SearchTree.tsx +79 -3
- package/src/widgets/views/Tree.tsx +40 -30
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,
|
|
@@ -436,11 +436,8 @@ const One2manyInput: React.FC<One2manyInputProps> = (
|
|
|
436
436
|
}
|
|
437
437
|
};
|
|
438
438
|
|
|
439
|
-
const onTreeRowClicked = (
|
|
440
|
-
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
|
|
439
|
+
const onTreeRowClicked = (record: any) => {
|
|
440
|
+
const { id: itemId } = record;
|
|
444
441
|
// We show the detail for the clicked item in a Form modal
|
|
445
442
|
setModalItem(items.find((item) => item.id === itemId));
|
|
446
443
|
setContinuousEntryMode(false);
|
|
@@ -568,7 +565,11 @@ const One2manyInput: React.FC<One2manyInputProps> = (
|
|
|
568
565
|
treeView={views.get("tree")}
|
|
569
566
|
results={resultsToShow}
|
|
570
567
|
loading={isLoading}
|
|
571
|
-
onRowClicked={
|
|
568
|
+
onRowClicked={
|
|
569
|
+
views.get("form")?.fields !== undefined
|
|
570
|
+
? onTreeRowClicked
|
|
571
|
+
: undefined
|
|
572
|
+
}
|
|
572
573
|
showPagination={false}
|
|
573
574
|
rowSelection={{
|
|
574
575
|
selectedRowKeys,
|
|
@@ -208,7 +208,8 @@ function DashboardTree(props: Props) {
|
|
|
208
208
|
}
|
|
209
209
|
}, [action, model]);
|
|
210
210
|
|
|
211
|
-
const onRowClickedHandler = (
|
|
211
|
+
const onRowClickedHandler = (record: any) => {
|
|
212
|
+
const { id } = record;
|
|
212
213
|
onRowClicked({
|
|
213
214
|
id,
|
|
214
215
|
model: currentModel!,
|
|
@@ -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
|
+
? [...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!.
|
|
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,7 +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) => {
|
|
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
|
+
|
|
434
503
|
onRowClicked({
|
|
435
504
|
id,
|
|
436
505
|
model: currentModel!,
|
|
@@ -448,6 +517,9 @@ function SearchTree(props: Props, ref: any) {
|
|
|
448
517
|
}
|
|
449
518
|
|
|
450
519
|
function calculateTableHeight() {
|
|
520
|
+
if (treeView?.isExpandable) {
|
|
521
|
+
return height - 160;
|
|
522
|
+
}
|
|
451
523
|
return height - (searchFilterHeight + 210);
|
|
452
524
|
}
|
|
453
525
|
|
|
@@ -521,6 +593,10 @@ function SearchTree(props: Props, ref: any) {
|
|
|
521
593
|
: [...originalResults.current];
|
|
522
594
|
setResults(sortedResults);
|
|
523
595
|
}}
|
|
596
|
+
onFetchChildrenForRecord={
|
|
597
|
+
treeView.isExpandable ? onFetchChildrenForRecord : undefined
|
|
598
|
+
}
|
|
599
|
+
childField={treeView.field_parent}
|
|
524
600
|
/>
|
|
525
601
|
</>
|
|
526
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;
|
|
@@ -21,12 +25,14 @@ type Props = {
|
|
|
21
25
|
results: Array<any>;
|
|
22
26
|
showPagination?: boolean;
|
|
23
27
|
onRequestPageChange?: (page: number, pageSize?: number) => void;
|
|
24
|
-
onRowClicked?: (
|
|
28
|
+
onRowClicked?: (record: any) => void;
|
|
25
29
|
rowSelection?: any;
|
|
26
30
|
scrollY?: number;
|
|
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
|
-
<
|
|
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
|
|
|
@@ -234,23 +240,27 @@ function Tree(props: Props): React.ReactElement {
|
|
|
234
240
|
dataSource={items}
|
|
235
241
|
loading={loading}
|
|
236
242
|
loadingComponent={<Spin />}
|
|
237
|
-
|
|
238
|
-
let style = undefined;
|
|
239
|
-
|
|
243
|
+
onRowStyle={(record: any) => {
|
|
240
244
|
if (colorsForResults![record.id]) {
|
|
241
|
-
|
|
245
|
+
return { color: colorsForResults![record.id] };
|
|
242
246
|
}
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
style,
|
|
246
|
-
onDoubleClick: () => {
|
|
247
|
-
if (onRowClicked) onRowClicked(record.id);
|
|
248
|
-
},
|
|
249
|
-
};
|
|
247
|
+
return undefined;
|
|
250
248
|
}}
|
|
249
|
+
onRowDoubleClick={onRowClicked}
|
|
251
250
|
onRowSelectionChange={rowSelection?.onChange}
|
|
252
251
|
onChangeSort={onChangeSort}
|
|
253
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
|
+
}
|
|
254
264
|
/>
|
|
255
265
|
{getSums()}
|
|
256
266
|
</div>
|