@gisce/react-ooui 0.5.0 → 0.7.1
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/helpers/treeHelper.d.ts +6 -1
- package/dist/helpers/treeHelper.d.ts.map +1 -1
- package/dist/helpers/treeHelper.js +27 -1
- package/dist/helpers/treeHelper.js.map +1 -1
- package/dist/index.js +62 -1
- package/dist/index.js.LICENSE.txt +15 -0
- package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
- package/dist/widgets/views/Dashboard/DashboardTree.js +11 -27
- package/dist/widgets/views/Dashboard/DashboardTree.js.map +1 -1
- package/dist/widgets/views/Form.d.ts.map +1 -1
- package/dist/widgets/views/Form.js +3 -14
- package/dist/widgets/views/Form.js.map +1 -1
- package/dist/widgets/views/SearchTree.d.ts.map +1 -1
- package/dist/widgets/views/SearchTree.js +39 -40
- package/dist/widgets/views/SearchTree.js.map +1 -1
- package/dist/widgets/views/Tree.d.ts +1 -1
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/dist/widgets/views/Tree.js +6 -28
- package/dist/widgets/views/Tree.js.map +1 -1
- package/package.json +4 -1
- package/src/helpers/treeHelper.ts +41 -0
- package/src/stories/views/SearchTree.stories.tsx +324 -162
- package/src/widgets/views/Dashboard/DashboardTree.tsx +13 -36
- package/src/widgets/views/Form.tsx +3 -16
- package/src/widgets/views/SearchTree.tsx +43 -49
- package/src/widgets/views/Tree.tsx +12 -45
|
@@ -5,7 +5,7 @@ import Tree from "@/widgets/views/Tree";
|
|
|
5
5
|
import { FormView, TreeView } from "@/types/index";
|
|
6
6
|
import ConnectionProvider from "@/ConnectionProvider";
|
|
7
7
|
|
|
8
|
-
import { getColorMap, getTree } from "@/helpers/treeHelper";
|
|
8
|
+
import { getColorMap, getTree, sortResults } from "@/helpers/treeHelper";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_SEARCH_LIMIT = 80;
|
|
11
11
|
|
|
@@ -117,7 +117,12 @@ function DashboardTree(props: Props) {
|
|
|
117
117
|
setTotalItems(totalItems);
|
|
118
118
|
setColorsForResults(getColorMap(attrsEvaluated));
|
|
119
119
|
|
|
120
|
-
const resultsSorted = sortResults(
|
|
120
|
+
const resultsSorted = sortResults({
|
|
121
|
+
resultsToSort: results,
|
|
122
|
+
sorter: sorter,
|
|
123
|
+
fields: { ...treeView!.fields, ...formView!.fields },
|
|
124
|
+
});
|
|
125
|
+
|
|
121
126
|
setResults(resultsSorted);
|
|
122
127
|
};
|
|
123
128
|
|
|
@@ -211,38 +216,6 @@ function DashboardTree(props: Props) {
|
|
|
211
216
|
});
|
|
212
217
|
};
|
|
213
218
|
|
|
214
|
-
function sortResults(resultsToSort: any[], sorter: any) {
|
|
215
|
-
if (!sorter) {
|
|
216
|
-
return resultsToSort;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const { field, order } = sorter;
|
|
220
|
-
const fields = { ...treeView!.fields, ...formView!.fields };
|
|
221
|
-
const type = fields[field].type;
|
|
222
|
-
|
|
223
|
-
const sortFn = (a: any, b: any) => {
|
|
224
|
-
let aItem = a[field] || "",
|
|
225
|
-
bItem = b[field] || "";
|
|
226
|
-
|
|
227
|
-
if (type === "many2one") {
|
|
228
|
-
aItem = a[field]?.value || "";
|
|
229
|
-
bItem = b[field]?.value || "";
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (aItem === bItem) {
|
|
233
|
-
return 0;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (order === "ascend") {
|
|
237
|
-
return aItem > bItem ? 1 : -1;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return aItem < bItem ? 1 : -1;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
return resultsToSort.sort(sortFn);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
219
|
const content = () => {
|
|
247
220
|
if (!treeView || !formView) {
|
|
248
221
|
return null;
|
|
@@ -257,7 +230,6 @@ function DashboardTree(props: Props) {
|
|
|
257
230
|
showPagination={false}
|
|
258
231
|
total={totalItems}
|
|
259
232
|
limit={limitRef.current}
|
|
260
|
-
disableScroll
|
|
261
233
|
page={page}
|
|
262
234
|
treeView={treeView}
|
|
263
235
|
results={results}
|
|
@@ -265,9 +237,14 @@ function DashboardTree(props: Props) {
|
|
|
265
237
|
loading={tableRefreshing}
|
|
266
238
|
onRowClicked={onRowClickedHandler}
|
|
267
239
|
colorsForResults={colorsForResults}
|
|
240
|
+
sorter={sorter}
|
|
268
241
|
onChangeSort={(newSorter) => {
|
|
269
242
|
setSorter?.(newSorter);
|
|
270
|
-
const sortedResults = sortResults(
|
|
243
|
+
const sortedResults = sortResults({
|
|
244
|
+
resultsToSort: results,
|
|
245
|
+
sorter: newSorter,
|
|
246
|
+
fields: { ...treeView.fields, ...formView.fields },
|
|
247
|
+
});
|
|
271
248
|
setResults(sortedResults);
|
|
272
249
|
}}
|
|
273
250
|
/>
|
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
6
6
|
useRef,
|
|
7
7
|
useContext,
|
|
8
8
|
} from "react";
|
|
9
|
-
import { Form as FormOoui
|
|
9
|
+
import { Form as FormOoui } from "@gisce/ooui";
|
|
10
10
|
import {
|
|
11
11
|
Form as AntForm,
|
|
12
12
|
Button,
|
|
@@ -771,20 +771,7 @@ function Form(props: FormProps, ref: any) {
|
|
|
771
771
|
) {
|
|
772
772
|
onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
|
|
773
773
|
} else if (response.type) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (response.context) {
|
|
777
|
-
responseContext = parseContext({
|
|
778
|
-
context: response.context,
|
|
779
|
-
fields,
|
|
780
|
-
values: getValues(),
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
await runAction({
|
|
785
|
-
actionData: response,
|
|
786
|
-
context: { ...context, ...responseContext },
|
|
787
|
-
});
|
|
774
|
+
await runAction({ actionData: response, context });
|
|
788
775
|
} else {
|
|
789
776
|
await fetchValues();
|
|
790
777
|
}
|
|
@@ -835,9 +822,9 @@ function Form(props: FormProps, ref: any) {
|
|
|
835
822
|
fields,
|
|
836
823
|
values: getValues(),
|
|
837
824
|
context: {
|
|
825
|
+
...context,
|
|
838
826
|
...parentContext,
|
|
839
827
|
...formOoui?.context,
|
|
840
|
-
...context,
|
|
841
828
|
},
|
|
842
829
|
onRefreshParentValues: () => {
|
|
843
830
|
fetchValues();
|
|
@@ -5,6 +5,7 @@ import React, {
|
|
|
5
5
|
useContext,
|
|
6
6
|
forwardRef,
|
|
7
7
|
useImperativeHandle,
|
|
8
|
+
useCallback,
|
|
8
9
|
} from "react";
|
|
9
10
|
import { Alert, Spin } from "antd";
|
|
10
11
|
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
ActionViewContext,
|
|
18
19
|
ActionViewContextType,
|
|
19
20
|
} from "@/context/ActionViewContext";
|
|
20
|
-
import { getColorMap, getTree } from "@/helpers/treeHelper";
|
|
21
|
+
import { getColorMap, getTree, sortResults } from "@/helpers/treeHelper";
|
|
21
22
|
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
|
22
23
|
import Measure from "react-measure";
|
|
23
24
|
import { mergeSearchFields } from "@/helpers/formHelper";
|
|
@@ -94,6 +95,8 @@ function SearchTree(props: Props, ref: any) {
|
|
|
94
95
|
const actionDomain = useRef<any>([]);
|
|
95
96
|
const [searchFilterHeight, setSearchFilterHeight] = useState<number>(200);
|
|
96
97
|
|
|
98
|
+
const originalResults = useRef<any[]>([]);
|
|
99
|
+
|
|
97
100
|
const { height } = useWindowDimensions();
|
|
98
101
|
|
|
99
102
|
const actionViewContext = useContext(
|
|
@@ -114,7 +117,6 @@ function SearchTree(props: Props, ref: any) {
|
|
|
114
117
|
setTotalItems: setActionViewTotalItems = undefined,
|
|
115
118
|
setSearchTreeNameSearch = undefined,
|
|
116
119
|
setTreeIsLoading = undefined,
|
|
117
|
-
treeIsLoading = false,
|
|
118
120
|
} = (rootTree ? actionViewContext : {}) || {};
|
|
119
121
|
|
|
120
122
|
useImperativeHandle(ref, () => ({
|
|
@@ -131,16 +133,16 @@ function SearchTree(props: Props, ref: any) {
|
|
|
131
133
|
};
|
|
132
134
|
|
|
133
135
|
function setResults(results: any) {
|
|
134
|
-
setResultsActionView?.(results);
|
|
135
|
-
setResultsInternal(results);
|
|
136
|
+
setResultsActionView?.([...results]);
|
|
137
|
+
setResultsInternal([...results]);
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
|
|
140
|
+
const getResults = useCallback(() => {
|
|
139
141
|
if (!resultsActionView) {
|
|
140
142
|
return resultsInternal;
|
|
141
143
|
}
|
|
142
144
|
return resultsActionView;
|
|
143
|
-
}
|
|
145
|
+
}, [resultsActionView, resultsInternal]);
|
|
144
146
|
|
|
145
147
|
const searchByNameSearch = async () => {
|
|
146
148
|
const searchResults = await ConnectionProvider.getHandler().nameSearch({
|
|
@@ -175,12 +177,21 @@ function SearchTree(props: Props, ref: any) {
|
|
|
175
177
|
);
|
|
176
178
|
const resultsData = resultsWithData[0];
|
|
177
179
|
|
|
180
|
+
originalResults.current = [...resultsData];
|
|
181
|
+
|
|
178
182
|
setColorsForResults(getColorMap(resultsWithData[1]));
|
|
179
|
-
setResults(resultsData);
|
|
180
183
|
|
|
181
184
|
const newResultIds = resultsData.map((item: any) => item.id);
|
|
182
185
|
|
|
183
|
-
const resultsSorted =
|
|
186
|
+
const resultsSorted =
|
|
187
|
+
sorter !== undefined
|
|
188
|
+
? sortResults({
|
|
189
|
+
resultsToSort: resultsData,
|
|
190
|
+
sorter,
|
|
191
|
+
fields: { ...treeView!.fields, ...formView!.fields },
|
|
192
|
+
})
|
|
193
|
+
: [...originalResults.current];
|
|
194
|
+
|
|
184
195
|
setResults(resultsSorted);
|
|
185
196
|
|
|
186
197
|
if (newResultIds.length > 0) {
|
|
@@ -251,7 +262,17 @@ function SearchTree(props: Props, ref: any) {
|
|
|
251
262
|
setActionViewTotalItems?.(totalItems);
|
|
252
263
|
setColorsForResults(getColorMap(attrsEvaluated));
|
|
253
264
|
|
|
254
|
-
|
|
265
|
+
originalResults.current = [...results];
|
|
266
|
+
|
|
267
|
+
const resultsSorted =
|
|
268
|
+
sorter !== undefined
|
|
269
|
+
? sortResults({
|
|
270
|
+
resultsToSort: results,
|
|
271
|
+
sorter: sorter,
|
|
272
|
+
fields: { ...treeView!.fields, ...formView!.fields },
|
|
273
|
+
})
|
|
274
|
+
: [...originalResults.current];
|
|
275
|
+
|
|
255
276
|
setResults(resultsSorted);
|
|
256
277
|
|
|
257
278
|
if (resultsActionView && resultsSorted.length > 0) {
|
|
@@ -418,49 +439,14 @@ function SearchTree(props: Props, ref: any) {
|
|
|
418
439
|
});
|
|
419
440
|
};
|
|
420
441
|
|
|
421
|
-
function changeSelectedRowKeys(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
setSelectedRowItems?.(items);
|
|
442
|
+
function changeSelectedRowKeys(selectedRowItems: any[]) {
|
|
443
|
+
setSelectedRowItems?.(selectedRowItems);
|
|
444
|
+
const selectedRowKeys = selectedRowItems.map((entry: any) => entry.id);
|
|
427
445
|
onChangeSelectedRowKeys?.(selectedRowKeys);
|
|
428
446
|
}
|
|
429
447
|
|
|
430
448
|
function calculateTableHeight() {
|
|
431
|
-
return height - (searchFilterHeight +
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function sortResults(resultsToSort: any[], sorter: any) {
|
|
435
|
-
if (!sorter) {
|
|
436
|
-
return resultsToSort;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
const { field, order } = sorter;
|
|
440
|
-
const fields = { ...treeView!.fields, ...formView!.fields };
|
|
441
|
-
const type = fields[field].type;
|
|
442
|
-
|
|
443
|
-
const sortFn = (a: any, b: any) => {
|
|
444
|
-
let aItem = a[field] || "",
|
|
445
|
-
bItem = b[field] || "";
|
|
446
|
-
|
|
447
|
-
if (type === "many2one") {
|
|
448
|
-
aItem = a[field]?.value || "";
|
|
449
|
-
bItem = b[field]?.value || "";
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (aItem === bItem) {
|
|
453
|
-
return 0;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (order === "ascend") {
|
|
457
|
-
return aItem > bItem ? 1 : -1;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
return aItem < bItem ? 1 : -1;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
return resultsToSort.sort(sortFn);
|
|
449
|
+
return height - (searchFilterHeight + 210);
|
|
464
450
|
}
|
|
465
451
|
|
|
466
452
|
const content = () => {
|
|
@@ -520,9 +506,17 @@ function SearchTree(props: Props, ref: any) {
|
|
|
520
506
|
selectedRowKeys: selectedRowItems?.map((item) => item.id),
|
|
521
507
|
onChange: changeSelectedRowKeys,
|
|
522
508
|
}}
|
|
509
|
+
sorter={sorter}
|
|
523
510
|
onChangeSort={(newSorter) => {
|
|
524
511
|
setSorter?.(newSorter);
|
|
525
|
-
const sortedResults =
|
|
512
|
+
const sortedResults =
|
|
513
|
+
newSorter !== undefined
|
|
514
|
+
? sortResults({
|
|
515
|
+
resultsToSort: getResults(),
|
|
516
|
+
sorter: newSorter,
|
|
517
|
+
fields: { ...treeView.fields, ...formView.fields },
|
|
518
|
+
})
|
|
519
|
+
: [...originalResults.current];
|
|
526
520
|
setResults(sortedResults);
|
|
527
521
|
}}
|
|
528
522
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Pagination, Checkbox, Space, Row, Col, Spin } from "antd";
|
|
3
3
|
import { getTree, getTableColumns, getTableItems } from "@/helpers/treeHelper";
|
|
4
4
|
import { Tree as TreeOoui } from "@gisce/ooui";
|
|
5
5
|
|
|
@@ -9,17 +9,8 @@ import { Many2oneSuffix } from "../base/many2one/Many2oneSuffix";
|
|
|
9
9
|
import { calculateColumnsWidth } from "@/helpers/dynamicColumnsHelper";
|
|
10
10
|
import { parseFloatToString } from "@/helpers/timeHelper";
|
|
11
11
|
import { ProgressBarInput } from "../base/ProgressBar";
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
interface TableProps {
|
|
15
|
-
minHeight: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const StyledTable = styled(Table)`
|
|
19
|
-
.ant-table-body {
|
|
20
|
-
min-height: ${(props: TableProps) => props.minHeight}px;
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
12
|
+
import { Table as GisceTable } from "@gisce/react-formiga-table";
|
|
13
|
+
import useDeepCompareEffect from "use-deep-compare-effect";
|
|
23
14
|
|
|
24
15
|
type Props = {
|
|
25
16
|
total: number;
|
|
@@ -35,7 +26,7 @@ type Props = {
|
|
|
35
26
|
scrollY?: number;
|
|
36
27
|
colorsForResults?: { [key: number]: string };
|
|
37
28
|
onChangeSort?: (results: any) => void;
|
|
38
|
-
|
|
29
|
+
sorter?: any;
|
|
39
30
|
};
|
|
40
31
|
|
|
41
32
|
const booleanComponentFn = (value: boolean): React.ReactElement => {
|
|
@@ -94,7 +85,7 @@ function Tree(props: Props): React.ReactElement {
|
|
|
94
85
|
scrollY,
|
|
95
86
|
colorsForResults = {},
|
|
96
87
|
onChangeSort,
|
|
97
|
-
|
|
88
|
+
sorter,
|
|
98
89
|
} = props;
|
|
99
90
|
|
|
100
91
|
const [items, setItems] = useState<Array<any>>([]);
|
|
@@ -119,6 +110,7 @@ function Tree(props: Props): React.ReactElement {
|
|
|
119
110
|
float_time: floatTimeComponent,
|
|
120
111
|
image: imageComponent,
|
|
121
112
|
});
|
|
113
|
+
|
|
122
114
|
setColumns(columns);
|
|
123
115
|
}, [treeView]);
|
|
124
116
|
|
|
@@ -220,32 +212,12 @@ function Tree(props: Props): React.ReactElement {
|
|
|
220
212
|
) : (
|
|
221
213
|
<div>
|
|
222
214
|
{pagination()}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
<div key={result.id}>
|
|
226
|
-
<br />
|
|
227
|
-
<span>{result.name}</span>
|
|
228
|
-
</div>
|
|
229
|
-
);
|
|
230
|
-
})} */}
|
|
231
|
-
<StyledTable
|
|
232
|
-
minHeight={adjustedHeight!}
|
|
215
|
+
<GisceTable
|
|
216
|
+
height={adjustedHeight!}
|
|
233
217
|
columns={dataTable.columns}
|
|
234
|
-
scroll={
|
|
235
|
-
disableScroll
|
|
236
|
-
? undefined
|
|
237
|
-
: { x: dataTable.tableWidth, y: adjustedHeight }
|
|
238
|
-
}
|
|
239
|
-
size="small"
|
|
240
218
|
dataSource={items}
|
|
241
|
-
pagination={false}
|
|
242
219
|
loading={loading}
|
|
243
|
-
|
|
244
|
-
return `cursor-pointer select-none record-row-${record.id}`;
|
|
245
|
-
}}
|
|
246
|
-
rowKey={(item: any) => {
|
|
247
|
-
return item.id;
|
|
248
|
-
}}
|
|
220
|
+
loadingComponent={<Spin />}
|
|
249
221
|
onRow={(record: any) => {
|
|
250
222
|
let style = undefined;
|
|
251
223
|
|
|
@@ -260,14 +232,9 @@ function Tree(props: Props): React.ReactElement {
|
|
|
260
232
|
},
|
|
261
233
|
};
|
|
262
234
|
}}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
onChangeSort?.(undefined);
|
|
267
|
-
} else {
|
|
268
|
-
onChangeSort?.(sorter);
|
|
269
|
-
}
|
|
270
|
-
}}
|
|
235
|
+
onRowSelectionChange={rowSelection?.onChange}
|
|
236
|
+
onChangeSort={onChangeSort}
|
|
237
|
+
sorter={sorter}
|
|
271
238
|
/>
|
|
272
239
|
{getSums()}
|
|
273
240
|
</div>
|