@terraware/web-components 5.2.8 → 5.2.9-rc.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/components/EditableTable/index.d.ts +2 -3
- package/components/EditableTable/index.d.ts.map +1 -1
- package/components/EditableTable/tableSettings.d.ts +11 -5
- package/components/EditableTable/tableSettings.d.ts.map +1 -1
- package/components/EditableTable/tableSettings.js +41 -8
- package/components/EditableTableV2/ColumnDragging.d.ts +23 -0
- package/components/EditableTableV2/ColumnDragging.d.ts.map +1 -0
- package/components/EditableTableV2/ColumnDragging.js +263 -0
- package/components/EditableTableV2/EditableCellV2.d.ts +10 -0
- package/components/EditableTableV2/EditableCellV2.d.ts.map +1 -0
- package/components/EditableTableV2/EditableCellV2.js +81 -0
- package/components/EditableTableV2/ToolbarButtons.d.ts +29 -0
- package/components/EditableTableV2/ToolbarButtons.d.ts.map +1 -0
- package/components/EditableTableV2/ToolbarButtons.js +84 -0
- package/components/EditableTableV2/index.d.ts +62 -0
- package/components/EditableTableV2/index.d.ts.map +1 -0
- package/components/EditableTableV2/index.js +1010 -0
- package/components/EditableTableV2/pinning.d.ts +8 -0
- package/components/EditableTableV2/pinning.d.ts.map +1 -0
- package/components/EditableTableV2/pinning.js +16 -0
- package/components/EditableTableV2/types.d.ts +89 -0
- package/components/EditableTableV2/types.d.ts.map +1 -0
- package/components/EditableTableV2/types.js +18 -0
- package/components/table/density.d.ts +1 -1
- package/index.d.ts +7 -3
- package/index.d.ts.map +1 -1
- package/index.js +4 -1
- package/license-report.html +1 -1
- package/package.json +2 -1
- package/strings/csv/en.csv +37 -0
- package/strings/csv/es.csv +37 -0
- package/strings/csv/fr.csv +37 -0
- package/strings/strings-en.d.ts +37 -0
- package/strings/strings-en.d.ts.map +1 -1
- package/strings/strings-en.js +38 -1
- package/strings/strings-es.d.ts +37 -0
- package/strings/strings-es.d.ts.map +1 -1
- package/strings/strings-es.js +38 -1
- package/strings/strings-fr.d.ts +37 -0
- package/strings/strings-fr.d.ts.map +1 -1
- package/strings/strings-fr.js +38 -1
- package/strings/strings-gx.d.ts +37 -0
- package/strings/strings-gx.d.ts.map +1 -1
- package/strings/strings-gx.js +38 -1
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { arrayMove } from "@dnd-kit/sortable";
|
|
4
|
+
import { ArrowDownward, ArrowUpward, ClearAll, Close, FilterAlt, FilterList, FilterListOff, MoreVert, PushPin, Search, Sort, SyncAlt, ViewColumn, VisibilityOff } from "@mui/icons-material";
|
|
5
|
+
import { Box, Button, Divider, FormControlLabel, IconButton, InputAdornment, ListItemIcon, MenuItem, Paper, Switch, Table, TableBody, TableCell, TableHead, TablePagination, TableRow, TableSortLabel, TextField, Toolbar, Tooltip } from "@mui/material";
|
|
6
|
+
import { alpha, darken, lighten, useTheme } from "@mui/material/styles";
|
|
7
|
+
import { functionalUpdate, useTable } from "@tanstack/react-table";
|
|
8
|
+
import { MRT_FilterFns, MRT_SortingFns } from "material-react-table";
|
|
9
|
+
import { useStrings } from "../../strings/index.js";
|
|
10
|
+
import Button_Button from "../Button/Button.js";
|
|
11
|
+
import { ColumnDragBodyCell, ColumnDragHandle, ColumnDragMenu, ColumnDragTableContainer, DraggableColumnHeader, DraggableColumnItem } from "./ColumnDragging.js";
|
|
12
|
+
import EditableCellV2 from "./EditableCellV2.js";
|
|
13
|
+
import { EditableTableShowHideColumnsButtonV2, EditableTableToggleDensePaddingButtonV2, EditableTableToggleFiltersButtonV2, EditableTableToggleFullScreenButtonV2, EditableTableToggleGlobalFilterButtonV2, EditableTableToolbarRoot } from "./ToolbarButtons.js";
|
|
14
|
+
import { toInternalPinning, toPublicPinning } from "./pinning.js";
|
|
15
|
+
import { editableTableFeatures } from "./types.js";
|
|
16
|
+
const isActiveFilter = (filter)=>{
|
|
17
|
+
const values = Array.isArray(filter.value) ? filter.value : [
|
|
18
|
+
filter.value
|
|
19
|
+
];
|
|
20
|
+
return values.some((value)=>null != value && '' !== value);
|
|
21
|
+
};
|
|
22
|
+
const readFilters = (storageKey)=>{
|
|
23
|
+
try {
|
|
24
|
+
const saved = storageKey ? JSON.parse(localStorage.getItem(`${storageKey}_columnFilters`) ?? 'null') : null;
|
|
25
|
+
if (Array.isArray(saved) && saved.every((filter)=>'object' == typeof filter && null !== filter && 'id' in filter && 'string' == typeof filter.id && 'value' in filter)) return saved.filter(isActiveFilter);
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const pinnedStyles = (column, theme, offsets)=>{
|
|
31
|
+
const position = column.getIsPinned();
|
|
32
|
+
const background = theme.palette.background.default;
|
|
33
|
+
const baseBackground = 'dark' === theme.palette.mode ? lighten(background, 0.05) : background;
|
|
34
|
+
return {
|
|
35
|
+
width: column.getSize(),
|
|
36
|
+
minWidth: column.getSize(),
|
|
37
|
+
...position && {
|
|
38
|
+
position: 'sticky',
|
|
39
|
+
zIndex: 1,
|
|
40
|
+
opacity: 0.97,
|
|
41
|
+
'&::before': {
|
|
42
|
+
content: '""',
|
|
43
|
+
position: 'absolute',
|
|
44
|
+
inset: 0,
|
|
45
|
+
zIndex: -1,
|
|
46
|
+
backgroundColor: alpha(darken(baseBackground, 'dark' === theme.palette.mode ? 0.05 : 0.01), 0.97),
|
|
47
|
+
boxShadow: 'start' === position && column.getIsLastColumn('start') ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` : 'end' === position && column.getIsFirstColumn('end') ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` : void 0
|
|
48
|
+
},
|
|
49
|
+
...'start' === position ? {
|
|
50
|
+
insetInlineStart: offsets[column.id] ?? column.getStart('start')
|
|
51
|
+
} : {
|
|
52
|
+
insetInlineEnd: offsets[column.id] ?? column.getAfter('end')
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const UnsortedIcon = (props)=>/*#__PURE__*/ jsx(SyncAlt, {
|
|
58
|
+
...props,
|
|
59
|
+
style: {
|
|
60
|
+
...props.style,
|
|
61
|
+
transform: 'rotate(-90deg) scaleX(0.9) translateX(-1px)'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const ColumnActionMenuItemV2 = ({ icon, children, ...props })=>/*#__PURE__*/ jsx(MenuItem, {
|
|
65
|
+
sx: {
|
|
66
|
+
minWidth: '120px',
|
|
67
|
+
my: 0,
|
|
68
|
+
py: '6px'
|
|
69
|
+
},
|
|
70
|
+
...props,
|
|
71
|
+
children: /*#__PURE__*/ jsxs(Box, {
|
|
72
|
+
display: "flex",
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
children: [
|
|
75
|
+
/*#__PURE__*/ jsx(ListItemIcon, {
|
|
76
|
+
children: icon
|
|
77
|
+
}),
|
|
78
|
+
children
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const ColumnFilter = ({ column, definition })=>{
|
|
83
|
+
const strings = useStrings();
|
|
84
|
+
const label = `${strings.TABLE_FILTER}: ${definition.header}`;
|
|
85
|
+
const placeholder = strings.TABLE_FILTER_BY.replace('{column}', definition.header);
|
|
86
|
+
const value = column.getFilterValue();
|
|
87
|
+
if ('range' === definition.filterVariant || 'date-range' === definition.filterVariant) {
|
|
88
|
+
const range = Array.isArray(value) ? value : [
|
|
89
|
+
'',
|
|
90
|
+
''
|
|
91
|
+
];
|
|
92
|
+
return /*#__PURE__*/ jsx(Box, {
|
|
93
|
+
display: "flex",
|
|
94
|
+
gap: 1,
|
|
95
|
+
children: [
|
|
96
|
+
0,
|
|
97
|
+
1
|
|
98
|
+
].map((index)=>/*#__PURE__*/ jsx(TextField, {
|
|
99
|
+
size: "small",
|
|
100
|
+
variant: "standard",
|
|
101
|
+
placeholder: 0 === index ? strings.TABLE_MIN : strings.TABLE_MAX,
|
|
102
|
+
type: 'date-range' === definition.filterVariant ? 'date' : 'number',
|
|
103
|
+
value: range[index] ?? '',
|
|
104
|
+
slotProps: {
|
|
105
|
+
htmlInput: {
|
|
106
|
+
'aria-label': `${label} ${0 === index ? strings.TABLE_MIN : strings.TABLE_MAX}`
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
onChange: (event)=>{
|
|
110
|
+
const next = [
|
|
111
|
+
...range
|
|
112
|
+
];
|
|
113
|
+
next[index] = event.target.value;
|
|
114
|
+
column.setFilterValue(next.some((entry)=>'' !== entry) ? next : void 0);
|
|
115
|
+
}
|
|
116
|
+
}, index))
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const multiple = 'multi-select' === definition.filterVariant;
|
|
120
|
+
const select = multiple || 'select' === definition.filterVariant;
|
|
121
|
+
return /*#__PURE__*/ jsxs(TextField, {
|
|
122
|
+
fullWidth: true,
|
|
123
|
+
variant: "standard",
|
|
124
|
+
placeholder: placeholder,
|
|
125
|
+
sx: {
|
|
126
|
+
minWidth: 120,
|
|
127
|
+
mx: '-2px',
|
|
128
|
+
p: 0,
|
|
129
|
+
width: 'calc(100% + 4px)'
|
|
130
|
+
},
|
|
131
|
+
select: select,
|
|
132
|
+
value: value ?? (multiple ? [] : ''),
|
|
133
|
+
onChange: (event)=>{
|
|
134
|
+
const next = event.target.value;
|
|
135
|
+
column.setFilterValue(Array.isArray(next) && !next.length ? void 0 : next || void 0);
|
|
136
|
+
},
|
|
137
|
+
slotProps: {
|
|
138
|
+
htmlInput: {
|
|
139
|
+
'aria-label': label
|
|
140
|
+
},
|
|
141
|
+
input: {
|
|
142
|
+
endAdornment: /*#__PURE__*/ jsx(InputAdornment, {
|
|
143
|
+
position: "end",
|
|
144
|
+
sx: {
|
|
145
|
+
mr: select ? '20px' : void 0,
|
|
146
|
+
visibility: isActiveFilter({
|
|
147
|
+
value
|
|
148
|
+
}) ? 'visible' : 'hidden'
|
|
149
|
+
},
|
|
150
|
+
children: /*#__PURE__*/ jsx(IconButton, {
|
|
151
|
+
size: "small",
|
|
152
|
+
"aria-label": `${strings.TABLE_CLEAR_FILTER}: ${definition.header}`,
|
|
153
|
+
disabled: !isActiveFilter({
|
|
154
|
+
value
|
|
155
|
+
}),
|
|
156
|
+
onClick: ()=>column.setFilterValue(void 0),
|
|
157
|
+
sx: {
|
|
158
|
+
height: '2rem',
|
|
159
|
+
width: '2rem',
|
|
160
|
+
transform: 'scale(0.9)'
|
|
161
|
+
},
|
|
162
|
+
children: /*#__PURE__*/ jsx(Close, {})
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
select: {
|
|
167
|
+
multiple,
|
|
168
|
+
displayEmpty: true,
|
|
169
|
+
'aria-label': label,
|
|
170
|
+
renderValue: (selected)=>(Array.isArray(selected) ? selected.join(', ') : String(selected ?? '')) || /*#__PURE__*/ jsx(Box, {
|
|
171
|
+
sx: {
|
|
172
|
+
opacity: 0.5
|
|
173
|
+
},
|
|
174
|
+
children: placeholder
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
children: [
|
|
179
|
+
select && !multiple && /*#__PURE__*/ jsx(MenuItem, {
|
|
180
|
+
value: "",
|
|
181
|
+
children: strings.TABLE_ALL
|
|
182
|
+
}),
|
|
183
|
+
select && definition.filterSelectOptions?.map((option)=>/*#__PURE__*/ jsx(MenuItem, {
|
|
184
|
+
value: option,
|
|
185
|
+
children: option
|
|
186
|
+
}, option))
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const EditableTableV2 = ({ clearAllFiltersLabel, columns, data, enableClearAllFilters = true, enableEditing = false, enableColumnOrdering = false, enableColumnDragging = false, enableColumnActions = true, enableShowAllColumnsMenuItem = true, showColumnsButton = false, showGlobalFilterButton = false, showColumnFiltersButton = false, showDensityButton = false, showFullScreenButton = false, enableColumnPinning = false, enableHiding = true, enableSorting = true, enableGlobalFilter = false, positionGlobalFilter = 'left', enableColumnFilters = false, stickyFilters = false, storageKey, enablePagination = true, enableBottomToolbar = true, enableTopToolbar = true, initialSorting, onClearAllFilters, onRowClick, renderToolbarInternalActions, renderTopToolbarCustomActions, muiTableHeadCellProps, muiTableBodyCellProps, tableOptions, containerProps, sx })=>{
|
|
191
|
+
const strings = useStrings();
|
|
192
|
+
const theme = useTheme();
|
|
193
|
+
const [editingCell, setEditingCell] = useState(null);
|
|
194
|
+
const [globalFilterVisible, setGlobalFilterVisible] = useState(true);
|
|
195
|
+
const [columnFiltersVisible, setColumnFiltersVisible] = useState(false);
|
|
196
|
+
const [density, setDensity] = useState();
|
|
197
|
+
const [fullScreen, setFullScreen] = useState(false);
|
|
198
|
+
const [menuColumnId, setMenuColumnId] = useState(null);
|
|
199
|
+
const [menuAnchor, setMenuAnchor] = useState(null);
|
|
200
|
+
const [columnsButtonCount, setColumnsButtonCount] = useState(0);
|
|
201
|
+
const registerColumnsButton = useCallback(()=>{
|
|
202
|
+
setColumnsButtonCount((count)=>count + 1);
|
|
203
|
+
return ()=>setColumnsButtonCount((count)=>count - 1);
|
|
204
|
+
}, []);
|
|
205
|
+
const [initialColumnFilters] = useState(()=>tableOptions?.initialState?.columnFilters ?? []);
|
|
206
|
+
const [columnFilters, setColumnFilters] = useState(()=>readFilters(stickyFilters ? storageKey : void 0) ?? initialColumnFilters);
|
|
207
|
+
useEffect(()=>{
|
|
208
|
+
setColumnFilters(readFilters(stickyFilters ? storageKey : void 0) ?? initialColumnFilters);
|
|
209
|
+
}, [
|
|
210
|
+
stickyFilters,
|
|
211
|
+
storageKey,
|
|
212
|
+
initialColumnFilters
|
|
213
|
+
]);
|
|
214
|
+
const tableColumns = useMemo(()=>columns.map((column)=>({
|
|
215
|
+
id: column.id,
|
|
216
|
+
header: column.header,
|
|
217
|
+
meta: {
|
|
218
|
+
filterVariant: column.filterVariant,
|
|
219
|
+
filterSelectOptions: column.filterSelectOptions
|
|
220
|
+
},
|
|
221
|
+
accessorFn: column.accessorFn ?? ((row)=>void 0 !== column.accessorKey ? row[column.accessorKey] : void 0),
|
|
222
|
+
size: column.size,
|
|
223
|
+
enableHiding: column.enableHiding ?? true,
|
|
224
|
+
enableColumnFilter: !!column.filterVariant,
|
|
225
|
+
...void 0 !== column.enableSorting ? {
|
|
226
|
+
enableSorting: column.enableSorting
|
|
227
|
+
} : column.accessorFn || void 0 !== column.accessorKey || column.sortFn || 'sortingFn' in column && column.sortingFn ? {} : {
|
|
228
|
+
enableSorting: false
|
|
229
|
+
},
|
|
230
|
+
...column.sortFn || column.sortingFn ? {
|
|
231
|
+
sortFn: column.sortFn ?? ('function' == typeof column.sortingFn ? column.sortingFn : column.sortingFn && 'auto' !== column.sortingFn ? MRT_SortingFns[column.sortingFn] : 'auto')
|
|
232
|
+
} : {},
|
|
233
|
+
filterFn: Object.assign((row, id, filterValue, addMeta)=>{
|
|
234
|
+
if ('function' == typeof column.filterFn) return column.filterFn(row.original, id, filterValue);
|
|
235
|
+
if (column.filterFn) {
|
|
236
|
+
const filter = MRT_FilterFns[column.filterFn];
|
|
237
|
+
return filter(row, id, filterValue, addMeta);
|
|
238
|
+
}
|
|
239
|
+
const value = row.getValue(id);
|
|
240
|
+
if ('select' === column.filterVariant) return String(value ?? '') === String(filterValue);
|
|
241
|
+
if ('multi-select' === column.filterVariant) return !Array.isArray(filterValue) || !filterValue.length || filterValue.some((selected)=>Array.isArray(value) ? value.includes(selected) : String(value ?? '') === String(selected));
|
|
242
|
+
if ('range' === column.filterVariant || 'date-range' === column.filterVariant) {
|
|
243
|
+
const [min, max] = Array.isArray(filterValue) ? filterValue : [];
|
|
244
|
+
const normalize = (entry)=>'date-range' === column.filterVariant ? Date.parse(String(entry)) : Number(entry);
|
|
245
|
+
const numeric = normalize(value);
|
|
246
|
+
return null != value && '' !== value && Number.isFinite(numeric) && ('' === min || null == min || numeric >= normalize(min)) && ('' === max || null == max || ('date-range' === column.filterVariant && 'string' == typeof max && /^\d{4}-\d{2}-\d{2}$/.test(max) ? numeric < normalize(max) + 86400000 : numeric <= normalize(max)));
|
|
247
|
+
}
|
|
248
|
+
return String(value ?? '').toLocaleLowerCase().includes(String(filterValue).toLocaleLowerCase());
|
|
249
|
+
}, {
|
|
250
|
+
autoRemove: 'string' == typeof column.filterFn ? MRT_FilterFns[column.filterFn].autoRemove : void 0
|
|
251
|
+
})
|
|
252
|
+
})), [
|
|
253
|
+
columns,
|
|
254
|
+
tableOptions?.defaultColumn
|
|
255
|
+
]);
|
|
256
|
+
const persistFilters = stickyFilters && !!storageKey && tableOptions?.state?.columnFilters === void 0;
|
|
257
|
+
const { state, initialState, onColumnPinningChange, ...options } = tableOptions ?? {};
|
|
258
|
+
const { columnPinning: controlledPinning, ...controlledState } = state ?? {};
|
|
259
|
+
const { columnPinning: initialPinning, ...initialTableState } = initialState ?? {};
|
|
260
|
+
const table = useTable({
|
|
261
|
+
features: editableTableFeatures,
|
|
262
|
+
columns: tableColumns,
|
|
263
|
+
data,
|
|
264
|
+
enableSorting,
|
|
265
|
+
sortDescFirst: false,
|
|
266
|
+
enableColumnPinning,
|
|
267
|
+
enableHiding,
|
|
268
|
+
enableColumnFilters,
|
|
269
|
+
enableGlobalFilter,
|
|
270
|
+
manualPagination: !enablePagination,
|
|
271
|
+
...options,
|
|
272
|
+
initialState: {
|
|
273
|
+
sorting: initialSorting ?? [],
|
|
274
|
+
...initialTableState,
|
|
275
|
+
...initialPinning && {
|
|
276
|
+
columnPinning: toInternalPinning(initialPinning)
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
state: {
|
|
280
|
+
...controlledState,
|
|
281
|
+
...controlledPinning && {
|
|
282
|
+
columnPinning: toInternalPinning(controlledPinning)
|
|
283
|
+
},
|
|
284
|
+
...persistFilters && {
|
|
285
|
+
columnFilters
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
...onColumnPinningChange && {
|
|
289
|
+
onColumnPinningChange: (updater)=>onColumnPinningChange((previous)=>{
|
|
290
|
+
const next = functionalUpdate(updater, toInternalPinning(previous));
|
|
291
|
+
return toPublicPinning(next);
|
|
292
|
+
})
|
|
293
|
+
},
|
|
294
|
+
...persistFilters && {
|
|
295
|
+
onColumnFiltersChange: (updater)=>{
|
|
296
|
+
setColumnFilters((previous)=>{
|
|
297
|
+
const next = 'function' == typeof updater ? updater(previous) : updater;
|
|
298
|
+
try {
|
|
299
|
+
localStorage.setItem(`${storageKey}_columnFilters`, JSON.stringify(next.filter(isActiveFilter)));
|
|
300
|
+
} catch {}
|
|
301
|
+
return next;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
const hasFilters = table.state.columnFilters.some(isActiveFilter) || !!table.state.globalFilter;
|
|
307
|
+
const clearFilters = ()=>{
|
|
308
|
+
table.setColumnFilters([]);
|
|
309
|
+
table.setGlobalFilter('');
|
|
310
|
+
onClearAllFilters?.();
|
|
311
|
+
};
|
|
312
|
+
const definitions = new Map(columns.map((column)=>[
|
|
313
|
+
column.id,
|
|
314
|
+
column
|
|
315
|
+
]));
|
|
316
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
317
|
+
const allColumns = [
|
|
318
|
+
...table.getStartLeafColumns(),
|
|
319
|
+
...table.getCenterLeafColumns(),
|
|
320
|
+
...table.getEndLeafColumns()
|
|
321
|
+
];
|
|
322
|
+
const orderedColumns = [
|
|
323
|
+
...table.getStartVisibleLeafColumns(),
|
|
324
|
+
...table.getCenterVisibleLeafColumns(),
|
|
325
|
+
...table.getEndVisibleLeafColumns()
|
|
326
|
+
];
|
|
327
|
+
const rows = table.getRowModel().rows;
|
|
328
|
+
const pageCountWithoutRowCount = table.options.manualPagination && void 0 !== table.options.pageCount && table.options.pageCount >= 0 && void 0 === table.options.rowCount;
|
|
329
|
+
const nextPageButton = {
|
|
330
|
+
disabled: !table.getCanNextPage()
|
|
331
|
+
};
|
|
332
|
+
const lastPageButton = {
|
|
333
|
+
disabled: !table.getCanNextPage(),
|
|
334
|
+
onClick: ()=>table.setPageIndex(Math.max(0, table.getPageCount() - 1))
|
|
335
|
+
};
|
|
336
|
+
const tableRef = useRef(null);
|
|
337
|
+
const [renderedWidths, setRenderedWidths] = useState({});
|
|
338
|
+
const visibleColumnIds = JSON.stringify(orderedColumns.map((column)=>column.id));
|
|
339
|
+
const hasPinnedColumns = orderedColumns.some((column)=>column.getIsPinned());
|
|
340
|
+
useLayoutEffect(()=>{
|
|
341
|
+
if (!tableRef.current || !hasPinnedColumns) return;
|
|
342
|
+
const headers = Array.from(tableRef.current.querySelectorAll('thead th[data-column-id]'));
|
|
343
|
+
const measure = ()=>{
|
|
344
|
+
const next = {};
|
|
345
|
+
headers.forEach((header)=>{
|
|
346
|
+
const width = header.getBoundingClientRect().width;
|
|
347
|
+
if (header.dataset.columnId && width > 0) next[header.dataset.columnId] = width;
|
|
348
|
+
});
|
|
349
|
+
setRenderedWidths((current)=>Object.keys(current).length === Object.keys(next).length && Object.keys(next).every((id)=>current[id] === next[id]) ? current : next);
|
|
350
|
+
};
|
|
351
|
+
measure();
|
|
352
|
+
if ("u" < typeof ResizeObserver) return;
|
|
353
|
+
const observer = new ResizeObserver(measure);
|
|
354
|
+
headers.forEach((header)=>observer.observe(header));
|
|
355
|
+
return ()=>observer.disconnect();
|
|
356
|
+
}, [
|
|
357
|
+
visibleColumnIds,
|
|
358
|
+
hasPinnedColumns
|
|
359
|
+
]);
|
|
360
|
+
const pinnedOffsets = {};
|
|
361
|
+
for (const group of [
|
|
362
|
+
table.getStartVisibleLeafColumns(),
|
|
363
|
+
[
|
|
364
|
+
...table.getEndVisibleLeafColumns()
|
|
365
|
+
].reverse()
|
|
366
|
+
]){
|
|
367
|
+
let offset = 0;
|
|
368
|
+
for (const column of group){
|
|
369
|
+
pinnedOffsets[column.id] = offset;
|
|
370
|
+
offset += renderedWidths[column.id] ?? column.getSize();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const controlsEnabled = enableHiding || enableColumnOrdering || enableColumnPinning;
|
|
374
|
+
const columnManagerReachable = columnsButtonCount > 0;
|
|
375
|
+
const hideableColumns = table.getAllLeafColumns().filter((column)=>column.getCanHide());
|
|
376
|
+
const filtersVisible = enableColumnFilters && columnFiltersVisible;
|
|
377
|
+
useEffect(()=>{
|
|
378
|
+
if (!fullScreen) return;
|
|
379
|
+
const onKeyDown = (event)=>{
|
|
380
|
+
if ('Escape' === event.key) setFullScreen(false);
|
|
381
|
+
};
|
|
382
|
+
const overflow = document.body.style.overflow;
|
|
383
|
+
document.body.style.overflow = 'hidden';
|
|
384
|
+
document.addEventListener('keydown', onKeyDown);
|
|
385
|
+
return ()=>{
|
|
386
|
+
document.body.style.overflow = overflow;
|
|
387
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
388
|
+
};
|
|
389
|
+
}, [
|
|
390
|
+
fullScreen
|
|
391
|
+
]);
|
|
392
|
+
const moveColumn = (id, offset)=>{
|
|
393
|
+
const index = allColumns.findIndex((column)=>column.id === id);
|
|
394
|
+
const column = allColumns[index];
|
|
395
|
+
const target = allColumns[index + offset];
|
|
396
|
+
if (!column || !target || column.getIsPinned() !== target.getIsPinned()) return;
|
|
397
|
+
const swap = (order)=>{
|
|
398
|
+
const from = order.indexOf(id);
|
|
399
|
+
const to = order.indexOf(target.id);
|
|
400
|
+
if (from < 0 || to < 0) return order;
|
|
401
|
+
const next = [
|
|
402
|
+
...order
|
|
403
|
+
];
|
|
404
|
+
[next[from], next[to]] = [
|
|
405
|
+
next[to],
|
|
406
|
+
next[from]
|
|
407
|
+
];
|
|
408
|
+
return next;
|
|
409
|
+
};
|
|
410
|
+
const pinned = column.getIsPinned();
|
|
411
|
+
if (pinned) table.setColumnPinning((current)=>({
|
|
412
|
+
...current,
|
|
413
|
+
[pinned]: swap(current[pinned])
|
|
414
|
+
}));
|
|
415
|
+
else table.setColumnOrder(swap(table.getAllLeafColumns().map((column)=>column.id)));
|
|
416
|
+
};
|
|
417
|
+
const reorderColumns = ({ active, over })=>{
|
|
418
|
+
if (!over || active.id === over.id) return;
|
|
419
|
+
const source = table.getAllLeafColumns().find((column)=>column.id === active.id);
|
|
420
|
+
const target = table.getAllLeafColumns().find((column)=>column.id === over.id);
|
|
421
|
+
if (!source || !target || source.getIsPinned() !== target.getIsPinned()) return;
|
|
422
|
+
const pin = source.getIsPinned();
|
|
423
|
+
const order = table.getAllLeafColumns().map((column)=>column.id);
|
|
424
|
+
table.setColumnOrder(arrayMove(order, order.indexOf(source.id), order.indexOf(target.id)));
|
|
425
|
+
if (pin) table.setColumnPinning((previous)=>{
|
|
426
|
+
const group = previous[pin] ?? [];
|
|
427
|
+
return {
|
|
428
|
+
...previous,
|
|
429
|
+
[pin]: arrayMove(group, group.indexOf(source.id), group.indexOf(target.id))
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
const searchField = enableGlobalFilter && globalFilterVisible && /*#__PURE__*/ jsx(TextField, {
|
|
434
|
+
placeholder: strings.TABLE_SEARCH,
|
|
435
|
+
size: "small",
|
|
436
|
+
slotProps: {
|
|
437
|
+
htmlInput: {
|
|
438
|
+
'aria-label': strings.TABLE_SEARCH
|
|
439
|
+
},
|
|
440
|
+
input: {
|
|
441
|
+
startAdornment: /*#__PURE__*/ jsx(Search, {
|
|
442
|
+
sx: {
|
|
443
|
+
mr: '4px'
|
|
444
|
+
}
|
|
445
|
+
}),
|
|
446
|
+
endAdornment: /*#__PURE__*/ jsx(InputAdornment, {
|
|
447
|
+
position: "end",
|
|
448
|
+
children: /*#__PURE__*/ jsx(IconButton, {
|
|
449
|
+
size: "small",
|
|
450
|
+
"aria-label": strings.TABLE_CLEAR_SEARCH,
|
|
451
|
+
disabled: !table.state.globalFilter,
|
|
452
|
+
onClick: ()=>table.setGlobalFilter(''),
|
|
453
|
+
children: /*#__PURE__*/ jsx(Close, {})
|
|
454
|
+
})
|
|
455
|
+
})
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
value: table.state.globalFilter ?? '',
|
|
459
|
+
onChange: (event)=>table.setGlobalFilter(event.target.value)
|
|
460
|
+
});
|
|
461
|
+
return /*#__PURE__*/ jsx(EditableTableToolbarRoot, {
|
|
462
|
+
value: {
|
|
463
|
+
table,
|
|
464
|
+
globalFilterVisible,
|
|
465
|
+
columnFiltersVisible,
|
|
466
|
+
density: density ?? 1,
|
|
467
|
+
fullScreen,
|
|
468
|
+
registerColumnsButton,
|
|
469
|
+
toggleGlobalFilter: ()=>setGlobalFilterVisible((visible)=>!visible),
|
|
470
|
+
toggleColumnFilters: ()=>setColumnFiltersVisible((visible)=>!visible),
|
|
471
|
+
toggleDensity: ()=>setDensity((value)=>((value ?? 1) + 2) % 3),
|
|
472
|
+
toggleFullScreen: ()=>setFullScreen((value)=>!value),
|
|
473
|
+
openColumns: (anchor)=>{
|
|
474
|
+
setMenuColumnId(null);
|
|
475
|
+
setMenuAnchor(anchor);
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
minHeight: "160px",
|
|
479
|
+
padding: 2,
|
|
480
|
+
sx: [
|
|
481
|
+
...Array.isArray(sx) ? sx : [
|
|
482
|
+
sx
|
|
483
|
+
],
|
|
484
|
+
...showDensityButton || void 0 !== density ? [
|
|
485
|
+
{
|
|
486
|
+
'& td': {
|
|
487
|
+
py: 0 === density ? '4px' : 2 === density ? '24px' : '16px'
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
] : [],
|
|
491
|
+
...fullScreen ? [
|
|
492
|
+
{
|
|
493
|
+
position: 'fixed',
|
|
494
|
+
inset: 0,
|
|
495
|
+
m: 0,
|
|
496
|
+
p: 0,
|
|
497
|
+
zIndex: 1200,
|
|
498
|
+
bgcolor: 'background.paper',
|
|
499
|
+
overflow: 'auto'
|
|
500
|
+
}
|
|
501
|
+
] : []
|
|
502
|
+
],
|
|
503
|
+
children: /*#__PURE__*/ jsxs(Paper, {
|
|
504
|
+
elevation: 0,
|
|
505
|
+
children: [
|
|
506
|
+
enableTopToolbar && /*#__PURE__*/ jsxs(Toolbar, {
|
|
507
|
+
disableGutters: true,
|
|
508
|
+
sx: {
|
|
509
|
+
gap: 1,
|
|
510
|
+
flexWrap: 'wrap',
|
|
511
|
+
alignItems: 'flex-start',
|
|
512
|
+
p: 1,
|
|
513
|
+
minHeight: '56px !important',
|
|
514
|
+
boxSizing: 'border-box'
|
|
515
|
+
},
|
|
516
|
+
children: [
|
|
517
|
+
'left' === positionGlobalFilter && searchField,
|
|
518
|
+
renderTopToolbarCustomActions?.({
|
|
519
|
+
table
|
|
520
|
+
}),
|
|
521
|
+
/*#__PURE__*/ jsx(Box, {
|
|
522
|
+
flexGrow: 1
|
|
523
|
+
}),
|
|
524
|
+
'right' === positionGlobalFilter && searchField,
|
|
525
|
+
enableClearAllFilters && hasFilters && /*#__PURE__*/ jsx(Button_Button, {
|
|
526
|
+
label: clearAllFiltersLabel,
|
|
527
|
+
priority: "ghost",
|
|
528
|
+
size: "small",
|
|
529
|
+
onClick: clearFilters
|
|
530
|
+
}),
|
|
531
|
+
/*#__PURE__*/ jsx(Box, {
|
|
532
|
+
display: "flex",
|
|
533
|
+
alignItems: "center",
|
|
534
|
+
children: renderToolbarInternalActions ? renderToolbarInternalActions({
|
|
535
|
+
table
|
|
536
|
+
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
537
|
+
children: [
|
|
538
|
+
showGlobalFilterButton && enableGlobalFilter && /*#__PURE__*/ jsx(EditableTableToggleGlobalFilterButtonV2, {
|
|
539
|
+
table: table
|
|
540
|
+
}),
|
|
541
|
+
showColumnFiltersButton && enableColumnFilters && /*#__PURE__*/ jsx(EditableTableToggleFiltersButtonV2, {
|
|
542
|
+
table: table
|
|
543
|
+
}),
|
|
544
|
+
showColumnsButton && controlsEnabled && /*#__PURE__*/ jsx(EditableTableShowHideColumnsButtonV2, {
|
|
545
|
+
table: table
|
|
546
|
+
}),
|
|
547
|
+
showDensityButton && /*#__PURE__*/ jsx(EditableTableToggleDensePaddingButtonV2, {
|
|
548
|
+
table: table
|
|
549
|
+
}),
|
|
550
|
+
showFullScreenButton && /*#__PURE__*/ jsx(EditableTableToggleFullScreenButtonV2, {
|
|
551
|
+
table: table
|
|
552
|
+
})
|
|
553
|
+
]
|
|
554
|
+
})
|
|
555
|
+
})
|
|
556
|
+
]
|
|
557
|
+
}),
|
|
558
|
+
/*#__PURE__*/ jsxs(ColumnDragMenu, {
|
|
559
|
+
ids: allColumns.map((column)=>column.id),
|
|
560
|
+
onDragEnd: reorderColumns,
|
|
561
|
+
anchorEl: menuAnchor,
|
|
562
|
+
open: !!menuAnchor,
|
|
563
|
+
onClose: ()=>setMenuAnchor(null),
|
|
564
|
+
children: [
|
|
565
|
+
menuColumnId && table.getColumn(menuColumnId)?.getCanSort() && [
|
|
566
|
+
{
|
|
567
|
+
label: strings.TABLE_CLEAR_SORTING,
|
|
568
|
+
icon: /*#__PURE__*/ jsx(ClearAll, {}),
|
|
569
|
+
disabled: !table.getColumn(menuColumnId)?.getIsSorted(),
|
|
570
|
+
action: ()=>table.getColumn(menuColumnId)?.clearSorting()
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
label: strings.TABLE_SORT_ASCENDING.replace('{column}', definitions.get(menuColumnId).header),
|
|
574
|
+
icon: /*#__PURE__*/ jsx(Sort, {
|
|
575
|
+
sx: {
|
|
576
|
+
transform: 'rotate(180deg) scaleX(-1)'
|
|
577
|
+
}
|
|
578
|
+
}),
|
|
579
|
+
disabled: table.getColumn(menuColumnId)?.getIsSorted() === 'asc',
|
|
580
|
+
action: ()=>table.getColumn(menuColumnId)?.toggleSorting(false)
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
label: strings.TABLE_SORT_DESCENDING.replace('{column}', definitions.get(menuColumnId).header),
|
|
584
|
+
icon: /*#__PURE__*/ jsx(Sort, {}),
|
|
585
|
+
disabled: table.getColumn(menuColumnId)?.getIsSorted() === 'desc',
|
|
586
|
+
divider: table.getColumn(menuColumnId)?.getCanFilter() || enableHiding || enableColumnPinning,
|
|
587
|
+
action: ()=>table.getColumn(menuColumnId)?.toggleSorting(true)
|
|
588
|
+
}
|
|
589
|
+
].map(({ label, icon, disabled, divider, action })=>/*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
590
|
+
icon: icon,
|
|
591
|
+
disabled: disabled,
|
|
592
|
+
divider: divider,
|
|
593
|
+
onClick: ()=>{
|
|
594
|
+
action();
|
|
595
|
+
setMenuAnchor(null);
|
|
596
|
+
},
|
|
597
|
+
children: label
|
|
598
|
+
}, label)),
|
|
599
|
+
menuColumnId && table.getColumn(menuColumnId)?.getCanFilter() && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
600
|
+
icon: /*#__PURE__*/ jsx(FilterListOff, {}),
|
|
601
|
+
disabled: !table.getColumn(menuColumnId)?.getIsFiltered(),
|
|
602
|
+
onClick: ()=>{
|
|
603
|
+
table.getColumn(menuColumnId)?.setFilterValue(void 0);
|
|
604
|
+
setMenuAnchor(null);
|
|
605
|
+
},
|
|
606
|
+
children: strings.TABLE_CLEAR_FILTER
|
|
607
|
+
}),
|
|
608
|
+
menuColumnId && table.getColumn(menuColumnId)?.getCanFilter() && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
609
|
+
icon: /*#__PURE__*/ jsx(FilterList, {}),
|
|
610
|
+
disabled: true,
|
|
611
|
+
divider: enableHiding || enableColumnPinning,
|
|
612
|
+
children: strings.TABLE_FILTER_BY.replace('{column}', definitions.get(menuColumnId).header)
|
|
613
|
+
}),
|
|
614
|
+
menuColumnId && enableColumnPinning && [
|
|
615
|
+
{
|
|
616
|
+
label: strings.TABLE_PIN_LEFT,
|
|
617
|
+
direction: 'start',
|
|
618
|
+
rotation: '90deg'
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
label: strings.TABLE_PIN_RIGHT,
|
|
622
|
+
direction: 'end',
|
|
623
|
+
rotation: '-90deg'
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
label: strings.TABLE_UNPIN,
|
|
627
|
+
direction: false,
|
|
628
|
+
rotation: '0deg'
|
|
629
|
+
}
|
|
630
|
+
].map(({ label, direction, rotation })=>/*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
631
|
+
icon: /*#__PURE__*/ jsx(PushPin, {
|
|
632
|
+
sx: {
|
|
633
|
+
transform: `rotate(${rotation})`
|
|
634
|
+
}
|
|
635
|
+
}),
|
|
636
|
+
disabled: !table.getColumn(menuColumnId)?.getCanPin() || table.getColumn(menuColumnId)?.getIsPinned() === direction,
|
|
637
|
+
divider: false === direction && enableHiding,
|
|
638
|
+
onClick: ()=>{
|
|
639
|
+
table.getColumn(menuColumnId)?.pin(direction);
|
|
640
|
+
setMenuAnchor(null);
|
|
641
|
+
},
|
|
642
|
+
children: label
|
|
643
|
+
}, label)),
|
|
644
|
+
menuColumnId && enableHiding && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
645
|
+
icon: /*#__PURE__*/ jsx(VisibilityOff, {}),
|
|
646
|
+
disabled: !table.getColumn(menuColumnId)?.getCanHide() || !columnManagerReachable && 1 === orderedColumns.length,
|
|
647
|
+
onClick: ()=>{
|
|
648
|
+
table.getColumn(menuColumnId)?.toggleVisibility(false);
|
|
649
|
+
setMenuAnchor(null);
|
|
650
|
+
},
|
|
651
|
+
children: strings.TABLE_HIDE_COLUMN.replace('{column}', definitions.get(menuColumnId).header)
|
|
652
|
+
}),
|
|
653
|
+
menuColumnId && enableHiding && enableShowAllColumnsMenuItem && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
|
|
654
|
+
icon: /*#__PURE__*/ jsx(ViewColumn, {}),
|
|
655
|
+
disabled: table.getAllLeafColumns().every((column)=>column.getIsVisible() || !column.getCanHide()),
|
|
656
|
+
onClick: ()=>{
|
|
657
|
+
table.getAllLeafColumns().filter((column)=>column.getCanHide()).forEach((column)=>column.toggleVisibility(true));
|
|
658
|
+
setMenuAnchor(null);
|
|
659
|
+
},
|
|
660
|
+
children: strings.TABLE_SHOW_ALL_COLUMNS
|
|
661
|
+
}),
|
|
662
|
+
!menuColumnId && enableHiding && /*#__PURE__*/ jsxs(Box, {
|
|
663
|
+
display: "flex",
|
|
664
|
+
justifyContent: "space-between",
|
|
665
|
+
px: 1,
|
|
666
|
+
pb: 1,
|
|
667
|
+
children: [
|
|
668
|
+
/*#__PURE__*/ jsx(Button, {
|
|
669
|
+
disabled: !hideableColumns.some((column)=>column.getIsVisible()) || !columnManagerReachable && orderedColumns.every((column)=>column.getCanHide()),
|
|
670
|
+
onClick: ()=>hideableColumns.forEach((column)=>column.toggleVisibility(false)),
|
|
671
|
+
children: strings.TABLE_HIDE_ALL
|
|
672
|
+
}),
|
|
673
|
+
/*#__PURE__*/ jsx(Button, {
|
|
674
|
+
disabled: hideableColumns.every((column)=>column.getIsVisible()),
|
|
675
|
+
onClick: ()=>hideableColumns.forEach((column)=>column.toggleVisibility(true)),
|
|
676
|
+
children: strings.TABLE_SHOW_ALL
|
|
677
|
+
})
|
|
678
|
+
]
|
|
679
|
+
}),
|
|
680
|
+
!menuColumnId && controlsEnabled && /*#__PURE__*/ jsx(Divider, {}),
|
|
681
|
+
allColumns.map((column, index)=>!menuColumnId && controlsEnabled && /*#__PURE__*/ jsxs(DraggableColumnItem, {
|
|
682
|
+
id: column.id,
|
|
683
|
+
label: definitions.get(column.id).header,
|
|
684
|
+
enabled: enableColumnOrdering,
|
|
685
|
+
disableRipple: true,
|
|
686
|
+
sx: {
|
|
687
|
+
my: 0,
|
|
688
|
+
py: '6px',
|
|
689
|
+
pl: '16px'
|
|
690
|
+
},
|
|
691
|
+
children: [
|
|
692
|
+
/*#__PURE__*/ jsx(ColumnDragHandle, {}),
|
|
693
|
+
/*#__PURE__*/ jsx(FormControlLabel, {
|
|
694
|
+
label: definitions.get(column.id)?.header,
|
|
695
|
+
slotProps: {
|
|
696
|
+
typography: {
|
|
697
|
+
sx: {
|
|
698
|
+
mb: 0
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
control: /*#__PURE__*/ jsx(Switch, {
|
|
703
|
+
checked: column.getIsVisible(),
|
|
704
|
+
disabled: !enableHiding || !column.getCanHide() || !columnManagerReachable && column.getIsVisible() && 1 === orderedColumns.length,
|
|
705
|
+
onChange: column.getToggleVisibilityHandler()
|
|
706
|
+
})
|
|
707
|
+
}),
|
|
708
|
+
enableColumnOrdering && /*#__PURE__*/ jsxs(Fragment, {
|
|
709
|
+
children: [
|
|
710
|
+
/*#__PURE__*/ jsx(IconButton, {
|
|
711
|
+
"aria-label": `${strings.TABLE_MOVE_BACK}: ${definitions.get(column.id)?.header}`,
|
|
712
|
+
disabled: allColumns[index - 1]?.getIsPinned() !== column.getIsPinned(),
|
|
713
|
+
onClick: ()=>moveColumn(column.id, -1),
|
|
714
|
+
children: /*#__PURE__*/ jsx(ArrowUpward, {})
|
|
715
|
+
}),
|
|
716
|
+
/*#__PURE__*/ jsx(IconButton, {
|
|
717
|
+
"aria-label": `${strings.TABLE_MOVE_FORWARD}: ${definitions.get(column.id)?.header}`,
|
|
718
|
+
disabled: allColumns[index + 1]?.getIsPinned() !== column.getIsPinned(),
|
|
719
|
+
onClick: ()=>moveColumn(column.id, 1),
|
|
720
|
+
children: /*#__PURE__*/ jsx(ArrowDownward, {})
|
|
721
|
+
})
|
|
722
|
+
]
|
|
723
|
+
}),
|
|
724
|
+
enableColumnPinning && /*#__PURE__*/ jsxs(TextField, {
|
|
725
|
+
select: true,
|
|
726
|
+
size: "small",
|
|
727
|
+
label: strings.TABLE_PIN,
|
|
728
|
+
disabled: !column.getCanPin(),
|
|
729
|
+
value: 'start' === column.getIsPinned() ? 'left' : 'end' === column.getIsPinned() ? 'right' : '',
|
|
730
|
+
onChange: (event)=>column.pin('left' === event.target.value ? 'start' : 'right' === event.target.value ? 'end' : false),
|
|
731
|
+
children: [
|
|
732
|
+
/*#__PURE__*/ jsx(MenuItem, {
|
|
733
|
+
value: "",
|
|
734
|
+
children: strings.TABLE_UNPIN
|
|
735
|
+
}),
|
|
736
|
+
/*#__PURE__*/ jsx(MenuItem, {
|
|
737
|
+
value: "left",
|
|
738
|
+
children: strings.TABLE_PIN_LEFT
|
|
739
|
+
}),
|
|
740
|
+
/*#__PURE__*/ jsx(MenuItem, {
|
|
741
|
+
value: "right",
|
|
742
|
+
children: strings.TABLE_PIN_RIGHT
|
|
743
|
+
})
|
|
744
|
+
]
|
|
745
|
+
})
|
|
746
|
+
]
|
|
747
|
+
}, column.id))
|
|
748
|
+
]
|
|
749
|
+
}),
|
|
750
|
+
/*#__PURE__*/ jsx(ColumnDragTableContainer, {
|
|
751
|
+
...containerProps,
|
|
752
|
+
ids: orderedColumns.map((column)=>column.id),
|
|
753
|
+
onDragEnd: reorderColumns,
|
|
754
|
+
children: /*#__PURE__*/ jsxs(Table, {
|
|
755
|
+
ref: tableRef,
|
|
756
|
+
sx: {
|
|
757
|
+
minWidth: table.getTotalSize()
|
|
758
|
+
},
|
|
759
|
+
children: [
|
|
760
|
+
/*#__PURE__*/ jsx(TableHead, {
|
|
761
|
+
children: /*#__PURE__*/ jsx(TableRow, {
|
|
762
|
+
children: orderedColumns.map((column)=>{
|
|
763
|
+
const headCellProps = 'function' == typeof muiTableHeadCellProps ? muiTableHeadCellProps({
|
|
764
|
+
column,
|
|
765
|
+
table
|
|
766
|
+
}) : muiTableHeadCellProps;
|
|
767
|
+
const header = /*#__PURE__*/ jsxs(Fragment, {
|
|
768
|
+
children: [
|
|
769
|
+
/*#__PURE__*/ jsx("span", {
|
|
770
|
+
className: "Mui-TableHeadCell-Content-Wrapper",
|
|
771
|
+
children: definitions.get(column.id)?.header
|
|
772
|
+
}),
|
|
773
|
+
column.getIsFiltered() && /*#__PURE__*/ jsx(Tooltip, {
|
|
774
|
+
title: `${strings.TABLE_FILTERED}: ${definitions.get(column.id)?.header}`,
|
|
775
|
+
children: /*#__PURE__*/ jsx(FilterAlt, {
|
|
776
|
+
sx: {
|
|
777
|
+
color: 'action.active',
|
|
778
|
+
ml: '4px',
|
|
779
|
+
width: '18px',
|
|
780
|
+
height: '18px'
|
|
781
|
+
},
|
|
782
|
+
role: "img",
|
|
783
|
+
"aria-label": `${strings.TABLE_FILTERED}: ${definitions.get(column.id)?.header}`,
|
|
784
|
+
onClick: (event)=>event.stopPropagation()
|
|
785
|
+
})
|
|
786
|
+
})
|
|
787
|
+
]
|
|
788
|
+
});
|
|
789
|
+
return /*#__PURE__*/ createElement(DraggableColumnHeader, {
|
|
790
|
+
...headCellProps,
|
|
791
|
+
key: column.id,
|
|
792
|
+
"data-column-id": column.id,
|
|
793
|
+
"data-pinned": column.getIsPinned() ? 'true' : void 0,
|
|
794
|
+
id: column.id,
|
|
795
|
+
label: definitions.get(column.id).header,
|
|
796
|
+
enabled: enableColumnDragging || enableColumnOrdering,
|
|
797
|
+
sortDirection: column.getIsSorted() || false,
|
|
798
|
+
sx: [
|
|
799
|
+
(theme)=>({
|
|
800
|
+
...pinnedStyles(column, theme, pinnedOffsets),
|
|
801
|
+
bgcolor: 'background.paper',
|
|
802
|
+
fontWeight: 'bold',
|
|
803
|
+
p: 2,
|
|
804
|
+
pt: '12px',
|
|
805
|
+
pb: filtersVisible ? '6.4px' : '9.6px',
|
|
806
|
+
verticalAlign: 'top',
|
|
807
|
+
'&:hover .MuiIconButton-root': {
|
|
808
|
+
opacity: 1
|
|
809
|
+
}
|
|
810
|
+
}),
|
|
811
|
+
...Array.isArray(headCellProps?.sx) ? headCellProps.sx : [
|
|
812
|
+
headCellProps?.sx
|
|
813
|
+
]
|
|
814
|
+
],
|
|
815
|
+
children: [
|
|
816
|
+
/*#__PURE__*/ jsxs(Box, {
|
|
817
|
+
display: "flex",
|
|
818
|
+
alignItems: "center",
|
|
819
|
+
sx: {
|
|
820
|
+
minHeight: '24px'
|
|
821
|
+
},
|
|
822
|
+
children: [
|
|
823
|
+
column.getCanSort() ? /*#__PURE__*/ jsx(TableSortLabel, {
|
|
824
|
+
active: !!column.getIsSorted(),
|
|
825
|
+
direction: column.getIsSorted() || 'asc',
|
|
826
|
+
IconComponent: column.getIsSorted() ? ArrowDownward : UnsortedIcon,
|
|
827
|
+
sx: (theme)=>({
|
|
828
|
+
fontWeight: 'inherit',
|
|
829
|
+
whiteSpace: definitions.get(column.id).header.length < 20 ? 'nowrap' : 'normal',
|
|
830
|
+
'& .MuiTableSortLabel-icon': {
|
|
831
|
+
color: `${'dark' === theme.palette.mode ? theme.palette.text.primary : theme.palette.text.secondary} !important`,
|
|
832
|
+
opacity: column.getIsSorted() ? 1 : 0.3,
|
|
833
|
+
width: '3ch',
|
|
834
|
+
m: 0
|
|
835
|
+
}
|
|
836
|
+
}),
|
|
837
|
+
onClick: column.getToggleSortingHandler(),
|
|
838
|
+
children: header
|
|
839
|
+
}) : header,
|
|
840
|
+
/*#__PURE__*/ jsx(ColumnDragHandle, {}),
|
|
841
|
+
enableColumnActions && (column.getCanSort() || column.getCanFilter() || controlsEnabled) && /*#__PURE__*/ jsx(IconButton, {
|
|
842
|
+
size: "small",
|
|
843
|
+
sx: {
|
|
844
|
+
height: '2rem',
|
|
845
|
+
width: '2rem',
|
|
846
|
+
m: '-8px -4px',
|
|
847
|
+
opacity: 0.3,
|
|
848
|
+
transition: 'all 150ms'
|
|
849
|
+
},
|
|
850
|
+
"aria-label": `${strings.TABLE_COLUMN_ACTIONS}: ${definitions.get(column.id)?.header}`,
|
|
851
|
+
"aria-haspopup": "menu",
|
|
852
|
+
"aria-expanded": !!menuAnchor && menuColumnId === column.id,
|
|
853
|
+
onClick: (event)=>{
|
|
854
|
+
setMenuColumnId(column.id);
|
|
855
|
+
setMenuAnchor(event.currentTarget);
|
|
856
|
+
},
|
|
857
|
+
children: /*#__PURE__*/ jsx(MoreVert, {
|
|
858
|
+
sx: {
|
|
859
|
+
transform: 'scale(0.9)'
|
|
860
|
+
}
|
|
861
|
+
})
|
|
862
|
+
})
|
|
863
|
+
]
|
|
864
|
+
}, "content"),
|
|
865
|
+
filtersVisible && column.getCanFilter() && /*#__PURE__*/ jsx(ColumnFilter, {
|
|
866
|
+
column: column,
|
|
867
|
+
definition: definitions.get(column.id)
|
|
868
|
+
}, "filter")
|
|
869
|
+
]
|
|
870
|
+
});
|
|
871
|
+
})
|
|
872
|
+
})
|
|
873
|
+
}),
|
|
874
|
+
/*#__PURE__*/ jsxs(TableBody, {
|
|
875
|
+
children: [
|
|
876
|
+
rows.map((row, rowIndex)=>/*#__PURE__*/ jsx(TableRow, {
|
|
877
|
+
onClick: onRowClick ? ()=>onRowClick(row.original) : void 0,
|
|
878
|
+
sx: (theme)=>{
|
|
879
|
+
const background = theme.palette.background.default;
|
|
880
|
+
const hoverColor = alpha('dark' === theme.palette.mode ? lighten(background, 0.3) : darken(background, 0.3), 0.3);
|
|
881
|
+
return {
|
|
882
|
+
cursor: onRowClick ? 'pointer' : 'default',
|
|
883
|
+
'&:hover > td': {
|
|
884
|
+
backgroundImage: `linear-gradient(${hoverColor}, ${hoverColor})`
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
},
|
|
888
|
+
children: [
|
|
889
|
+
...row.getStartVisibleCells(),
|
|
890
|
+
...row.getCenterVisibleCells(),
|
|
891
|
+
...row.getEndVisibleCells()
|
|
892
|
+
].map((cell)=>{
|
|
893
|
+
const column = cell.column;
|
|
894
|
+
const definition = definitions.get(column.id);
|
|
895
|
+
const editConfig = definition.editConfig;
|
|
896
|
+
const canEdit = ('function' == typeof definition.enableEditing ? definition.enableEditing(row) : definition.enableEditing ?? enableEditing) && enableEditing && (!!editConfig?.onSave || editConfig?.editVariant === 'custom' && !!editConfig.customEditComponent);
|
|
897
|
+
const value = cell.getValue();
|
|
898
|
+
const bodyCellProps = 'function' == typeof muiTableBodyCellProps ? muiTableBodyCellProps({
|
|
899
|
+
cell,
|
|
900
|
+
column,
|
|
901
|
+
row,
|
|
902
|
+
table
|
|
903
|
+
}) : muiTableBodyCellProps;
|
|
904
|
+
return /*#__PURE__*/ createElement(ColumnDragBodyCell, {
|
|
905
|
+
...bodyCellProps,
|
|
906
|
+
key: cell.id,
|
|
907
|
+
columnId: column.id,
|
|
908
|
+
lastRow: rowIndex === rows.length - 1,
|
|
909
|
+
"data-pinned": column.getIsPinned() ? 'true' : void 0,
|
|
910
|
+
tabIndex: bodyCellProps?.tabIndex ?? (canEdit ? 0 : void 0),
|
|
911
|
+
onClick: (event)=>{
|
|
912
|
+
if (canEdit) event.stopPropagation();
|
|
913
|
+
bodyCellProps?.onClick?.(event);
|
|
914
|
+
},
|
|
915
|
+
onDoubleClick: (event)=>{
|
|
916
|
+
if (canEdit) setEditingCell({
|
|
917
|
+
id: cell.id
|
|
918
|
+
});
|
|
919
|
+
bodyCellProps?.onDoubleClick?.(event);
|
|
920
|
+
},
|
|
921
|
+
onKeyDown: (event)=>{
|
|
922
|
+
if (canEdit && event.target === event.currentTarget) {
|
|
923
|
+
if ('Enter' === event.key || 'F2' === event.key) {
|
|
924
|
+
event.preventDefault();
|
|
925
|
+
setEditingCell({
|
|
926
|
+
id: cell.id
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
bodyCellProps?.onKeyDown?.(event);
|
|
931
|
+
},
|
|
932
|
+
sx: [
|
|
933
|
+
(theme)=>({
|
|
934
|
+
...pinnedStyles(column, theme, pinnedOffsets),
|
|
935
|
+
borderBottom: 'none',
|
|
936
|
+
bgcolor: rowIndex % 2 === 0 ? 'TwClrBaseGray025' : 'background.paper',
|
|
937
|
+
cursor: canEdit ? 'pointer' : 'inherit',
|
|
938
|
+
outlineOffset: '-1px',
|
|
939
|
+
'&:hover': {
|
|
940
|
+
outline: canEdit ? '1px solid' : void 0,
|
|
941
|
+
outlineColor: 'grey.500'
|
|
942
|
+
}
|
|
943
|
+
}),
|
|
944
|
+
...Array.isArray(bodyCellProps?.sx) ? bodyCellProps.sx : [
|
|
945
|
+
bodyCellProps?.sx
|
|
946
|
+
]
|
|
947
|
+
]
|
|
948
|
+
}, editingCell?.id === cell.id ? /*#__PURE__*/ jsx(EditableCellV2, {
|
|
949
|
+
cell: cell,
|
|
950
|
+
column: definition,
|
|
951
|
+
onClose: ()=>setEditingCell((current)=>current === editingCell ? null : current)
|
|
952
|
+
}, cell.id) : definition.Cell ? /*#__PURE__*/ jsx(definition.Cell, {
|
|
953
|
+
...cell.getContext()
|
|
954
|
+
}) : String(value ?? ''));
|
|
955
|
+
})
|
|
956
|
+
}, row.id)),
|
|
957
|
+
!rows.length && /*#__PURE__*/ jsx(TableRow, {
|
|
958
|
+
children: /*#__PURE__*/ jsx(TableCell, {
|
|
959
|
+
colSpan: Math.max(1, visibleColumns.length),
|
|
960
|
+
children: strings.TABLE_NO_ROWS
|
|
961
|
+
})
|
|
962
|
+
})
|
|
963
|
+
]
|
|
964
|
+
})
|
|
965
|
+
]
|
|
966
|
+
})
|
|
967
|
+
}),
|
|
968
|
+
enablePagination && enableBottomToolbar && /*#__PURE__*/ jsx(TablePagination, {
|
|
969
|
+
component: "div",
|
|
970
|
+
sx: (theme)=>({
|
|
971
|
+
boxShadow: `0 1px 2px -1px ${alpha(theme.palette.grey[700], 0.5)} inset`
|
|
972
|
+
}),
|
|
973
|
+
showFirstButton: true,
|
|
974
|
+
showLastButton: true,
|
|
975
|
+
count: pageCountWithoutRowCount ? -1 : table.getRowCount(),
|
|
976
|
+
slotProps: pageCountWithoutRowCount ? {
|
|
977
|
+
actions: 'rtl' === theme.direction ? {
|
|
978
|
+
previousButton: nextPageButton,
|
|
979
|
+
firstButton: lastPageButton
|
|
980
|
+
} : {
|
|
981
|
+
nextButton: nextPageButton,
|
|
982
|
+
lastButton: lastPageButton
|
|
983
|
+
}
|
|
984
|
+
} : void 0,
|
|
985
|
+
page: table.state.pagination.pageIndex,
|
|
986
|
+
rowsPerPage: table.state.pagination.pageSize,
|
|
987
|
+
rowsPerPageOptions: Array.from(new Set([
|
|
988
|
+
table.state.pagination.pageSize,
|
|
989
|
+
10,
|
|
990
|
+
25,
|
|
991
|
+
50,
|
|
992
|
+
100
|
|
993
|
+
])).sort((a, b)=>a - b),
|
|
994
|
+
labelRowsPerPage: strings.TABLE_ROWS_PER_PAGE,
|
|
995
|
+
labelDisplayedRows: ({ from, to, count })=>pageCountWithoutRowCount ? `${rows.length ? from : 0}–${rows.length ? from + rows.length - 1 : 0}` : `${from}–${to} / ${count}`,
|
|
996
|
+
getItemAriaLabel: (type)=>({
|
|
997
|
+
first: strings.TABLE_FIRST_PAGE,
|
|
998
|
+
last: strings.TABLE_LAST_PAGE,
|
|
999
|
+
next: strings.TABLE_NEXT_PAGE,
|
|
1000
|
+
previous: strings.TABLE_PREVIOUS_PAGE
|
|
1001
|
+
})[type],
|
|
1002
|
+
onPageChange: (_, page)=>table.setPageIndex(page),
|
|
1003
|
+
onRowsPerPageChange: (event)=>table.setPageSize(Number(event.target.value))
|
|
1004
|
+
})
|
|
1005
|
+
]
|
|
1006
|
+
})
|
|
1007
|
+
});
|
|
1008
|
+
};
|
|
1009
|
+
const components_EditableTableV2 = EditableTableV2;
|
|
1010
|
+
export default components_EditableTableV2;
|