@gridsuite/commons-ui 0.77.2 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -13
- package/dist/index.js +0 -13
- package/package.json +1 -3
- package/dist/components/muiVirtualizedTable/ColumnHeader.d.ts +0 -26
- package/dist/components/muiVirtualizedTable/ColumnHeader.js +0 -108
- package/dist/components/muiVirtualizedTable/KeyedColumnsRowIndexer.d.ts +0 -130
- package/dist/components/muiVirtualizedTable/KeyedColumnsRowIndexer.js +0 -521
- package/dist/components/muiVirtualizedTable/MuiVirtualizedTable.d.ts +0 -97
- package/dist/components/muiVirtualizedTable/MuiVirtualizedTable.js +0 -692
- package/dist/components/muiVirtualizedTable/index.d.ts +0 -8
- package/dist/components/muiVirtualizedTable/index.js +0 -15
|
@@ -1,692 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { PureComponent, createRef } from "react";
|
|
3
|
-
import { FormattedMessage } from "react-intl";
|
|
4
|
-
import clsx from "clsx";
|
|
5
|
-
import memoize from "memoize-one";
|
|
6
|
-
import { TableCell, IconButton, Popover, Autocomplete, TextField, Chip } from "@mui/material";
|
|
7
|
-
import { styled } from "@mui/system";
|
|
8
|
-
import { GetApp } from "@mui/icons-material";
|
|
9
|
-
import { Table, Column, AutoSizer } from "react-virtualized";
|
|
10
|
-
import CsvDownloader from "react-csv-downloader";
|
|
11
|
-
import { OverflowableText } from "../overflowableText/OverflowableText.js";
|
|
12
|
-
import { toNestedGlobalSelectors, makeComposeClasses } from "../../utils/styles.js";
|
|
13
|
-
import { getHelper, collectibleHelper, ChangeWays, KeyedColumnsRowIndexer } from "./KeyedColumnsRowIndexer.js";
|
|
14
|
-
import { ColumnHeader } from "./ColumnHeader.js";
|
|
15
|
-
function getTextWidth(text) {
|
|
16
|
-
let canvas = (
|
|
17
|
-
//@ts-ignore this is questioning
|
|
18
|
-
getTextWidth.canvas || //@ts-ignore this is questioning
|
|
19
|
-
(getTextWidth.canvas = document.createElement("canvas"))
|
|
20
|
-
);
|
|
21
|
-
let context = canvas.getContext("2d");
|
|
22
|
-
context.font = '14px "Roboto", "Helvetica", "Arial", sans-serif';
|
|
23
|
-
let metrics = context.measureText(text);
|
|
24
|
-
return metrics.width;
|
|
25
|
-
}
|
|
26
|
-
const DEFAULT_CELL_PADDING = 16;
|
|
27
|
-
const DEFAULT_HEADER_HEIGHT = 48;
|
|
28
|
-
const DEFAULT_ROW_HEIGHT = 48;
|
|
29
|
-
const cssFlexContainer = "flexContainer";
|
|
30
|
-
const cssTable = "table";
|
|
31
|
-
const cssTableRow = "tableRow";
|
|
32
|
-
const cssTableRowHover = "tableRowHover";
|
|
33
|
-
const cssTableCell = "tableCell";
|
|
34
|
-
const cssTableCellColor = "tableCellColor";
|
|
35
|
-
const cssNoClick = "noClick";
|
|
36
|
-
const cssHeader = "header";
|
|
37
|
-
const cssRowBackgroundDark = "rowBackgroundDark";
|
|
38
|
-
const cssRowBackgroundLight = "rowBackgroundLight";
|
|
39
|
-
const defaultStyles = {
|
|
40
|
-
[cssFlexContainer]: {
|
|
41
|
-
display: "flex",
|
|
42
|
-
alignItems: "center",
|
|
43
|
-
boxSizing: "border-box"
|
|
44
|
-
},
|
|
45
|
-
[cssTable]: {
|
|
46
|
-
// temporary right-to-left patch, waiting for
|
|
47
|
-
// https://github.com/bvaughn/react-virtualized/issues/454
|
|
48
|
-
"& .ReactVirtualized__Table__headerRow": {
|
|
49
|
-
flip: false
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
[cssTableRow]: {
|
|
53
|
-
cursor: "pointer"
|
|
54
|
-
},
|
|
55
|
-
[cssTableRowHover]: {},
|
|
56
|
-
[cssTableCell]: {
|
|
57
|
-
flex: 1,
|
|
58
|
-
padding: DEFAULT_CELL_PADDING + "px"
|
|
59
|
-
},
|
|
60
|
-
[cssTableCellColor]: {},
|
|
61
|
-
[cssNoClick]: {
|
|
62
|
-
cursor: "initial"
|
|
63
|
-
},
|
|
64
|
-
[cssHeader]: {
|
|
65
|
-
fontWeight: "bold"
|
|
66
|
-
},
|
|
67
|
-
[cssRowBackgroundDark]: {},
|
|
68
|
-
[cssRowBackgroundLight]: {}
|
|
69
|
-
};
|
|
70
|
-
const defaultTooltipSx = {
|
|
71
|
-
maxWidth: "1260px",
|
|
72
|
-
fontSize: "0.9rem"
|
|
73
|
-
};
|
|
74
|
-
const generateMuiVirtualizedTableClass = (className) => `MuiVirtualizedTable-${className}`;
|
|
75
|
-
const composeClasses = makeComposeClasses(generateMuiVirtualizedTableClass);
|
|
76
|
-
const AmongChooser = (props) => {
|
|
77
|
-
const { options, value, setValue, id, onDropDownVisibility } = props;
|
|
78
|
-
return /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
|
|
79
|
-
Autocomplete,
|
|
80
|
-
{
|
|
81
|
-
id,
|
|
82
|
-
value,
|
|
83
|
-
multiple: true,
|
|
84
|
-
onChange: (evt, newVal) => {
|
|
85
|
-
setValue(newVal);
|
|
86
|
-
},
|
|
87
|
-
onClose: () => onDropDownVisibility(false),
|
|
88
|
-
onOpen: () => onDropDownVisibility(true),
|
|
89
|
-
options,
|
|
90
|
-
renderInput: (props2) => /* @__PURE__ */ jsx(TextField, { autoFocus: true, ...props2 }),
|
|
91
|
-
renderTags: (val, getTagsProps) => {
|
|
92
|
-
return val.map((code, index) => {
|
|
93
|
-
return /* @__PURE__ */ jsx(Chip, { id: "chip_" + code, size: "small", label: code, ...getTagsProps({ index }) });
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
) });
|
|
98
|
-
};
|
|
99
|
-
function makeIndexRecord(viewIndexToModel, rows) {
|
|
100
|
-
return {
|
|
101
|
-
viewIndexToModel,
|
|
102
|
-
rowGetter: !viewIndexToModel ? (viewIndex) => rows[viewIndex] : (viewIndex) => {
|
|
103
|
-
if (viewIndex >= viewIndexToModel.length || viewIndex < 0) {
|
|
104
|
-
return {};
|
|
105
|
-
}
|
|
106
|
-
const modelIndex = viewIndexToModel[viewIndex];
|
|
107
|
-
return rows[modelIndex];
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const initIndexer = (props, versionSetter) => {
|
|
112
|
-
if (!props.sortable) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
if (props.indexer) {
|
|
116
|
-
return props.indexer;
|
|
117
|
-
}
|
|
118
|
-
return new KeyedColumnsRowIndexer(true, true, null, versionSetter);
|
|
119
|
-
};
|
|
120
|
-
const preFilterData = memoize(
|
|
121
|
-
(columns, rows, filterFromProps, indexer, filterVersion) => {
|
|
122
|
-
return indexer.preFilterRowMapping(columns, rows, filterFromProps);
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
const reorderIndex = memoize(
|
|
126
|
-
(indexer, indirectionVersion, rows, columns, filterFromProps, sortFromProps) => {
|
|
127
|
-
if (!rows) {
|
|
128
|
-
return {
|
|
129
|
-
viewIndexToModel: [],
|
|
130
|
-
rowGetter: (viewIndex) => viewIndex
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const highestCodedColumn = !indexer ? 0 : indexer.highestCodedColumn(columns);
|
|
134
|
-
if (sortFromProps && highestCodedColumn) {
|
|
135
|
-
const colIdx = Math.abs(highestCodedColumn) - 1;
|
|
136
|
-
let reorderedIndex = sortFromProps(
|
|
137
|
-
columns[colIdx].dataKey,
|
|
138
|
-
highestCodedColumn > 0,
|
|
139
|
-
!!columns[colIdx].numeric
|
|
140
|
-
);
|
|
141
|
-
return makeIndexRecord(reorderedIndex, rows);
|
|
142
|
-
}
|
|
143
|
-
if (sortFromProps) {
|
|
144
|
-
try {
|
|
145
|
-
const viewIndexToModel = sortFromProps(null, false, false);
|
|
146
|
-
return makeIndexRecord(viewIndexToModel, rows);
|
|
147
|
-
} catch (e) {
|
|
148
|
-
console.warn(
|
|
149
|
-
"error in external sort. consider adding support for datakey=null in your external sort function"
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (indexer) {
|
|
154
|
-
const prefiltered = preFilterData(columns, rows, filterFromProps, indexer, indirectionVersion);
|
|
155
|
-
const reorderedIndex = indexer.makeGroupAndSortIndirector(prefiltered, columns);
|
|
156
|
-
return makeIndexRecord(reorderedIndex, rows);
|
|
157
|
-
}
|
|
158
|
-
if (filterFromProps) {
|
|
159
|
-
const viewIndexToModel = rows.map((r, i) => [r, i]).filter(([r, _]) => filterFromProps(r)).map(([_, j]) => j);
|
|
160
|
-
return makeIndexRecord(viewIndexToModel, rows);
|
|
161
|
-
}
|
|
162
|
-
return makeIndexRecord(null, rows);
|
|
163
|
-
}
|
|
164
|
-
);
|
|
165
|
-
const _MuiVirtualizedTableComponent = class _MuiVirtualizedTableComponent extends PureComponent {
|
|
166
|
-
constructor(props, context) {
|
|
167
|
-
super(props, context);
|
|
168
|
-
this.setVersion = (v) => {
|
|
169
|
-
this.setState({ indirectionVersion: v });
|
|
170
|
-
};
|
|
171
|
-
this.computeDataWidth = (text) => {
|
|
172
|
-
return getTextWidth(text || "") + 2 * DEFAULT_CELL_PADDING;
|
|
173
|
-
};
|
|
174
|
-
this.sizes = memoize((columns, rows, rowGetter) => {
|
|
175
|
-
let sizes = {};
|
|
176
|
-
columns.forEach((col) => {
|
|
177
|
-
if (col.width) {
|
|
178
|
-
sizes[col.dataKey] = col.width;
|
|
179
|
-
} else {
|
|
180
|
-
let size = Math.max(col.minWidth || 0, this.computeDataWidth(col.label));
|
|
181
|
-
for (let i = 0; i < rows.length; ++i) {
|
|
182
|
-
const gotRow = rowGetter(i);
|
|
183
|
-
let text = this.getDisplayValue(col, gotRow[col.dataKey]);
|
|
184
|
-
size = Math.max(size, this.computeDataWidth(text));
|
|
185
|
-
}
|
|
186
|
-
if (col.maxWidth) {
|
|
187
|
-
size = Math.min(col.maxWidth, size);
|
|
188
|
-
}
|
|
189
|
-
sizes[col.dataKey] = Math.ceil(size);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
return sizes;
|
|
193
|
-
});
|
|
194
|
-
this.openPopover = (popoverTarget, colKey) => {
|
|
195
|
-
const col = this.props.columns.find((c) => c.dataKey === colKey);
|
|
196
|
-
if (getHelper(col) !== collectibleHelper) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
this.dropDownVisible = false;
|
|
200
|
-
this.setState({
|
|
201
|
-
popoverAnchorEl: popoverTarget,
|
|
202
|
-
popoverColKey: colKey
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
this.handleKeyDownOnPopover = (evt) => {
|
|
206
|
-
if (evt.key === "Enter" && !this.dropDownVisible) {
|
|
207
|
-
this.closePopover(evt, "enterKeyDown");
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
this.closePopover = (_, reason) => {
|
|
211
|
-
let bumpsVersion = false;
|
|
212
|
-
if (reason === "backdropClick" || reason === "enterKeyDown") {
|
|
213
|
-
bumpsVersion = this._commitFilterChange();
|
|
214
|
-
}
|
|
215
|
-
this.setState((state, _2) => {
|
|
216
|
-
return {
|
|
217
|
-
popoverAnchorEl: null,
|
|
218
|
-
popoverColKey: null,
|
|
219
|
-
deferredFilterChange: null,
|
|
220
|
-
indirectionVersion: state.indirectionVersion + (bumpsVersion ? 1 : 0)
|
|
221
|
-
};
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
this.makeColumnFilterEditor = () => {
|
|
225
|
-
var _a, _b, _c;
|
|
226
|
-
const colKey = this.state.popoverColKey;
|
|
227
|
-
const outerParams = (_a = this.state.indexer) == null ? void 0 : _a.getColFilterOuterParams(colKey);
|
|
228
|
-
const userParams = !this.props.defersFilterChanges || !this.state.deferredFilterChange ? (_b = this.state.indexer) == null ? void 0 : _b.getColFilterUserParams(colKey) : this.state.deferredFilterChange.newVal ?? void 0;
|
|
229
|
-
const prefiltered = preFilterData(
|
|
230
|
-
this.props.columns,
|
|
231
|
-
this.props.rows,
|
|
232
|
-
this.props.filter,
|
|
233
|
-
this.state.indexer,
|
|
234
|
-
this.state.indirectionVersion
|
|
235
|
-
);
|
|
236
|
-
let options2 = [];
|
|
237
|
-
if (outerParams) {
|
|
238
|
-
options2.push(...outerParams);
|
|
239
|
-
}
|
|
240
|
-
const colStat = (_c = prefiltered == null ? void 0 : prefiltered.colsStats) == null ? void 0 : _c[colKey];
|
|
241
|
-
if (colStat == null ? void 0 : colStat.seen) {
|
|
242
|
-
for (const key of Object.getOwnPropertyNames(colStat.seen)) {
|
|
243
|
-
if (options2.findIndex((o) => o === key) < 0) {
|
|
244
|
-
options2.push(key);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
options2.sort();
|
|
249
|
-
return /* @__PURE__ */ jsx(
|
|
250
|
-
AmongChooser,
|
|
251
|
-
{
|
|
252
|
-
options: options2,
|
|
253
|
-
value: userParams,
|
|
254
|
-
id: "fielt" + colKey,
|
|
255
|
-
setValue: (newVal) => {
|
|
256
|
-
this.onFilterParamsChange(newVal, colKey);
|
|
257
|
-
},
|
|
258
|
-
onDropDownVisibility: (visible) => this.dropDownVisible = visible
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
};
|
|
262
|
-
this._commitFilterChange = () => {
|
|
263
|
-
var _a;
|
|
264
|
-
if (this.state.deferredFilterChange) {
|
|
265
|
-
const colKey = this.state.deferredFilterChange.colKey;
|
|
266
|
-
let newVal = this.state.deferredFilterChange.newVal;
|
|
267
|
-
if ((newVal == null ? void 0 : newVal.length) === 0) {
|
|
268
|
-
newVal = null;
|
|
269
|
-
}
|
|
270
|
-
if ((_a = this.state.indexer) == null ? void 0 : _a.setColFilterUserParams(colKey, newVal)) {
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return false;
|
|
275
|
-
};
|
|
276
|
-
this.sortClickHandler = (evt, _, columnIndex) => {
|
|
277
|
-
var _a;
|
|
278
|
-
const colKey = this.props.columns[columnIndex].dataKey;
|
|
279
|
-
if (evt.altKey) {
|
|
280
|
-
this.openPopover(evt.target, colKey);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
let way = ChangeWays.SIMPLE;
|
|
284
|
-
if (evt.ctrlKey && evt.shiftKey) {
|
|
285
|
-
way = ChangeWays.AMEND;
|
|
286
|
-
} else if (evt.ctrlKey) {
|
|
287
|
-
way = ChangeWays.REMOVE;
|
|
288
|
-
} else if (evt.shiftKey) {
|
|
289
|
-
way = ChangeWays.TAIL;
|
|
290
|
-
}
|
|
291
|
-
if ((_a = this.state.indexer) == null ? void 0 : _a.updateSortingFromUser(colKey, way)) {
|
|
292
|
-
this.setState({
|
|
293
|
-
indirectionVersion: this.state.indirectionVersion + 1
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
this.filterClickHandler = (_, target, columnIndex) => {
|
|
298
|
-
const retargeted = (target == null ? void 0 : target.parentNode) ?? target;
|
|
299
|
-
const colKey = this.props.columns[columnIndex].dataKey;
|
|
300
|
-
this.openPopover(retargeted, colKey);
|
|
301
|
-
};
|
|
302
|
-
this.sortableHeader = ({ label, columnIndex }) => {
|
|
303
|
-
var _a;
|
|
304
|
-
const { columns } = this.props;
|
|
305
|
-
const indexer = this.state.indexer;
|
|
306
|
-
const colKey = columns[columnIndex].dataKey;
|
|
307
|
-
const signedRank = indexer == null ? void 0 : indexer.columnSortingSignedRank(colKey);
|
|
308
|
-
const userParams = indexer == null ? void 0 : indexer.getColFilterUserParams(colKey);
|
|
309
|
-
const numeric = columns[columnIndex].numeric;
|
|
310
|
-
const prefiltered = preFilterData(columns, this.props.rows, this.props.filter, indexer, indexer == null ? void 0 : indexer.filterVersion);
|
|
311
|
-
const colStat = (_a = prefiltered == null ? void 0 : prefiltered.colsStats) == null ? void 0 : _a[colKey];
|
|
312
|
-
let filterLevel = 0;
|
|
313
|
-
if (userParams == null ? void 0 : userParams.length) {
|
|
314
|
-
filterLevel += 1;
|
|
315
|
-
if (!(colStat == null ? void 0 : colStat.seen)) {
|
|
316
|
-
filterLevel += 2;
|
|
317
|
-
} else if (userParams.filter((v) => !colStat.seen[v]).length) {
|
|
318
|
-
filterLevel += 2;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const onFilterClick = numeric || this.props.sort || columns[columnIndex].cellRenderer ? void 0 : (ev, retargeted) => {
|
|
322
|
-
this.filterClickHandler(ev, retargeted, columnIndex);
|
|
323
|
-
};
|
|
324
|
-
return /* @__PURE__ */ jsx(
|
|
325
|
-
ColumnHeader,
|
|
326
|
-
{
|
|
327
|
-
label,
|
|
328
|
-
ref: (e) => this._registerHeader(label, e),
|
|
329
|
-
sortSignedRank: signedRank,
|
|
330
|
-
filterLevel,
|
|
331
|
-
numeric: numeric ?? false,
|
|
332
|
-
onSortClick: (ev, name) => {
|
|
333
|
-
this.sortClickHandler(ev, name, columnIndex);
|
|
334
|
-
},
|
|
335
|
-
onFilterClick
|
|
336
|
-
}
|
|
337
|
-
);
|
|
338
|
-
};
|
|
339
|
-
this.simpleHeaderRenderer = ({ label }) => {
|
|
340
|
-
return /* @__PURE__ */ jsx(
|
|
341
|
-
"div",
|
|
342
|
-
{
|
|
343
|
-
ref: (element) => {
|
|
344
|
-
this._registerHeader(label, element);
|
|
345
|
-
},
|
|
346
|
-
children: label
|
|
347
|
-
}
|
|
348
|
-
);
|
|
349
|
-
};
|
|
350
|
-
this.getRowClassName = ({
|
|
351
|
-
index,
|
|
352
|
-
rowGetter
|
|
353
|
-
}) => {
|
|
354
|
-
var _a;
|
|
355
|
-
const { classes, onRowClick } = this.props;
|
|
356
|
-
return clsx(
|
|
357
|
-
composeClasses(classes, cssTableRow),
|
|
358
|
-
composeClasses(classes, cssFlexContainer),
|
|
359
|
-
index % 2 === 0 && composeClasses(classes, cssRowBackgroundDark),
|
|
360
|
-
index % 2 !== 0 && composeClasses(classes, cssRowBackgroundLight),
|
|
361
|
-
((_a = rowGetter(index)) == null ? void 0 : _a.notClickable) === true && composeClasses(classes, cssNoClick),
|
|
362
|
-
// Allow to define a row as not clickable
|
|
363
|
-
{
|
|
364
|
-
[composeClasses(classes, cssTableRowHover)]: index !== -1 && onRowClick != null
|
|
365
|
-
}
|
|
366
|
-
);
|
|
367
|
-
};
|
|
368
|
-
this.onClickableRowClick = (event) => {
|
|
369
|
-
var _a, _b, _c;
|
|
370
|
-
if (((_a = event.rowData) == null ? void 0 : _a.notClickable) !== true || ((_b = event.event) == null ? void 0 : _b.shiftKey) || ((_c = event.event) == null ? void 0 : _c.ctrlKey)) {
|
|
371
|
-
this.props.onRowClick(event);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
this.cellRenderer = ({ cellData, columnIndex, rowIndex }) => {
|
|
375
|
-
var _a, _b;
|
|
376
|
-
const { columns, classes, rowHeight, onCellClick, rows, tooltipSx } = this.props;
|
|
377
|
-
let displayedValue = this.getDisplayValue(columns[columnIndex], cellData);
|
|
378
|
-
return /* @__PURE__ */ jsx(
|
|
379
|
-
TableCell,
|
|
380
|
-
{
|
|
381
|
-
component: "div",
|
|
382
|
-
className: clsx(composeClasses(classes, cssTableCell), composeClasses(classes, cssFlexContainer), {
|
|
383
|
-
[composeClasses(classes, cssNoClick)]: displayedValue === void 0 || ((_a = rows[rowIndex]) == null ? void 0 : _a.notClickable) === true || onCellClick == null || columns[columnIndex].clickable === void 0 || !columns[columnIndex].clickable,
|
|
384
|
-
[composeClasses(classes, cssTableCellColor)]: displayedValue === void 0 || onCellClick !== null && !((_b = rows[rowIndex]) == null ? void 0 : _b.notClickable) === true && columns[columnIndex].clickable !== void 0 && columns[columnIndex].clickable
|
|
385
|
-
}),
|
|
386
|
-
variant: "body",
|
|
387
|
-
style: { height: rowHeight, width: "100%" },
|
|
388
|
-
align: columnIndex != null && columns[columnIndex].numeric || false ? "right" : "left",
|
|
389
|
-
onClick: () => {
|
|
390
|
-
var _a2;
|
|
391
|
-
if (onCellClick && columns[columnIndex].clickable !== void 0 && !((_a2 = rows[rowIndex]) == null ? void 0 : _a2.notClickable) === true && columns[columnIndex].clickable) {
|
|
392
|
-
onCellClick(rows[rowIndex], columns[columnIndex]);
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
children: /* @__PURE__ */ jsx(
|
|
396
|
-
OverflowableText,
|
|
397
|
-
{
|
|
398
|
-
text: displayedValue,
|
|
399
|
-
tooltipStyle: classes.cellTooltip,
|
|
400
|
-
tooltipSx: { ...defaultTooltipSx, ...tooltipSx }
|
|
401
|
-
}
|
|
402
|
-
)
|
|
403
|
-
}
|
|
404
|
-
);
|
|
405
|
-
};
|
|
406
|
-
this.makeSizedTable = (height, width, sizes, reorderedIndex, rowGetter) => {
|
|
407
|
-
const { sort, ...otherProps } = this.props;
|
|
408
|
-
return /* @__PURE__ */ jsx(
|
|
409
|
-
Table,
|
|
410
|
-
{
|
|
411
|
-
...otherProps,
|
|
412
|
-
height,
|
|
413
|
-
width,
|
|
414
|
-
rowHeight: otherProps.rowHeight,
|
|
415
|
-
gridStyle: { direction: "inherit" },
|
|
416
|
-
headerHeight: this.state.headerHeight,
|
|
417
|
-
className: composeClasses(otherProps.classes, cssTable),
|
|
418
|
-
onRowClick: this.props.onRowClick && /* The {...otherProps} just above would hold the slot onRowClick */
|
|
419
|
-
this.onClickableRowClick,
|
|
420
|
-
rowCount: (reorderedIndex == null ? void 0 : reorderedIndex.length) ?? otherProps.rows.length,
|
|
421
|
-
rowClassName: ({ index }) => this.getRowClassName({ index, rowGetter }),
|
|
422
|
-
rowGetter: ({ index }) => rowGetter(index),
|
|
423
|
-
children: otherProps.columns.map(({ dataKey, ...other }, index) => {
|
|
424
|
-
return /* @__PURE__ */ jsx(
|
|
425
|
-
Column,
|
|
426
|
-
{
|
|
427
|
-
headerRenderer: this.makeHeaderRenderer(dataKey, index),
|
|
428
|
-
className: composeClasses(otherProps.classes, cssFlexContainer),
|
|
429
|
-
cellRenderer: this.cellRenderer,
|
|
430
|
-
dataKey,
|
|
431
|
-
flexGrow: 1,
|
|
432
|
-
width: sizes[dataKey],
|
|
433
|
-
...other
|
|
434
|
-
},
|
|
435
|
-
dataKey
|
|
436
|
-
);
|
|
437
|
-
})
|
|
438
|
-
}
|
|
439
|
-
);
|
|
440
|
-
};
|
|
441
|
-
this.getCSVFilename = () => {
|
|
442
|
-
var _a;
|
|
443
|
-
if (((_a = this.props.name) == null ? void 0 : _a.length) > 0) {
|
|
444
|
-
return this.props.name.replace(/\s/g, "_");
|
|
445
|
-
} else {
|
|
446
|
-
let filename = Object.entries(this.props.columns).map((p) => p[1].label).join("_");
|
|
447
|
-
return filename;
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
this.getCSVData = () => {
|
|
451
|
-
var _a;
|
|
452
|
-
let reorderedIndex = reorderIndex(
|
|
453
|
-
this.state.indexer,
|
|
454
|
-
this.state.indirectionVersion,
|
|
455
|
-
this.props.rows,
|
|
456
|
-
this.props.columns,
|
|
457
|
-
this.props.filter,
|
|
458
|
-
this.props.sort
|
|
459
|
-
);
|
|
460
|
-
let rowsCount = ((_a = reorderedIndex.viewIndexToModel) == null ? void 0 : _a.length) ?? this.props.rows.length;
|
|
461
|
-
const csvData = [];
|
|
462
|
-
for (let index = 0; index < rowsCount; ++index) {
|
|
463
|
-
const myobj = {};
|
|
464
|
-
const sortedRow = reorderedIndex.rowGetter(index);
|
|
465
|
-
const exportedKeys = this.props.exportCSVDataKeys;
|
|
466
|
-
this.props.columns.forEach((col) => {
|
|
467
|
-
if (exportedKeys == null ? void 0 : exportedKeys.find((el) => el === col.dataKey)) {
|
|
468
|
-
myobj[col.dataKey] = sortedRow[col.dataKey];
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
csvData.push(myobj);
|
|
472
|
-
}
|
|
473
|
-
return Promise.resolve(csvData);
|
|
474
|
-
};
|
|
475
|
-
this.csvHeaders = memoize((columns, exportCSVDataKeys) => {
|
|
476
|
-
let tempHeaders = [];
|
|
477
|
-
columns.forEach((col) => {
|
|
478
|
-
if (exportCSVDataKeys !== void 0 && exportCSVDataKeys.find((el) => el === col.dataKey)) {
|
|
479
|
-
tempHeaders.push({
|
|
480
|
-
displayName: col.label,
|
|
481
|
-
id: col.dataKey
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
return tempHeaders;
|
|
486
|
-
});
|
|
487
|
-
this._computeHeaderSize = this._computeHeaderSize.bind(this);
|
|
488
|
-
this._registerHeader = this._registerHeader.bind(this);
|
|
489
|
-
this._registerObserver = this._registerObserver.bind(this);
|
|
490
|
-
this.headers = createRef();
|
|
491
|
-
this.headers.current = {};
|
|
492
|
-
let options = {
|
|
493
|
-
root: null,
|
|
494
|
-
rootMargin: "0px",
|
|
495
|
-
threshold: 0.1
|
|
496
|
-
};
|
|
497
|
-
this.observer = new IntersectionObserver(this._computeHeaderSize, options);
|
|
498
|
-
this.dropDownVisible = false;
|
|
499
|
-
this.state = {
|
|
500
|
-
headerHeight: this.props.headerHeight,
|
|
501
|
-
indexer: initIndexer(props, this.setVersion),
|
|
502
|
-
indirectionVersion: 0,
|
|
503
|
-
popoverAnchorEl: null,
|
|
504
|
-
popoverColKey: null,
|
|
505
|
-
deferredFilterChange: null
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
componentDidUpdate(oldProps) {
|
|
509
|
-
if (oldProps.indexer !== this.props.indexer || oldProps.sortable !== this.props.sortable) {
|
|
510
|
-
this.setState((state) => {
|
|
511
|
-
return {
|
|
512
|
-
indexer: initIndexer(this.props, this.setVersion),
|
|
513
|
-
indirectionVersion: ((state == null ? void 0 : state.indirectionVersion) ?? 0) + 1
|
|
514
|
-
};
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
if (oldProps.headerHeight !== this.props.headerHeight) {
|
|
518
|
-
this._computeHeaderSize();
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
componentDidMount() {
|
|
522
|
-
window.addEventListener("resize", this._computeHeaderSize);
|
|
523
|
-
}
|
|
524
|
-
componentWillUnmount() {
|
|
525
|
-
window.removeEventListener("resize", this._computeHeaderSize);
|
|
526
|
-
this.observer.disconnect();
|
|
527
|
-
}
|
|
528
|
-
_registerHeader(label, header) {
|
|
529
|
-
if (this.headers.current) {
|
|
530
|
-
this.headers.current[label] = header;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
_registerObserver(element) {
|
|
534
|
-
if (element !== null) {
|
|
535
|
-
this.observer.observe(element);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
onFilterParamsChange(newVal, colKey) {
|
|
539
|
-
var _a;
|
|
540
|
-
const nonEmpty = (newVal == null ? void 0 : newVal.length) === 0 ? null : newVal;
|
|
541
|
-
if (this.props.defersFilterChanges) {
|
|
542
|
-
this.setState({
|
|
543
|
-
deferredFilterChange: { newVal, colKey }
|
|
544
|
-
});
|
|
545
|
-
} else if ((_a = this.state.indexer) == null ? void 0 : _a.setColFilterUserParams(colKey, nonEmpty)) {
|
|
546
|
-
this.setState({
|
|
547
|
-
indirectionVersion: this.state.indirectionVersion + 1
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
// type check should be increased here
|
|
552
|
-
getDisplayValue(column, cellData) {
|
|
553
|
-
let displayedValue;
|
|
554
|
-
if (!column.numeric) {
|
|
555
|
-
displayedValue = cellData;
|
|
556
|
-
} else if (isNaN(cellData)) {
|
|
557
|
-
displayedValue = "";
|
|
558
|
-
} else if (column.fractionDigits === void 0 || column.fractionDigits === 0) {
|
|
559
|
-
displayedValue = Math.round(cellData);
|
|
560
|
-
} else {
|
|
561
|
-
displayedValue = Number(cellData).toFixed(column.fractionDigits);
|
|
562
|
-
}
|
|
563
|
-
if (column.unit !== void 0) {
|
|
564
|
-
displayedValue += " ";
|
|
565
|
-
displayedValue += column.unit;
|
|
566
|
-
}
|
|
567
|
-
return displayedValue;
|
|
568
|
-
}
|
|
569
|
-
_computeHeaderSize() {
|
|
570
|
-
const headers = Object.values(this.headers.current);
|
|
571
|
-
if (headers.length === 0) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
const scrollHeights = headers.map((header) => header.scrollHeight);
|
|
575
|
-
let headerHeight = Math.max(
|
|
576
|
-
Math.max(...scrollHeights) + DEFAULT_CELL_PADDING,
|
|
577
|
-
this.props.headerHeight
|
|
578
|
-
// hides (most often) padding override by forcing height
|
|
579
|
-
);
|
|
580
|
-
if (headerHeight !== this.state.headerHeight) {
|
|
581
|
-
this.setState({
|
|
582
|
-
headerHeight
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
makeHeaderRenderer(dataKey, columnIndex) {
|
|
587
|
-
const { columns, classes } = this.props;
|
|
588
|
-
return (headerProps) => {
|
|
589
|
-
return /* @__PURE__ */ jsxs(
|
|
590
|
-
TableCell,
|
|
591
|
-
{
|
|
592
|
-
component: "div",
|
|
593
|
-
className: clsx(
|
|
594
|
-
composeClasses(classes, cssTableCell),
|
|
595
|
-
composeClasses(classes, cssFlexContainer),
|
|
596
|
-
composeClasses(classes, cssNoClick),
|
|
597
|
-
composeClasses(classes, cssHeader)
|
|
598
|
-
),
|
|
599
|
-
variant: "head",
|
|
600
|
-
style: { height: this.state.headerHeight },
|
|
601
|
-
align: columns[columnIndex].numeric || false ? "right" : "left",
|
|
602
|
-
ref: (e) => this._registerObserver(e),
|
|
603
|
-
children: [
|
|
604
|
-
this.props.sortable && this.state.indexer ? this.sortableHeader({
|
|
605
|
-
...headerProps,
|
|
606
|
-
columnIndex,
|
|
607
|
-
key: { dataKey }
|
|
608
|
-
}) : this.simpleHeaderRenderer({
|
|
609
|
-
...headerProps
|
|
610
|
-
}),
|
|
611
|
-
columns[columnIndex].extra && columns[columnIndex].extra
|
|
612
|
-
]
|
|
613
|
-
}
|
|
614
|
-
);
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
render() {
|
|
618
|
-
const { viewIndexToModel, rowGetter } = reorderIndex(
|
|
619
|
-
this.state.indexer,
|
|
620
|
-
this.state.indirectionVersion,
|
|
621
|
-
this.props.rows,
|
|
622
|
-
this.props.columns,
|
|
623
|
-
this.props.filter,
|
|
624
|
-
this.props.sort
|
|
625
|
-
);
|
|
626
|
-
const sizes = this.sizes(this.props.columns, this.props.rows, rowGetter);
|
|
627
|
-
const csvHeaders = this.csvHeaders(this.props.columns, this.props.exportCSVDataKeys);
|
|
628
|
-
return /* @__PURE__ */ jsxs(
|
|
629
|
-
"div",
|
|
630
|
-
{
|
|
631
|
-
style: {
|
|
632
|
-
display: "flex",
|
|
633
|
-
flexDirection: "column",
|
|
634
|
-
height: "100%"
|
|
635
|
-
},
|
|
636
|
-
className: this.props.className,
|
|
637
|
-
children: [
|
|
638
|
-
this.props.enableExportCSV && /* @__PURE__ */ jsxs(
|
|
639
|
-
"div",
|
|
640
|
-
{
|
|
641
|
-
style: {
|
|
642
|
-
display: "flex",
|
|
643
|
-
justifyContent: "flex-end",
|
|
644
|
-
alignItems: "center"
|
|
645
|
-
},
|
|
646
|
-
children: [
|
|
647
|
-
/* @__PURE__ */ jsx(FormattedMessage, { id: "MuiVirtualizedTable/exportCSV" }),
|
|
648
|
-
/* @__PURE__ */ jsx(CsvDownloader, { datas: this.getCSVData, columns: csvHeaders, filename: this.getCSVFilename(), children: /* @__PURE__ */ jsx(IconButton, { "aria-label": "exportCSVButton", size: "large", children: /* @__PURE__ */ jsx(GetApp, {}) }) })
|
|
649
|
-
]
|
|
650
|
-
}
|
|
651
|
-
),
|
|
652
|
-
/* @__PURE__ */ jsx("div", { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsx(AutoSizer, { children: ({ height, width }) => this.makeSizedTable(height, width, sizes, viewIndexToModel, rowGetter) }) }),
|
|
653
|
-
this.state.popoverAnchorEl && /* @__PURE__ */ jsx(
|
|
654
|
-
Popover,
|
|
655
|
-
{
|
|
656
|
-
anchorEl: this.state.popoverAnchorEl,
|
|
657
|
-
anchorOrigin: {
|
|
658
|
-
vertical: "bottom",
|
|
659
|
-
horizontal: "left"
|
|
660
|
-
},
|
|
661
|
-
transformOrigin: {
|
|
662
|
-
vertical: "top",
|
|
663
|
-
horizontal: "left"
|
|
664
|
-
},
|
|
665
|
-
onKeyDownCapture: this.handleKeyDownOnPopover,
|
|
666
|
-
onClose: this.closePopover,
|
|
667
|
-
open: !!this.state.popoverAnchorEl,
|
|
668
|
-
PaperProps: { style: { minWidth: "20ex" } },
|
|
669
|
-
children: this.makeColumnFilterEditor()
|
|
670
|
-
}
|
|
671
|
-
)
|
|
672
|
-
]
|
|
673
|
-
}
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
_MuiVirtualizedTableComponent.defaultProps = {
|
|
678
|
-
headerHeight: DEFAULT_HEADER_HEIGHT,
|
|
679
|
-
rowHeight: DEFAULT_ROW_HEIGHT,
|
|
680
|
-
enableExportCSV: false,
|
|
681
|
-
classes: {}
|
|
682
|
-
};
|
|
683
|
-
let MuiVirtualizedTableComponent = _MuiVirtualizedTableComponent;
|
|
684
|
-
const nestedGlobalSelectorsStyles = toNestedGlobalSelectors(defaultStyles, generateMuiVirtualizedTableClass);
|
|
685
|
-
const MuiVirtualizedTable = styled(MuiVirtualizedTableComponent)(nestedGlobalSelectorsStyles);
|
|
686
|
-
export {
|
|
687
|
-
DEFAULT_CELL_PADDING,
|
|
688
|
-
DEFAULT_HEADER_HEIGHT,
|
|
689
|
-
DEFAULT_ROW_HEIGHT,
|
|
690
|
-
MuiVirtualizedTable,
|
|
691
|
-
generateMuiVirtualizedTableClass
|
|
692
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2021, RTE (http://www.rte-france.com)
|
|
3
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
6
|
-
*/
|
|
7
|
-
export * from './KeyedColumnsRowIndexer';
|
|
8
|
-
export * from './MuiVirtualizedTable';
|