@addev-be/ui 0.2.16 → 0.2.19
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/eslint.config.js +28 -0
- package/package.json +13 -20
- package/{dist/Icons.d.ts → src/Icons.tsx} +69 -6
- package/src/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.ts +93 -0
- package/src/components/data/AdvancedRequestDataGrid/helpers/columns.tsx +262 -0
- package/src/components/data/AdvancedRequestDataGrid/index.tsx +267 -0
- package/src/components/data/AdvancedRequestDataGrid/types.ts +47 -0
- package/src/components/data/DataGrid/DataGridCell.tsx +73 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/helpers.ts +14 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +59 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/index.tsx +181 -0
- package/src/components/data/DataGrid/DataGridColumnsModal/styles.ts +104 -0
- package/src/components/data/DataGrid/DataGridEditableCell.tsx +43 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.tsx +120 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/hooks.tsx +75 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +360 -0
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +96 -0
- package/src/components/data/DataGrid/DataGridFooter.tsx +42 -0
- package/src/components/data/DataGrid/DataGridHeader.tsx +126 -0
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +132 -0
- package/src/components/data/DataGrid/FilterModalContent/index.tsx +136 -0
- package/src/components/data/DataGrid/FilterModalContent/styles.ts +22 -0
- package/src/components/data/DataGrid/VirtualScroller.tsx +46 -0
- package/src/components/data/DataGrid/helpers/columns.tsx +295 -0
- package/src/components/data/DataGrid/helpers/filters.ts +287 -0
- package/src/components/data/DataGrid/hooks/index.ts +30 -0
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +306 -0
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +175 -0
- package/src/components/data/DataGrid/hooks/useDataGridSettings.ts +48 -0
- package/src/components/data/DataGrid/index.tsx +140 -0
- package/src/components/data/DataGrid/styles.ts +323 -0
- package/src/components/data/DataGrid/types.ts +267 -0
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +277 -0
- package/src/components/data/SqlRequestDataGrid/helpers/sqlRequests.ts +16 -0
- package/src/components/data/SqlRequestDataGrid/index.tsx +347 -0
- package/src/components/data/SqlRequestDataGrid/types.ts +47 -0
- package/src/components/forms/Button.tsx +99 -0
- package/src/components/forms/IconButton.tsx +56 -0
- package/src/components/forms/IndeterminateCheckbox.tsx +46 -0
- package/src/components/forms/Select.tsx +40 -0
- package/src/components/forms/styles.ts +20 -0
- package/src/components/layout/Dropdown/index.tsx +79 -0
- package/src/components/layout/Dropdown/styles.ts +44 -0
- package/src/components/layout/Loading/index.tsx +29 -0
- package/src/components/layout/Loading/styles.ts +29 -0
- package/src/components/layout/Modal/index.tsx +51 -0
- package/src/components/layout/Modal/styles.ts +110 -0
- package/src/components/ui/ContextMenu/index.tsx +79 -0
- package/src/components/ui/ContextMenu/styles.ts +119 -0
- package/src/config/index.ts +14 -0
- package/src/helpers/dates.ts +9 -0
- package/src/helpers/getScrollbarSize.ts +14 -0
- package/src/helpers/numbers.ts +26 -0
- package/src/hooks/useElementSize.ts +24 -0
- package/src/hooks/useWindowSize.ts +20 -0
- package/{dist/index.d.ts → src/index.ts} +2 -0
- package/src/providers/PortalsProvider/index.tsx +54 -0
- package/src/providers/PortalsProvider/styles.ts +27 -0
- package/src/providers/SettingsProvider/index.tsx +70 -0
- package/src/providers/ThemeProvider/ThemeProvider.ts +55 -0
- package/src/providers/ThemeProvider/defaultTheme.ts +444 -0
- package/{dist/providers/ThemeProvider/index.d.ts → src/providers/ThemeProvider/index.ts} +1 -0
- package/src/providers/ThemeProvider/types.ts +123 -0
- package/src/providers/UiProviders/index.tsx +65 -0
- package/src/providers/UiProviders/styles.ts +10 -0
- package/src/providers/hooks.ts +8 -0
- package/{dist/providers/index.d.ts → src/providers/index.ts} +1 -0
- package/src/services/HttpService.ts +80 -0
- package/src/services/WebSocketService.ts +147 -0
- package/src/services/advancedRequests.ts +101 -0
- package/src/services/base.ts +31 -0
- package/src/services/globalSearch.ts +27 -0
- package/src/services/hooks.ts +23 -0
- package/src/services/sqlRequests.ts +110 -0
- package/src/styles/animations.scss +30 -0
- package/src/styles/index.scss +42 -0
- package/src/typings.d.ts +6 -0
- package/tsconfig.json +18 -0
- package/dist/Icons.js +0 -120
- package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.d.ts +0 -14
- package/dist/components/data/AdvancedRequestDataGrid/helpers/advancedRequests.js +0 -76
- package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.d.ts +0 -22
- package/dist/components/data/AdvancedRequestDataGrid/helpers/columns.js +0 -156
- package/dist/components/data/AdvancedRequestDataGrid/helpers/index.js +0 -18
- package/dist/components/data/AdvancedRequestDataGrid/index.d.ts +0 -2
- package/dist/components/data/AdvancedRequestDataGrid/index.js +0 -215
- package/dist/components/data/AdvancedRequestDataGrid/types.d.ts +0 -21
- package/dist/components/data/AdvancedRequestDataGrid/types.js +0 -2
- package/dist/components/data/DataGrid/DataGridCell.d.ts +0 -2
- package/dist/components/data/DataGrid/DataGridCell.js +0 -59
- package/dist/components/data/DataGrid/DataGridColumnsModal/helpers.d.ts +0 -2
- package/dist/components/data/DataGrid/DataGridColumnsModal/helpers.js +0 -24
- package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.d.ts +0 -6
- package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.js +0 -38
- package/dist/components/data/DataGrid/DataGridColumnsModal/index.d.ts +0 -15
- package/dist/components/data/DataGrid/DataGridColumnsModal/index.js +0 -111
- package/dist/components/data/DataGrid/DataGridColumnsModal/styles.d.ts +0 -22
- package/dist/components/data/DataGrid/DataGridColumnsModal/styles.js +0 -54
- package/dist/components/data/DataGrid/DataGridEditableCell.d.ts +0 -2
- package/dist/components/data/DataGrid/DataGridEditableCell.js +0 -27
- package/dist/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.d.ts +0 -13
- package/dist/components/data/DataGrid/DataGridFilterMenu/FilterValuesScroller.js +0 -71
- package/dist/components/data/DataGrid/DataGridFilterMenu/hooks.d.ts +0 -9
- package/dist/components/data/DataGrid/DataGridFilterMenu/hooks.js +0 -52
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.d.ts +0 -9
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +0 -221
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +0 -18
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +0 -31
- package/dist/components/data/DataGrid/DataGridFooter.d.ts +0 -4
- package/dist/components/data/DataGrid/DataGridFooter.js +0 -44
- package/dist/components/data/DataGrid/DataGridHeader.d.ts +0 -4
- package/dist/components/data/DataGrid/DataGridHeader.js +0 -119
- package/dist/components/data/DataGrid/DataGridHeaderCell.d.ts +0 -2
- package/dist/components/data/DataGrid/DataGridHeaderCell.js +0 -84
- package/dist/components/data/DataGrid/FilterModalContent/index.d.ts +0 -7
- package/dist/components/data/DataGrid/FilterModalContent/index.js +0 -117
- package/dist/components/data/DataGrid/FilterModalContent/styles.d.ts +0 -3
- package/dist/components/data/DataGrid/FilterModalContent/styles.js +0 -15
- package/dist/components/data/DataGrid/VirtualScroller.d.ts +0 -11
- package/dist/components/data/DataGrid/VirtualScroller.js +0 -41
- package/dist/components/data/DataGrid/helpers/columns.d.ts +0 -13
- package/dist/components/data/DataGrid/helpers/columns.js +0 -169
- package/dist/components/data/DataGrid/helpers/filters.d.ts +0 -18
- package/dist/components/data/DataGrid/helpers/filters.js +0 -334
- package/dist/components/data/DataGrid/helpers/index.js +0 -18
- package/dist/components/data/DataGrid/hooks/index.d.ts +0 -7
- package/dist/components/data/DataGrid/hooks/index.js +0 -34
- package/dist/components/data/DataGrid/hooks/useDataGrid.d.ts +0 -2
- package/dist/components/data/DataGrid/hooks/useDataGrid.js +0 -252
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.d.ts +0 -4
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +0 -163
- package/dist/components/data/DataGrid/hooks/useDataGridSettings.d.ts +0 -16
- package/dist/components/data/DataGrid/hooks/useDataGridSettings.js +0 -43
- package/dist/components/data/DataGrid/index.d.ts +0 -4
- package/dist/components/data/DataGrid/index.js +0 -108
- package/dist/components/data/DataGrid/styles.d.ts +0 -60
- package/dist/components/data/DataGrid/styles.js +0 -128
- package/dist/components/data/DataGrid/types.d.ts +0 -165
- package/dist/components/data/DataGrid/types.js +0 -34
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +0 -16
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +0 -125
- package/dist/components/data/SqlRequestDataGrid/helpers/index.js +0 -18
- package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.d.ts +0 -3
- package/dist/components/data/SqlRequestDataGrid/helpers/sqlRequests.js +0 -18
- package/dist/components/data/SqlRequestDataGrid/index.d.ts +0 -2
- package/dist/components/data/SqlRequestDataGrid/index.js +0 -296
- package/dist/components/data/SqlRequestDataGrid/types.d.ts +0 -21
- package/dist/components/data/SqlRequestDataGrid/types.js +0 -2
- package/dist/components/data/index.js +0 -24
- package/dist/components/forms/Button.d.ts +0 -10
- package/dist/components/forms/Button.js +0 -70
- package/dist/components/forms/IconButton.d.ts +0 -7
- package/dist/components/forms/IconButton.js +0 -64
- package/dist/components/forms/IndeterminateCheckbox.d.ts +0 -8
- package/dist/components/forms/IndeterminateCheckbox.js +0 -41
- package/dist/components/forms/Select.d.ts +0 -10
- package/dist/components/forms/Select.js +0 -49
- package/dist/components/forms/index.js +0 -23
- package/dist/components/forms/styles.d.ts +0 -2
- package/dist/components/forms/styles.js +0 -34
- package/dist/components/index.js +0 -19
- package/dist/components/layout/Dropdown/index.d.ts +0 -11
- package/dist/components/layout/Dropdown/index.js +0 -85
- package/dist/components/layout/Dropdown/styles.d.ts +0 -11
- package/dist/components/layout/Dropdown/styles.js +0 -45
- package/dist/components/layout/Loading/index.d.ts +0 -6
- package/dist/components/layout/Loading/index.js +0 -42
- package/dist/components/layout/Loading/styles.d.ts +0 -6
- package/dist/components/layout/Loading/styles.js +0 -18
- package/dist/components/layout/Modal/index.d.ts +0 -16
- package/dist/components/layout/Modal/index.js +0 -67
- package/dist/components/layout/Modal/styles.d.ts +0 -32
- package/dist/components/layout/Modal/styles.js +0 -52
- package/dist/components/layout/index.js +0 -19
- package/dist/components/ui/ContextMenu/index.d.ts +0 -11
- package/dist/components/ui/ContextMenu/index.js +0 -63
- package/dist/components/ui/ContextMenu/styles.d.ts +0 -18
- package/dist/components/ui/ContextMenu/styles.js +0 -56
- package/dist/config/index.d.ts +0 -10
- package/dist/config/index.js +0 -2
- package/dist/helpers/dates.d.ts +0 -2
- package/dist/helpers/dates.js +0 -13
- package/dist/helpers/getScrollbarSize.d.ts +0 -1
- package/dist/helpers/getScrollbarSize.js +0 -17
- package/dist/helpers/numbers.d.ts +0 -4
- package/dist/helpers/numbers.js +0 -39
- package/dist/hooks/index.js +0 -18
- package/dist/hooks/useElementSize.d.ts +0 -4
- package/dist/hooks/useElementSize.js +0 -23
- package/dist/hooks/useWindowSize.d.ts +0 -4
- package/dist/hooks/useWindowSize.js +0 -19
- package/dist/index.js +0 -21
- package/dist/providers/PortalsProvider/index.d.ts +0 -10
- package/dist/providers/PortalsProvider/index.js +0 -46
- package/dist/providers/PortalsProvider/styles.d.ts +0 -9
- package/dist/providers/PortalsProvider/styles.js +0 -21
- package/dist/providers/SettingsProvider/index.d.ts +0 -8
- package/dist/providers/SettingsProvider/index.js +0 -54
- package/dist/providers/ThemeProvider/ThemeProvider.d.ts +0 -7
- package/dist/providers/ThemeProvider/ThemeProvider.js +0 -51
- package/dist/providers/ThemeProvider/defaultTheme.d.ts +0 -2
- package/dist/providers/ThemeProvider/defaultTheme.js +0 -417
- package/dist/providers/ThemeProvider/index.js +0 -5
- package/dist/providers/ThemeProvider/types.d.ts +0 -24
- package/dist/providers/ThemeProvider/types.js +0 -2
- package/dist/providers/UiProviders/index.d.ts +0 -12
- package/dist/providers/UiProviders/index.js +0 -62
- package/dist/providers/UiProviders/styles.d.ts +0 -3
- package/dist/providers/UiProviders/styles.js +0 -13
- package/dist/providers/hooks.d.ts +0 -3
- package/dist/providers/hooks.js +0 -13
- package/dist/providers/index.js +0 -20
- package/dist/services/HttpService.d.ts +0 -10
- package/dist/services/HttpService.js +0 -117
- package/dist/services/WebSocketService.d.ts +0 -24
- package/dist/services/WebSocketService.js +0 -136
- package/dist/services/advancedRequests.d.ts +0 -41
- package/dist/services/advancedRequests.js +0 -13
- package/dist/services/base.d.ts +0 -19
- package/dist/services/base.js +0 -10
- package/dist/services/globalSearch.d.ts +0 -13
- package/dist/services/globalSearch.js +0 -8
- package/dist/services/hooks.d.ts +0 -2
- package/dist/services/hooks.js +0 -18
- package/dist/services/index.js +0 -18
- package/dist/services/sqlRequests.d.ts +0 -45
- package/dist/services/sqlRequests.js +0 -11
- /package/{dist/components/data/AdvancedRequestDataGrid/helpers/index.d.ts → src/components/data/AdvancedRequestDataGrid/helpers/index.ts} +0 -0
- /package/{dist/components/data/DataGrid/helpers/index.d.ts → src/components/data/DataGrid/helpers/index.ts} +0 -0
- /package/{dist/components/data/SqlRequestDataGrid/helpers/index.d.ts → src/components/data/SqlRequestDataGrid/helpers/index.ts} +0 -0
- /package/{dist/components/data/index.d.ts → src/components/data/index.ts} +0 -0
- /package/{dist/components/forms/index.d.ts → src/components/forms/index.ts} +0 -0
- /package/{dist/components/index.d.ts → src/components/index.ts} +0 -0
- /package/{dist/components/layout/index.d.ts → src/components/layout/index.ts} +0 -0
- /package/{dist/hooks/index.d.ts → src/hooks/index.ts} +0 -0
- /package/{dist/services/index.d.ts → src/services/index.ts} +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConditionDTO,
|
|
3
|
+
FieldDTO,
|
|
4
|
+
OrderByDTO,
|
|
5
|
+
useAdvancedRequestHandler,
|
|
6
|
+
} from '../../../services/advancedRequests';
|
|
7
|
+
import {
|
|
8
|
+
DataGridColumns,
|
|
9
|
+
DataGridFilters,
|
|
10
|
+
DataGridSort,
|
|
11
|
+
} from '../DataGrid/types';
|
|
12
|
+
import _, { debounce } from 'lodash';
|
|
13
|
+
import {
|
|
14
|
+
convertFiltersToConditions,
|
|
15
|
+
getAdvancedRequestDto,
|
|
16
|
+
getColumnSortField,
|
|
17
|
+
parseJsonObjectFields,
|
|
18
|
+
} from './helpers';
|
|
19
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
20
|
+
|
|
21
|
+
import { AdvancedRequestDataGridProps } from './types';
|
|
22
|
+
import { DataGrid } from '../DataGrid';
|
|
23
|
+
|
|
24
|
+
export const AdvancedRequestDataGrid = <R,>({
|
|
25
|
+
onSelectionChange: onSelectionChangeFromProps,
|
|
26
|
+
idField,
|
|
27
|
+
...props
|
|
28
|
+
}: AdvancedRequestDataGridProps<R>) => {
|
|
29
|
+
const currentRows = useRef<R[]>([]);
|
|
30
|
+
const [rows, setRows] = useState<R[]>([]);
|
|
31
|
+
const [start, setStart] = useState(0);
|
|
32
|
+
const [length, setLength] = useState(50);
|
|
33
|
+
const [total, setTotal] = useState(-1);
|
|
34
|
+
const advancedRequest = useAdvancedRequestHandler<R>();
|
|
35
|
+
const idAdvancedRequest = useAdvancedRequestHandler<{ Id: string }>();
|
|
36
|
+
|
|
37
|
+
const [conditions, setConditions] = useState<Record<string, ConditionDTO>>(
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
const [orderBy, setOrderBy] = useState<OrderByDTO[]>([]);
|
|
41
|
+
|
|
42
|
+
const refresh = useCallback(() => {
|
|
43
|
+
setRows([]);
|
|
44
|
+
setStart(0);
|
|
45
|
+
setLength(50);
|
|
46
|
+
setTotal(-1);
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
const onFiltersChanged = useCallback(
|
|
50
|
+
(filters: DataGridFilters) => {
|
|
51
|
+
const newConditions = convertFiltersToConditions(filters, props.columns);
|
|
52
|
+
setTotal(-1);
|
|
53
|
+
setConditions(newConditions);
|
|
54
|
+
},
|
|
55
|
+
[props.columns]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const onSortsChanged = useCallback(
|
|
59
|
+
(sorts: Record<string, DataGridSort>) => {
|
|
60
|
+
refresh();
|
|
61
|
+
setOrderBy(
|
|
62
|
+
Object.entries(sorts).map(
|
|
63
|
+
([columnKey, direction]) =>
|
|
64
|
+
({
|
|
65
|
+
field: getColumnSortField(props.columns, columnKey),
|
|
66
|
+
direction: direction.toUpperCase(),
|
|
67
|
+
} as OrderByDTO)
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
[props.columns, refresh]
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const loadRows = useRef(
|
|
75
|
+
debounce(
|
|
76
|
+
(
|
|
77
|
+
columns: DataGridColumns<R>,
|
|
78
|
+
conditions: ConditionDTO[],
|
|
79
|
+
orderBy: OrderByDTO[],
|
|
80
|
+
start: number,
|
|
81
|
+
length: number,
|
|
82
|
+
idField: FieldDTO | null | undefined,
|
|
83
|
+
getTotal = false
|
|
84
|
+
) => {
|
|
85
|
+
advancedRequest(
|
|
86
|
+
getAdvancedRequestDto({
|
|
87
|
+
type: props.type,
|
|
88
|
+
columns,
|
|
89
|
+
conditions,
|
|
90
|
+
orderBy,
|
|
91
|
+
start,
|
|
92
|
+
length,
|
|
93
|
+
getTotal,
|
|
94
|
+
idField,
|
|
95
|
+
})
|
|
96
|
+
).then((response) => {
|
|
97
|
+
if (getTotal) {
|
|
98
|
+
currentRows.current = Array(response.count).fill(null);
|
|
99
|
+
if (getTotal) setTotal(response.count ?? 0);
|
|
100
|
+
}
|
|
101
|
+
const parsedRows = parseJsonObjectFields(
|
|
102
|
+
response.data,
|
|
103
|
+
columns,
|
|
104
|
+
props.parser
|
|
105
|
+
);
|
|
106
|
+
currentRows.current.splice(start, length, ...parsedRows);
|
|
107
|
+
setRows([...currentRows.current]);
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
100
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const loadFilterValues = useCallback(
|
|
115
|
+
(columnKey: string) => {
|
|
116
|
+
return advancedRequest({
|
|
117
|
+
fields: [
|
|
118
|
+
props.columns[columnKey].field ?? {
|
|
119
|
+
fieldName: columnKey,
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
conditions: [
|
|
123
|
+
...(props.conditions ?? []),
|
|
124
|
+
...Object.values(_.pickBy(conditions, (_, key) => key !== columnKey)),
|
|
125
|
+
].filter((condition) => condition.field !== columnKey),
|
|
126
|
+
orderBy: [
|
|
127
|
+
{
|
|
128
|
+
field:
|
|
129
|
+
props.columns[columnKey].filterField ??
|
|
130
|
+
props.columns[columnKey].field?.fieldAlias ??
|
|
131
|
+
props.columns[columnKey].field?.fieldName ??
|
|
132
|
+
columnKey,
|
|
133
|
+
direction: 'ASC',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
type: props.type,
|
|
137
|
+
getTotal: false,
|
|
138
|
+
unique: true,
|
|
139
|
+
}).then((response) =>
|
|
140
|
+
response.data.map(
|
|
141
|
+
(row) => props.columns[columnKey].filter?.getter?.(row) ?? null
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
[advancedRequest, conditions, props.columns, props.conditions, props.type]
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
useEffect(
|
|
149
|
+
() =>
|
|
150
|
+
loadRows.current(
|
|
151
|
+
props.columns,
|
|
152
|
+
[...(props.conditions ?? []), ...(Object.values(conditions) ?? [])],
|
|
153
|
+
orderBy,
|
|
154
|
+
start,
|
|
155
|
+
length,
|
|
156
|
+
idField,
|
|
157
|
+
total < 0
|
|
158
|
+
),
|
|
159
|
+
[
|
|
160
|
+
props.columns,
|
|
161
|
+
conditions,
|
|
162
|
+
orderBy,
|
|
163
|
+
start,
|
|
164
|
+
length,
|
|
165
|
+
total,
|
|
166
|
+
props.conditions,
|
|
167
|
+
idField,
|
|
168
|
+
]
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const loadCopyRows = useCallback(
|
|
172
|
+
() =>
|
|
173
|
+
advancedRequest(
|
|
174
|
+
getAdvancedRequestDto({
|
|
175
|
+
type: props.type,
|
|
176
|
+
columns: props.columns,
|
|
177
|
+
conditions: [
|
|
178
|
+
...(props.conditions ?? []),
|
|
179
|
+
...(Object.values(conditions) ?? []),
|
|
180
|
+
],
|
|
181
|
+
orderBy,
|
|
182
|
+
start: 0,
|
|
183
|
+
length: total,
|
|
184
|
+
idField,
|
|
185
|
+
})
|
|
186
|
+
).then((response) =>
|
|
187
|
+
parseJsonObjectFields(response.data, props.columns, props.parser)
|
|
188
|
+
),
|
|
189
|
+
[
|
|
190
|
+
advancedRequest,
|
|
191
|
+
conditions,
|
|
192
|
+
idField,
|
|
193
|
+
orderBy,
|
|
194
|
+
props.columns,
|
|
195
|
+
props.conditions,
|
|
196
|
+
props.parser,
|
|
197
|
+
props.type,
|
|
198
|
+
total,
|
|
199
|
+
]
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const loadAllIds = useCallback(
|
|
203
|
+
() =>
|
|
204
|
+
idAdvancedRequest(
|
|
205
|
+
getAdvancedRequestDto({
|
|
206
|
+
type: props.type,
|
|
207
|
+
columns: {
|
|
208
|
+
Id: {
|
|
209
|
+
name: 'Id',
|
|
210
|
+
field: idField ?? { fieldName: 'Id' },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
conditions: [
|
|
214
|
+
...(props.conditions ?? []),
|
|
215
|
+
...(Object.values(conditions) ?? []),
|
|
216
|
+
],
|
|
217
|
+
orderBy,
|
|
218
|
+
start: 0,
|
|
219
|
+
length: total,
|
|
220
|
+
idField: null,
|
|
221
|
+
})
|
|
222
|
+
).then((response) => response.data.map((row) => row['Id'])),
|
|
223
|
+
[
|
|
224
|
+
conditions,
|
|
225
|
+
idAdvancedRequest,
|
|
226
|
+
idField,
|
|
227
|
+
orderBy,
|
|
228
|
+
props.conditions,
|
|
229
|
+
props.type,
|
|
230
|
+
total,
|
|
231
|
+
]
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const onVisibleRowsChanged = useCallback(
|
|
235
|
+
(newStart: number, newLength: number) => {
|
|
236
|
+
if (newStart !== start || newLength !== length) {
|
|
237
|
+
setStart(newStart);
|
|
238
|
+
setLength(newLength);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
[length, start]
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const onSelectionChange = useCallback(
|
|
245
|
+
(selectedKeys: string[]) => {
|
|
246
|
+
onSelectionChangeFromProps?.(selectedKeys);
|
|
247
|
+
},
|
|
248
|
+
[onSelectionChangeFromProps]
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<DataGrid
|
|
253
|
+
onVisibleRowsChange={onVisibleRowsChanged}
|
|
254
|
+
filter={false}
|
|
255
|
+
sort={false}
|
|
256
|
+
onFiltersChanged={onFiltersChanged}
|
|
257
|
+
onSortsChanged={onSortsChanged}
|
|
258
|
+
filterValuesLoader={loadFilterValues}
|
|
259
|
+
rows={rows}
|
|
260
|
+
loadCopyRows={loadCopyRows}
|
|
261
|
+
refresh={refresh}
|
|
262
|
+
onSelectionChange={onSelectionChange}
|
|
263
|
+
getAllIds={loadAllIds}
|
|
264
|
+
{...props}
|
|
265
|
+
/>
|
|
266
|
+
);
|
|
267
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AdvancedRequestRow,
|
|
3
|
+
ConditionDTO,
|
|
4
|
+
FieldDTO,
|
|
5
|
+
OrderByDTO,
|
|
6
|
+
} from '../../../services/advancedRequests';
|
|
7
|
+
import {
|
|
8
|
+
DataGridColumn,
|
|
9
|
+
DataGridFilter,
|
|
10
|
+
DataGridFilterType,
|
|
11
|
+
DataGridProps,
|
|
12
|
+
} from '../DataGrid/types';
|
|
13
|
+
|
|
14
|
+
export type AdvancedRequestDataGridFilter<
|
|
15
|
+
T extends DataGridFilterType = DataGridFilterType
|
|
16
|
+
> = DataGridFilter<T> & {
|
|
17
|
+
field?: FieldDTO;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type AdvancedRequestDataGridFilters = Record<
|
|
21
|
+
string,
|
|
22
|
+
AdvancedRequestDataGridFilter
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export type AdvancedRequestDataGridColumn<R> = DataGridColumn<R> & {
|
|
26
|
+
filter?: AdvancedRequestDataGridFilter;
|
|
27
|
+
field?: FieldDTO;
|
|
28
|
+
filterField?: string;
|
|
29
|
+
sortField?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type AdvancedRequestDataGridColumns<R> = Record<
|
|
33
|
+
string,
|
|
34
|
+
AdvancedRequestDataGridColumn<R>
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
export type AdvancedRequestDataGridProps<R> = Omit<
|
|
38
|
+
DataGridProps<R>,
|
|
39
|
+
'rows' | 'columns'
|
|
40
|
+
> & {
|
|
41
|
+
columns: AdvancedRequestDataGridColumns<R>;
|
|
42
|
+
type: string;
|
|
43
|
+
orderBy?: OrderByDTO[];
|
|
44
|
+
conditions?: ConditionDTO[];
|
|
45
|
+
idField?: FieldDTO | null;
|
|
46
|
+
parser?: (row: AdvancedRequestRow<R>) => R;
|
|
47
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
3
|
+
|
|
4
|
+
import * as styles from './styles';
|
|
5
|
+
|
|
6
|
+
import { DataGridCellProps, DataGridColumn } from './types';
|
|
7
|
+
import { MouseEvent, useCallback } from 'react';
|
|
8
|
+
|
|
9
|
+
import { DataGridEditableCell } from './DataGridEditableCell';
|
|
10
|
+
import { useDataGridContext } from './hooks';
|
|
11
|
+
|
|
12
|
+
const defaultRender = <R,>(row: R, col: DataGridColumn<R>) => {
|
|
13
|
+
const value = col.propertyName ? row[col.propertyName] : '';
|
|
14
|
+
return !value ? '' : String(value);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const DataGridCell = <R,>({
|
|
18
|
+
row,
|
|
19
|
+
rowIndex,
|
|
20
|
+
columnKey,
|
|
21
|
+
columnIndex,
|
|
22
|
+
column,
|
|
23
|
+
context,
|
|
24
|
+
style,
|
|
25
|
+
}: DataGridCellProps<R>) => {
|
|
26
|
+
const {
|
|
27
|
+
name,
|
|
28
|
+
editable,
|
|
29
|
+
editingCell = [-1, -1],
|
|
30
|
+
setEditingCell,
|
|
31
|
+
onRowDoubleClick,
|
|
32
|
+
} = useDataGridContext(context);
|
|
33
|
+
const isEditable =
|
|
34
|
+
!!editable && !!column.editable && column.type && column.getter;
|
|
35
|
+
const isEditing =
|
|
36
|
+
isEditable && editingCell[0] === rowIndex && editingCell[1] === columnIndex;
|
|
37
|
+
const DataGridCellComponent = column.component ?? styles.DataGridCell;
|
|
38
|
+
|
|
39
|
+
const onDoubleClick = useCallback(
|
|
40
|
+
(e: MouseEvent) => {
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (isEditable) {
|
|
44
|
+
setEditingCell([rowIndex, columnIndex]);
|
|
45
|
+
} else onRowDoubleClick?.(row, e);
|
|
46
|
+
},
|
|
47
|
+
[columnIndex, isEditable, onRowDoubleClick, row, rowIndex, setEditingCell]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (isEditing) {
|
|
51
|
+
return (
|
|
52
|
+
<DataGridEditableCell
|
|
53
|
+
key={`${name}-${rowIndex}-${columnIndex}`}
|
|
54
|
+
row={row}
|
|
55
|
+
rowIndex={rowIndex}
|
|
56
|
+
columnKey={columnKey}
|
|
57
|
+
columnIndex={columnIndex}
|
|
58
|
+
column={column}
|
|
59
|
+
context={context}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<DataGridCellComponent
|
|
66
|
+
key={`${name}-${rowIndex}-${columnIndex}`}
|
|
67
|
+
onDoubleClick={onDoubleClick}
|
|
68
|
+
style={style}
|
|
69
|
+
>
|
|
70
|
+
{(column.render ?? defaultRender)(row, column)}
|
|
71
|
+
</DataGridCellComponent>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataGridColumnKeyValuePair, DataGridColumns } from '../types';
|
|
2
|
+
|
|
3
|
+
export const normalizeColumnsOrders = <R>(
|
|
4
|
+
columns: DataGridColumns<R> | DataGridColumnKeyValuePair<R>[]
|
|
5
|
+
) =>
|
|
6
|
+
(Array.isArray(columns) ? columns : Object.entries(columns)).map<
|
|
7
|
+
DataGridColumnKeyValuePair<R>
|
|
8
|
+
>(([key, column], index) => [
|
|
9
|
+
key,
|
|
10
|
+
{
|
|
11
|
+
...column,
|
|
12
|
+
order: index,
|
|
13
|
+
},
|
|
14
|
+
]);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useCallback, useContext, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button } from '../../../forms';
|
|
4
|
+
import { DataGridColumnsEditor } from '.';
|
|
5
|
+
import { DataGridContext } from '../types';
|
|
6
|
+
import { Modal } from '../../../layout/Modal';
|
|
7
|
+
import { mapValues } from 'lodash';
|
|
8
|
+
|
|
9
|
+
export const useDataGridColumnsModal = <R,>(context: DataGridContext<R>) => {
|
|
10
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
11
|
+
const { columns, setSettings, saveSettings } = useContext(context);
|
|
12
|
+
const [currentColumns, setCurrentColumns] = useState(columns);
|
|
13
|
+
|
|
14
|
+
const openModal = useCallback(() => {
|
|
15
|
+
setCurrentColumns(columns);
|
|
16
|
+
setIsVisible(true);
|
|
17
|
+
}, [columns]);
|
|
18
|
+
const closeModal = useCallback(() => {
|
|
19
|
+
setIsVisible(false);
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
const onApplyClicked = useCallback(() => {
|
|
23
|
+
const newSettings = mapValues(currentColumns, (col) => ({
|
|
24
|
+
order: col.order ?? 0,
|
|
25
|
+
width: col.width ?? 150,
|
|
26
|
+
}));
|
|
27
|
+
setSettings(() => newSettings);
|
|
28
|
+
saveSettings(newSettings);
|
|
29
|
+
closeModal();
|
|
30
|
+
}, [currentColumns, closeModal, saveSettings, setSettings]);
|
|
31
|
+
|
|
32
|
+
const modal = useMemo(
|
|
33
|
+
() =>
|
|
34
|
+
isVisible ? (
|
|
35
|
+
<Modal $width={600} $height={400}>
|
|
36
|
+
<Modal.Header>Paramètres des colonnes</Modal.Header>
|
|
37
|
+
<Modal.Content>
|
|
38
|
+
<DataGridColumnsEditor
|
|
39
|
+
columns={currentColumns}
|
|
40
|
+
onColumnsChanged={setCurrentColumns}
|
|
41
|
+
/>
|
|
42
|
+
</Modal.Content>
|
|
43
|
+
<Modal.Footer>
|
|
44
|
+
<Button onClick={closeModal}>Annuler</Button>
|
|
45
|
+
<Button
|
|
46
|
+
color="primary"
|
|
47
|
+
style={{ marginLeft: 'auto' }}
|
|
48
|
+
onClick={onApplyClicked}
|
|
49
|
+
>
|
|
50
|
+
Appliquer
|
|
51
|
+
</Button>
|
|
52
|
+
</Modal.Footer>
|
|
53
|
+
</Modal>
|
|
54
|
+
) : null,
|
|
55
|
+
[closeModal, currentColumns, isVisible, onApplyClicked]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return { openModal, closeModal, modal };
|
|
59
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as styles from './styles';
|
|
2
|
+
|
|
3
|
+
import { DataGridColumn, DataGridColumns } from '../types';
|
|
4
|
+
import { Dispatch, SetStateAction, useCallback } from 'react';
|
|
5
|
+
import { DownIcon, LeftIcon, RightIcon, UpIcon } from '../../../../Icons';
|
|
6
|
+
|
|
7
|
+
import { IconButton } from '../../../forms/IconButton';
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import { normalizeColumnsOrders } from './helpers';
|
|
10
|
+
import { useVisibleAndHiddenColumns } from '../hooks';
|
|
11
|
+
|
|
12
|
+
export const DataGridColumnItem = <R,>({
|
|
13
|
+
columnIndex,
|
|
14
|
+
columnKey,
|
|
15
|
+
column,
|
|
16
|
+
visible,
|
|
17
|
+
onUpButtonClicked,
|
|
18
|
+
onDownButtonClicked,
|
|
19
|
+
onVisibleButtonClicked,
|
|
20
|
+
}: {
|
|
21
|
+
columnIndex: number;
|
|
22
|
+
columnKey: string;
|
|
23
|
+
column: DataGridColumn<R>;
|
|
24
|
+
visible: boolean;
|
|
25
|
+
onUpButtonClicked?: (index: number) => void;
|
|
26
|
+
onDownButtonClicked?: (index: number) => void;
|
|
27
|
+
onVisibleButtonClicked: (key: string) => void;
|
|
28
|
+
}) => (
|
|
29
|
+
<styles.ColumnItem $visible={visible}>
|
|
30
|
+
{!visible && (
|
|
31
|
+
<styles.Buttons $visible={false}>
|
|
32
|
+
<IconButton
|
|
33
|
+
size="small"
|
|
34
|
+
icon={LeftIcon}
|
|
35
|
+
onClick={() => onVisibleButtonClicked(columnKey)}
|
|
36
|
+
/>
|
|
37
|
+
</styles.Buttons>
|
|
38
|
+
)}
|
|
39
|
+
<span>{column?.name}</span>
|
|
40
|
+
{visible && (
|
|
41
|
+
<styles.Buttons $visible>
|
|
42
|
+
{onUpButtonClicked && (
|
|
43
|
+
<IconButton
|
|
44
|
+
size="small"
|
|
45
|
+
icon={UpIcon}
|
|
46
|
+
onClick={() => onUpButtonClicked(columnIndex)}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
{onDownButtonClicked && (
|
|
50
|
+
<IconButton
|
|
51
|
+
size="small"
|
|
52
|
+
icon={DownIcon}
|
|
53
|
+
onClick={() => onDownButtonClicked(columnIndex)}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
56
|
+
<IconButton
|
|
57
|
+
size="small"
|
|
58
|
+
icon={RightIcon}
|
|
59
|
+
onClick={() => onVisibleButtonClicked(columnKey)}
|
|
60
|
+
/>
|
|
61
|
+
</styles.Buttons>
|
|
62
|
+
)}
|
|
63
|
+
</styles.ColumnItem>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export const DataGridColumnsEditor = <R,>({
|
|
67
|
+
columns,
|
|
68
|
+
onColumnsChanged,
|
|
69
|
+
}: {
|
|
70
|
+
columns: DataGridColumns<R>;
|
|
71
|
+
onColumnsChanged: Dispatch<SetStateAction<DataGridColumns<R>>>;
|
|
72
|
+
}) => {
|
|
73
|
+
const [visibleColumns, hiddenColumns] = useVisibleAndHiddenColumns(columns);
|
|
74
|
+
const sortedVisibleColumnsEntries = normalizeColumnsOrders(
|
|
75
|
+
_.sortBy(Object.entries(visibleColumns), ([, col]) => col.order ?? 0)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const onUpButtonClicked = useCallback(
|
|
79
|
+
(index: number) => {
|
|
80
|
+
if (index > 0) {
|
|
81
|
+
const newArray = normalizeColumnsOrders([
|
|
82
|
+
...sortedVisibleColumnsEntries.slice(0, index - 1),
|
|
83
|
+
sortedVisibleColumnsEntries[index],
|
|
84
|
+
sortedVisibleColumnsEntries[index - 1],
|
|
85
|
+
...sortedVisibleColumnsEntries.slice(index + 1),
|
|
86
|
+
]);
|
|
87
|
+
onColumnsChanged(() => ({
|
|
88
|
+
...Object.fromEntries(newArray),
|
|
89
|
+
...hiddenColumns,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
[hiddenColumns, onColumnsChanged, sortedVisibleColumnsEntries]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const onDownButtonClicked = useCallback(
|
|
97
|
+
(index: number) => {
|
|
98
|
+
if (index < sortedVisibleColumnsEntries.length - 1) {
|
|
99
|
+
const newArray = normalizeColumnsOrders([
|
|
100
|
+
...sortedVisibleColumnsEntries.slice(0, index),
|
|
101
|
+
sortedVisibleColumnsEntries[index + 1],
|
|
102
|
+
sortedVisibleColumnsEntries[index],
|
|
103
|
+
...sortedVisibleColumnsEntries.slice(index + 2),
|
|
104
|
+
]);
|
|
105
|
+
onColumnsChanged(() => ({
|
|
106
|
+
...Object.fromEntries(newArray),
|
|
107
|
+
...hiddenColumns,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[hiddenColumns, onColumnsChanged, sortedVisibleColumnsEntries]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const onHideButtonClicked = useCallback(
|
|
115
|
+
(columnKey: string) => {
|
|
116
|
+
onColumnsChanged((prev) => ({
|
|
117
|
+
...prev,
|
|
118
|
+
[columnKey]: {
|
|
119
|
+
...prev[columnKey],
|
|
120
|
+
order: -1,
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
},
|
|
124
|
+
[onColumnsChanged]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const onShowButtonClicked = useCallback(
|
|
128
|
+
(columnKey: string) => {
|
|
129
|
+
onColumnsChanged((prev) => ({
|
|
130
|
+
...prev,
|
|
131
|
+
[columnKey]: {
|
|
132
|
+
...hiddenColumns[columnKey],
|
|
133
|
+
order: Object.keys(prev).length,
|
|
134
|
+
},
|
|
135
|
+
}));
|
|
136
|
+
},
|
|
137
|
+
[hiddenColumns, onColumnsChanged]
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<styles.Container>
|
|
142
|
+
<styles.Panel>
|
|
143
|
+
<styles.Title>Colonnes visibles</styles.Title>
|
|
144
|
+
<styles.ColumnsList>
|
|
145
|
+
{sortedVisibleColumnsEntries.map(([key, column], index) => (
|
|
146
|
+
<DataGridColumnItem
|
|
147
|
+
key={key}
|
|
148
|
+
columnKey={key}
|
|
149
|
+
columnIndex={index}
|
|
150
|
+
column={column}
|
|
151
|
+
visible
|
|
152
|
+
onUpButtonClicked={index > 0 ? onUpButtonClicked : undefined}
|
|
153
|
+
onDownButtonClicked={
|
|
154
|
+
index < sortedVisibleColumnsEntries.length - 1
|
|
155
|
+
? onDownButtonClicked
|
|
156
|
+
: undefined
|
|
157
|
+
}
|
|
158
|
+
onVisibleButtonClicked={onHideButtonClicked}
|
|
159
|
+
/>
|
|
160
|
+
))}
|
|
161
|
+
</styles.ColumnsList>
|
|
162
|
+
</styles.Panel>
|
|
163
|
+
|
|
164
|
+
<styles.Panel>
|
|
165
|
+
<styles.Title>Colonnes masquées</styles.Title>
|
|
166
|
+
<styles.ColumnsList>
|
|
167
|
+
{Object.entries(hiddenColumns).map(([key, column], index) => (
|
|
168
|
+
<DataGridColumnItem
|
|
169
|
+
key={key}
|
|
170
|
+
columnKey={key}
|
|
171
|
+
columnIndex={index}
|
|
172
|
+
column={column}
|
|
173
|
+
visible={false}
|
|
174
|
+
onVisibleButtonClicked={onShowButtonClicked}
|
|
175
|
+
/>
|
|
176
|
+
))}
|
|
177
|
+
</styles.ColumnsList>
|
|
178
|
+
</styles.Panel>
|
|
179
|
+
</styles.Container>
|
|
180
|
+
);
|
|
181
|
+
};
|