@perses-dev/components 0.54.0-beta.0 → 0.54.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/FormEditor/FormActions.d.ts +1 -1
- package/dist/FormEditor/FormActions.d.ts.map +1 -1
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.d.ts +1 -1
- package/dist/FormatControls/FormatControls.d.ts.map +1 -1
- package/dist/FormatControls/FormatControls.js +1 -1
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/FormatControls/UnitSelector.d.ts +1 -1
- package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
- package/dist/FormatControls/UnitSelector.js +1 -1
- package/dist/FormatControls/UnitSelector.js.map +1 -1
- package/dist/Legend/Legend.js +1 -1
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/legend-model.d.ts +1 -1
- package/dist/Legend/legend-model.d.ts.map +1 -1
- package/dist/Legend/legend-model.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +26 -6
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +34 -0
- package/dist/Table/TableToolbar.d.ts.map +1 -0
- package/dist/Table/TableToolbar.js +127 -0
- package/dist/Table/TableToolbar.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +3 -1
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +128 -117
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +5 -1
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +12 -0
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
- package/dist/Table/hooks/useFuzzySearch.js +43 -0
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +37 -3
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +1 -2
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
- package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
- package/dist/cjs/FormatControls/FormatControls.js +4 -4
- package/dist/cjs/FormatControls/UnitSelector.js +3 -3
- package/dist/cjs/Legend/Legend.js +2 -2
- package/dist/cjs/Table/Table.js +24 -4
- package/dist/cjs/Table/TableToolbar.js +140 -0
- package/dist/cjs/Table/VirtualizedTable.js +126 -115
- package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
- package/dist/cjs/Table/hooks/useFuzzySearch.js +48 -0
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
- package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
- package/dist/cjs/model/action.js +43 -0
- package/dist/cjs/model/bits.js +113 -0
- package/dist/cjs/model/bytes.js +115 -0
- package/dist/cjs/model/constants.js +23 -0
- package/dist/cjs/model/currency.js +126 -0
- package/dist/cjs/model/date.js +297 -0
- package/dist/cjs/model/decimal.js +72 -0
- package/dist/cjs/model/formatterCache.js +120 -0
- package/dist/cjs/model/index.js +16 -0
- package/dist/cjs/model/legend.js +101 -0
- package/dist/cjs/model/percent.js +82 -0
- package/dist/cjs/model/temperature.js +72 -0
- package/dist/cjs/model/thresholds.js +16 -0
- package/dist/cjs/model/throughput.js +161 -0
- package/dist/cjs/model/time.js +178 -0
- package/dist/cjs/model/transforms.js +29 -0
- package/dist/cjs/model/types.js +16 -0
- package/dist/cjs/model/units.js +186 -0
- package/dist/cjs/model/utils.js +48 -0
- package/dist/cjs/utils/axis.js +5 -5
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/request-interpolation.js +49 -0
- package/dist/model/action.d.ts +4 -0
- package/dist/model/action.d.ts.map +1 -0
- package/dist/model/action.js +27 -0
- package/dist/model/action.js.map +1 -0
- package/dist/model/bits.d.ts +12 -0
- package/dist/model/bits.d.ts.map +1 -0
- package/dist/model/bits.js +89 -0
- package/dist/model/bits.js.map +1 -0
- package/dist/model/bytes.d.ts +12 -0
- package/dist/model/bytes.d.ts.map +1 -0
- package/dist/model/bytes.js +91 -0
- package/dist/model/bytes.js.map +1 -0
- package/dist/model/constants.d.ts +2 -0
- package/dist/model/constants.d.ts.map +1 -0
- package/dist/model/constants.js +15 -0
- package/dist/model/constants.js.map +1 -0
- package/dist/model/currency.d.ts +11 -0
- package/dist/model/currency.d.ts.map +1 -0
- package/dist/model/currency.js +107 -0
- package/dist/model/currency.js.map +1 -0
- package/dist/model/date.d.ts +28 -0
- package/dist/model/date.d.ts.map +1 -0
- package/dist/model/date.js +278 -0
- package/dist/model/date.js.map +1 -0
- package/dist/model/decimal.d.ts +12 -0
- package/dist/model/decimal.d.ts.map +1 -0
- package/dist/model/decimal.js +53 -0
- package/dist/model/decimal.js.map +1 -0
- package/dist/model/formatterCache.d.ts +11 -0
- package/dist/model/formatterCache.d.ts.map +1 -0
- package/dist/model/formatterCache.js +104 -0
- package/dist/model/formatterCache.js.map +1 -0
- package/dist/model/index.d.ts +16 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +16 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +19 -0
- package/dist/model/legend.d.ts.map +1 -0
- package/dist/model/legend.js +61 -0
- package/dist/model/legend.js.map +1 -0
- package/dist/model/percent.d.ts +11 -0
- package/dist/model/percent.d.ts.map +1 -0
- package/dist/model/percent.js +63 -0
- package/dist/model/percent.js.map +1 -0
- package/dist/model/temperature.d.ts +11 -0
- package/dist/model/temperature.d.ts.map +1 -0
- package/dist/model/temperature.js +53 -0
- package/dist/model/temperature.js.map +1 -0
- package/dist/model/theme.d.ts +1 -1
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/dist/model/thresholds.d.ts +16 -0
- package/dist/model/thresholds.d.ts.map +1 -0
- package/dist/model/thresholds.js +15 -0
- package/dist/model/thresholds.js.map +1 -0
- package/dist/model/throughput.d.ts +12 -0
- package/dist/model/throughput.d.ts.map +1 -0
- package/dist/model/throughput.js +142 -0
- package/dist/model/throughput.js.map +1 -0
- package/dist/model/time.d.ts +23 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +158 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/transforms.d.ts +43 -0
- package/dist/model/transforms.d.ts.map +1 -0
- package/dist/model/transforms.js +22 -0
- package/dist/model/transforms.js.map +1 -0
- package/dist/model/types.d.ts +56 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +15 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/units.d.ts +105 -0
- package/dist/model/units.d.ts.map +1 -0
- package/dist/model/units.js +132 -0
- package/dist/model/units.js.map +1 -0
- package/dist/model/utils.d.ts +4 -0
- package/dist/model/utils.d.ts.map +1 -0
- package/dist/model/utils.js +32 -0
- package/dist/model/utils.js.map +1 -0
- package/dist/utils/axis.d.ts +1 -1
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +1 -1
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/request-interpolation.d.ts +6 -0
- package/dist/utils/request-interpolation.d.ts.map +1 -0
- package/dist/utils/request-interpolation.js +33 -0
- package/dist/utils/request-interpolation.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { Checkbox, IconButton, InputAdornment, ListItemText, Menu, MenuItem, Stack } from '@mui/material';
|
|
15
|
+
import { useCallback, useState } from 'react';
|
|
16
|
+
import Magnify from 'mdi-material-ui/Magnify';
|
|
17
|
+
import Close from 'mdi-material-ui/Close';
|
|
18
|
+
import ViewColumn from 'mdi-material-ui/ViewColumn';
|
|
19
|
+
import { TextField } from '../controls';
|
|
20
|
+
export function TableToolbar({ isSearchEnabled, globalFilter, onGlobalFilterChange, isColumnFilterEnabled, columns, width, columnFilterMenuMaxHeight = 400 }) {
|
|
21
|
+
const [colMenuAnchor, setColMenuAnchor] = useState(null);
|
|
22
|
+
const colMenuOpen = Boolean(colMenuAnchor);
|
|
23
|
+
const [searchResetKey, setSearchResetKey] = useState(0);
|
|
24
|
+
const handleSearchClear = useCallback(()=>{
|
|
25
|
+
onGlobalFilterChange('');
|
|
26
|
+
setSearchResetKey((prev)=>prev + 1);
|
|
27
|
+
}, [
|
|
28
|
+
onGlobalFilterChange
|
|
29
|
+
]);
|
|
30
|
+
if (!isSearchEnabled && !isColumnFilterEnabled) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
34
|
+
direction: "row",
|
|
35
|
+
gap: 1,
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
justifyContent: "flex-end",
|
|
38
|
+
width: width,
|
|
39
|
+
padding: "0.5rem",
|
|
40
|
+
sx: {
|
|
41
|
+
backgroundColor: (theme)=>theme.palette.background.default
|
|
42
|
+
},
|
|
43
|
+
children: [
|
|
44
|
+
isSearchEnabled && /*#__PURE__*/ _jsx(TextField, {
|
|
45
|
+
placeholder: "Search...",
|
|
46
|
+
value: globalFilter,
|
|
47
|
+
onChange: onGlobalFilterChange,
|
|
48
|
+
variant: "standard",
|
|
49
|
+
slotProps: {
|
|
50
|
+
htmlInput: {
|
|
51
|
+
'aria-label': 'search table'
|
|
52
|
+
},
|
|
53
|
+
input: {
|
|
54
|
+
startAdornment: /*#__PURE__*/ _jsx(InputAdornment, {
|
|
55
|
+
position: "start",
|
|
56
|
+
children: /*#__PURE__*/ _jsx(Magnify, {
|
|
57
|
+
fontSize: "small"
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
endAdornment: globalFilter !== '' && /*#__PURE__*/ _jsx(InputAdornment, {
|
|
61
|
+
position: "end",
|
|
62
|
+
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
63
|
+
onClick: handleSearchClear,
|
|
64
|
+
children: /*#__PURE__*/ _jsx(Close, {
|
|
65
|
+
fontSize: "small"
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
sx: {
|
|
72
|
+
flexGrow: 1
|
|
73
|
+
}
|
|
74
|
+
}, searchResetKey),
|
|
75
|
+
isColumnFilterEnabled && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
76
|
+
children: [
|
|
77
|
+
/*#__PURE__*/ _jsx(IconButton, {
|
|
78
|
+
onClick: (e)=>setColMenuAnchor(e.currentTarget),
|
|
79
|
+
"aria-haspopup": "listbox",
|
|
80
|
+
"aria-expanded": colMenuOpen,
|
|
81
|
+
color: "info",
|
|
82
|
+
children: /*#__PURE__*/ _jsx(ViewColumn, {})
|
|
83
|
+
}),
|
|
84
|
+
/*#__PURE__*/ _jsx(Menu, {
|
|
85
|
+
anchorEl: colMenuAnchor,
|
|
86
|
+
open: colMenuOpen,
|
|
87
|
+
onClose: ()=>setColMenuAnchor(null),
|
|
88
|
+
slotProps: {
|
|
89
|
+
list: {
|
|
90
|
+
dense: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
sx: {
|
|
94
|
+
maxHeight: columnFilterMenuMaxHeight
|
|
95
|
+
},
|
|
96
|
+
children: columns.map((column)=>{
|
|
97
|
+
const header = column.columnDef.header;
|
|
98
|
+
const label = typeof header === 'string' ? header : column.id;
|
|
99
|
+
return /*#__PURE__*/ _jsxs(MenuItem, {
|
|
100
|
+
disabled: !column.getCanHide(),
|
|
101
|
+
onClick: column.getCanHide() ? column.getToggleVisibilityHandler() : undefined,
|
|
102
|
+
dense: true,
|
|
103
|
+
children: [
|
|
104
|
+
/*#__PURE__*/ _jsx(Checkbox, {
|
|
105
|
+
checked: column.getIsVisible(),
|
|
106
|
+
disabled: !column.getCanHide(),
|
|
107
|
+
size: "small",
|
|
108
|
+
disableRipple: true,
|
|
109
|
+
sx: {
|
|
110
|
+
p: 0,
|
|
111
|
+
mr: 1
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
/*#__PURE__*/ _jsx(ListItemText, {
|
|
115
|
+
primary: label
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
}, column.id);
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
})
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=TableToolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Table/TableToolbar.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Checkbox, IconButton, InputAdornment, ListItemText, Menu, MenuItem, Stack } from '@mui/material';\nimport { Column } from '@tanstack/react-table';\nimport { ReactElement, useCallback, useState } from 'react';\nimport Magnify from 'mdi-material-ui/Magnify';\nimport Close from 'mdi-material-ui/Close';\nimport ViewColumn from 'mdi-material-ui/ViewColumn';\nimport { TextField } from '../controls';\n\nexport interface TableToolbarProps<TableData> {\n /**\n * When `true`, a search input is rendered.\n */\n isSearchEnabled?: boolean;\n\n /**\n * Current value of the global filter / search query.\n */\n globalFilter: string;\n\n /**\n * Callback fired when the search query changes.\n */\n onGlobalFilterChange: (value: string) => void;\n\n /**\n * When `true`, a \"Columns\" button is rendered that opens a column visibility dropdown.\n */\n isColumnFilterEnabled?: boolean;\n\n /**\n * All columns from the table instance, used to build the visibility menu.\n */\n columns: Array<Column<TableData>>;\n /**\n * The width of the toolbar, used to determine when to switch to a more compact layout.\n */\n width: number | string;\n\n /**\n * Max height for the column filter menu.\n */\n columnFilterMenuMaxHeight?: number | string;\n}\n\nexport function TableToolbar<TableData>({\n isSearchEnabled,\n globalFilter,\n onGlobalFilterChange,\n isColumnFilterEnabled,\n columns,\n width,\n columnFilterMenuMaxHeight = 400,\n}: TableToolbarProps<TableData>): ReactElement | null {\n const [colMenuAnchor, setColMenuAnchor] = useState<null | HTMLElement>(null);\n const colMenuOpen = Boolean(colMenuAnchor);\n const [searchResetKey, setSearchResetKey] = useState(0);\n\n const handleSearchClear = useCallback(() => {\n onGlobalFilterChange('');\n setSearchResetKey((prev) => prev + 1);\n }, [onGlobalFilterChange]);\n\n if (!isSearchEnabled && !isColumnFilterEnabled) {\n return null;\n }\n\n return (\n <Stack\n direction=\"row\"\n gap={1}\n alignItems=\"center\"\n justifyContent=\"flex-end\"\n width={width}\n padding=\"0.5rem\"\n sx={{ backgroundColor: (theme) => theme.palette.background.default }}\n >\n {isSearchEnabled && (\n <TextField\n key={searchResetKey}\n placeholder=\"Search...\"\n value={globalFilter}\n onChange={onGlobalFilterChange}\n variant=\"standard\"\n slotProps={{\n htmlInput: { 'aria-label': 'search table' },\n input: {\n startAdornment: (\n <InputAdornment position=\"start\">\n <Magnify fontSize=\"small\" />\n </InputAdornment>\n ),\n endAdornment: globalFilter !== '' && (\n <InputAdornment position=\"end\">\n <IconButton onClick={handleSearchClear}>\n <Close fontSize=\"small\" />\n </IconButton>\n </InputAdornment>\n ),\n },\n }}\n sx={{ flexGrow: 1 }}\n />\n )}\n {isColumnFilterEnabled && (\n <>\n <IconButton\n onClick={(e) => setColMenuAnchor(e.currentTarget)}\n aria-haspopup=\"listbox\"\n aria-expanded={colMenuOpen}\n color=\"info\"\n >\n <ViewColumn />\n </IconButton>\n <Menu\n anchorEl={colMenuAnchor}\n open={colMenuOpen}\n onClose={() => setColMenuAnchor(null)}\n slotProps={{ list: { dense: true } }}\n sx={{ maxHeight: columnFilterMenuMaxHeight }}\n >\n {columns.map((column) => {\n const header = column.columnDef.header;\n const label = typeof header === 'string' ? header : column.id;\n return (\n <MenuItem\n key={column.id}\n disabled={!column.getCanHide()}\n onClick={column.getCanHide() ? column.getToggleVisibilityHandler() : undefined}\n dense\n >\n <Checkbox\n checked={column.getIsVisible()}\n disabled={!column.getCanHide()}\n size=\"small\"\n disableRipple\n sx={{ p: 0, mr: 1 }}\n />\n <ListItemText primary={label} />\n </MenuItem>\n );\n })}\n </Menu>\n </>\n )}\n </Stack>\n );\n}\n"],"names":["Checkbox","IconButton","InputAdornment","ListItemText","Menu","MenuItem","Stack","useCallback","useState","Magnify","Close","ViewColumn","TextField","TableToolbar","isSearchEnabled","globalFilter","onGlobalFilterChange","isColumnFilterEnabled","columns","width","columnFilterMenuMaxHeight","colMenuAnchor","setColMenuAnchor","colMenuOpen","Boolean","searchResetKey","setSearchResetKey","handleSearchClear","prev","direction","gap","alignItems","justifyContent","padding","sx","backgroundColor","theme","palette","background","default","placeholder","value","onChange","variant","slotProps","htmlInput","input","startAdornment","position","fontSize","endAdornment","onClick","flexGrow","e","currentTarget","aria-haspopup","aria-expanded","color","anchorEl","open","onClose","list","dense","maxHeight","map","column","header","columnDef","label","id","disabled","getCanHide","getToggleVisibilityHandler","undefined","checked","getIsVisible","size","disableRipple","p","mr","primary"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,QAAQ,EAAEC,UAAU,EAAEC,cAAc,EAAEC,YAAY,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,QAAQ,gBAAgB;AAE1G,SAAuBC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAC5D,OAAOC,aAAa,0BAA0B;AAC9C,OAAOC,WAAW,wBAAwB;AAC1C,OAAOC,gBAAgB,6BAA6B;AACpD,SAASC,SAAS,QAAQ,cAAc;AAsCxC,OAAO,SAASC,aAAwB,EACtCC,eAAe,EACfC,YAAY,EACZC,oBAAoB,EACpBC,qBAAqB,EACrBC,OAAO,EACPC,KAAK,EACLC,4BAA4B,GAAG,EACF;IAC7B,MAAM,CAACC,eAAeC,iBAAiB,GAAGd,SAA6B;IACvE,MAAMe,cAAcC,QAAQH;IAC5B,MAAM,CAACI,gBAAgBC,kBAAkB,GAAGlB,SAAS;IAErD,MAAMmB,oBAAoBpB,YAAY;QACpCS,qBAAqB;QACrBU,kBAAkB,CAACE,OAASA,OAAO;IACrC,GAAG;QAACZ;KAAqB;IAEzB,IAAI,CAACF,mBAAmB,CAACG,uBAAuB;QAC9C,OAAO;IACT;IAEA,qBACE,MAACX;QACCuB,WAAU;QACVC,KAAK;QACLC,YAAW;QACXC,gBAAe;QACfb,OAAOA;QACPc,SAAQ;QACRC,IAAI;YAAEC,iBAAiB,CAACC,QAAUA,MAAMC,OAAO,CAACC,UAAU,CAACC,OAAO;QAAC;;YAElEzB,iCACC,KAACF;gBAEC4B,aAAY;gBACZC,OAAO1B;gBACP2B,UAAU1B;gBACV2B,SAAQ;gBACRC,WAAW;oBACTC,WA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
|
2
2
|
import { ReactElement } from 'react';
|
|
3
|
+
import { TableToolbarProps } from './TableToolbar';
|
|
3
4
|
import { TableCellConfigs, TableProps } from './model/table-model';
|
|
4
5
|
export type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>> & Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {
|
|
5
6
|
onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;
|
|
@@ -8,6 +9,7 @@ export type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableDat
|
|
|
8
9
|
headers: Array<HeaderGroup<TableData>>;
|
|
9
10
|
cellConfigs?: TableCellConfigs;
|
|
10
11
|
rowCount: number;
|
|
12
|
+
toolbarConfig: Pick<TableToolbarProps<TableData>, 'isSearchEnabled' | 'globalFilter' | 'onGlobalFilterChange' | 'isColumnFilterEnabled' | 'columns' | 'columnFilterMenuMaxHeight'>;
|
|
11
13
|
};
|
|
12
|
-
export declare function VirtualizedTable<TableData>({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, }: VirtualizedTableProps<TableData>): ReactElement;
|
|
14
|
+
export declare function VirtualizedTable<TableData>({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, toolbarConfig, }: VirtualizedTableProps<TableData>): ReactElement;
|
|
13
15
|
//# sourceMappingURL=VirtualizedTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot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B,EAClB,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,aAAa,EACb,IAAI,EACJ,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,aAAa,GACd,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,YAAY,CAyPjD"}
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { flexRender } from '@tanstack/react-table';
|
|
15
15
|
import { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';
|
|
16
16
|
import { TableVirtuoso } from 'react-virtuoso';
|
|
17
|
-
import {
|
|
17
|
+
import { useMemo, useRef } from 'react';
|
|
18
|
+
import { TableToolbar } from './TableToolbar';
|
|
18
19
|
import { TableRow } from './TableRow';
|
|
19
20
|
import { TableBody } from './TableBody';
|
|
20
21
|
import { InnerTable } from './InnerTable';
|
|
@@ -27,7 +28,7 @@ import { TableFoot } from './TableFoot';
|
|
|
27
28
|
// Separating out the virtualized table because we may want a paginated table
|
|
28
29
|
// in the future that does not need virtualization, and we'd likely lay them
|
|
29
30
|
// out differently.
|
|
30
|
-
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount }) {
|
|
31
|
+
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, toolbarConfig }) {
|
|
31
32
|
const virtuosoRef = useRef(null);
|
|
32
33
|
// Use a ref for these values because they are only needed for keyboard
|
|
33
34
|
// focus interactions and setting them on state will lead to a significant
|
|
@@ -115,129 +116,139 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, d
|
|
|
115
116
|
pageSize: parseInt(event.target.value, 10)
|
|
116
117
|
});
|
|
117
118
|
};
|
|
118
|
-
return /*#__PURE__*/ _jsx(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
119
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
120
|
+
children: /*#__PURE__*/ _jsxs(Box, {
|
|
121
|
+
style: {
|
|
122
|
+
width,
|
|
123
|
+
height,
|
|
124
|
+
display: 'flex',
|
|
125
|
+
flexDirection: 'column'
|
|
126
|
+
},
|
|
127
|
+
children: [
|
|
128
|
+
/*#__PURE__*/ _jsx(TableToolbar, {
|
|
129
|
+
...toolbarConfig,
|
|
130
|
+
width: width
|
|
131
|
+
}),
|
|
132
|
+
/*#__PURE__*/ _jsx(TableVirtuoso, {
|
|
133
|
+
ref: virtuosoRef,
|
|
134
|
+
totalCount: rows.length,
|
|
135
|
+
components: VirtuosoTableComponents,
|
|
136
|
+
// Note: this value is impacted by overscan. See this issue if overscan
|
|
137
|
+
// is added.
|
|
138
|
+
// https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138
|
|
139
|
+
rangeChanged: setVisibleRange,
|
|
140
|
+
fixedHeaderContent: ()=>{
|
|
141
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
142
|
+
children: headers.map((headerGroup)=>{
|
|
143
|
+
return /*#__PURE__*/ _jsx(TableRow, {
|
|
144
|
+
density: density,
|
|
145
|
+
children: headerGroup.headers.map((header, i, headers)=>{
|
|
146
|
+
const column = header.column;
|
|
147
|
+
const position = {
|
|
148
|
+
row: 0,
|
|
149
|
+
column: i
|
|
150
|
+
};
|
|
151
|
+
const isSorted = column.getIsSorted();
|
|
152
|
+
const nextSorting = column.getNextSortingOrder();
|
|
153
|
+
return /*#__PURE__*/ _jsx(TableHeaderCell, {
|
|
154
|
+
onSort: column.getCanSort() ? column.getToggleSortingHandler() : undefined,
|
|
155
|
+
sortDirection: typeof isSorted === 'string' ? isSorted : undefined,
|
|
156
|
+
nextSortDirection: typeof nextSorting === 'string' ? nextSorting : undefined,
|
|
157
|
+
width: column.getSize() || defaultColumnWidth,
|
|
158
|
+
defaultColumnHeight: defaultColumnHeight,
|
|
159
|
+
align: column.columnDef.meta?.align,
|
|
160
|
+
variant: "head",
|
|
161
|
+
density: density,
|
|
162
|
+
description: column.columnDef.meta?.headerDescription,
|
|
163
|
+
focusState: getFocusState(position),
|
|
164
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
165
|
+
isFirstColumn: i === 0,
|
|
166
|
+
isLastColumn: i === headers.length - 1,
|
|
167
|
+
children: flexRender(column.columnDef.header, header.getContext())
|
|
168
|
+
}, header.id);
|
|
169
|
+
})
|
|
170
|
+
}, headerGroup.id);
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
},
|
|
174
|
+
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ _jsx(MuiTableRow, {
|
|
175
|
+
sx: {
|
|
176
|
+
backgroundColor: (theme)=>theme.palette.background.default
|
|
177
|
+
},
|
|
178
|
+
children: /*#__PURE__*/ _jsx(TablePagination, {
|
|
179
|
+
colSpan: columns.length,
|
|
180
|
+
count: rowCount,
|
|
181
|
+
page: pagination.pageIndex,
|
|
182
|
+
rowsPerPage: pagination.pageSize,
|
|
183
|
+
onPageChange: handleChangePage,
|
|
184
|
+
onRowsPerPageChange: handleChangeRowsPerPage
|
|
185
|
+
})
|
|
186
|
+
}) : undefined,
|
|
187
|
+
itemContent: (index)=>{
|
|
188
|
+
const row = rows[index];
|
|
189
|
+
if (!row) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
193
|
+
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
138
194
|
const position = {
|
|
139
|
-
row:
|
|
195
|
+
row: index + 1,
|
|
140
196
|
column: i
|
|
141
197
|
};
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
198
|
+
const cellContext = cell.getContext();
|
|
199
|
+
const cellConfig = cellConfigs?.[cellContext.cell.id];
|
|
200
|
+
const cellRenderFn = cell.column.columnDef.cell;
|
|
201
|
+
const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
|
|
202
|
+
/*
|
|
203
|
+
IMPORTANT:
|
|
204
|
+
If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)
|
|
205
|
+
Components have no access to any context (Which is intentional and correct)
|
|
206
|
+
We may want to add parameters to a link from neighboring cells in the future as well.
|
|
207
|
+
If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)
|
|
208
|
+
*/ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
|
|
209
|
+
let description = undefined;
|
|
210
|
+
if (typeof cellDescriptionDef === 'function') {
|
|
211
|
+
// If the cell description is a function, set the value using
|
|
212
|
+
// the function.
|
|
213
|
+
description = cellDescriptionDef(cellContext);
|
|
214
|
+
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
215
|
+
// If the cell description is `true` AND the cell content is
|
|
216
|
+
// a string (and thus viable as a `title` attribute), use the
|
|
217
|
+
// cell content.
|
|
218
|
+
description = cellContent;
|
|
219
|
+
}
|
|
220
|
+
/* this has been specifically added for the data link,
|
|
221
|
+
therefore, non string and numeric values should be excluded
|
|
222
|
+
*/ const adjacentCellsValuesMap = Object.entries(row.original)?.filter(([_, value])=>[
|
|
223
|
+
'string',
|
|
224
|
+
'number'
|
|
225
|
+
].includes(typeof value)).reduce((acc, [key, value])=>({
|
|
226
|
+
...acc,
|
|
227
|
+
[key]: String(value)
|
|
228
|
+
}), {});
|
|
229
|
+
return /*#__PURE__*/ _jsx(TableCell, {
|
|
230
|
+
"data-testid": cell.id,
|
|
231
|
+
title: description || cellConfig?.text || cellContent,
|
|
232
|
+
width: cell.column.getSize() || defaultColumnWidth,
|
|
149
233
|
defaultColumnHeight: defaultColumnHeight,
|
|
150
|
-
align: column.columnDef.meta?.align,
|
|
151
|
-
variant: "head",
|
|
234
|
+
align: cell.column.columnDef.meta?.align,
|
|
152
235
|
density: density,
|
|
153
|
-
description: column.columnDef.meta?.headerDescription,
|
|
154
236
|
focusState: getFocusState(position),
|
|
155
237
|
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
156
238
|
isFirstColumn: i === 0,
|
|
157
|
-
isLastColumn: i ===
|
|
158
|
-
|
|
159
|
-
|
|
239
|
+
isLastColumn: i === cells.length - 1,
|
|
240
|
+
description: description,
|
|
241
|
+
color: cellConfig?.textColor ?? undefined,
|
|
242
|
+
backgroundColor: cellConfig?.backgroundColor ?? undefined,
|
|
243
|
+
dataLink: cell.column.columnDef.meta?.dataLink,
|
|
244
|
+
adjacentCellsValuesMap: adjacentCellsValuesMap,
|
|
245
|
+
children: cellConfig?.text || cellContent
|
|
246
|
+
}, cell.id);
|
|
160
247
|
})
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ _jsx(MuiTableRow, {
|
|
166
|
-
sx: {
|
|
167
|
-
backgroundColor: (theme)=>theme.palette.background.default
|
|
168
|
-
},
|
|
169
|
-
children: /*#__PURE__*/ _jsx(TablePagination, {
|
|
170
|
-
colSpan: columns.length,
|
|
171
|
-
count: rowCount,
|
|
172
|
-
page: pagination.pageIndex,
|
|
173
|
-
rowsPerPage: pagination.pageSize,
|
|
174
|
-
onPageChange: handleChangePage,
|
|
175
|
-
onRowsPerPageChange: handleChangeRowsPerPage
|
|
176
|
-
})
|
|
177
|
-
}) : undefined,
|
|
178
|
-
itemContent: (index)=>{
|
|
179
|
-
const row = rows[index];
|
|
180
|
-
if (!row) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
184
|
-
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
185
|
-
const position = {
|
|
186
|
-
row: index + 1,
|
|
187
|
-
column: i
|
|
188
|
-
};
|
|
189
|
-
const cellContext = cell.getContext();
|
|
190
|
-
const cellConfig = cellConfigs?.[cellContext.cell.id];
|
|
191
|
-
const cellRenderFn = cell.column.columnDef.cell;
|
|
192
|
-
const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
|
|
193
|
-
/*
|
|
194
|
-
IMPORTANT:
|
|
195
|
-
If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)
|
|
196
|
-
Components have no access to any context (Which is intentional and correct)
|
|
197
|
-
We may want to add parameters to a link from neighboring cells in the future as well.
|
|
198
|
-
If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)
|
|
199
|
-
*/ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
|
|
200
|
-
let description = undefined;
|
|
201
|
-
if (typeof cellDescriptionDef === 'function') {
|
|
202
|
-
// If the cell description is a function, set the value using
|
|
203
|
-
// the function.
|
|
204
|
-
description = cellDescriptionDef(cellContext);
|
|
205
|
-
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
206
|
-
// If the cell description is `true` AND the cell content is
|
|
207
|
-
// a string (and thus viable as a `title` attribute), use the
|
|
208
|
-
// cell content.
|
|
209
|
-
description = cellContent;
|
|
210
|
-
}
|
|
211
|
-
/* this has been specifically added for the data link,
|
|
212
|
-
therefore, non string and numeric values should be excluded
|
|
213
|
-
*/ const adjacentCellsValuesMap = Object.entries(row.original)?.filter(([_, value])=>[
|
|
214
|
-
'string',
|
|
215
|
-
'number'
|
|
216
|
-
].includes(typeof value)).reduce((acc, [key, value])=>({
|
|
217
|
-
...acc,
|
|
218
|
-
[key]: String(value)
|
|
219
|
-
}), {});
|
|
220
|
-
return /*#__PURE__*/ _jsx(TableCell, {
|
|
221
|
-
"data-testid": cell.id,
|
|
222
|
-
title: description || cellConfig?.text || cellContent,
|
|
223
|
-
width: cell.column.getSize() || defaultColumnWidth,
|
|
224
|
-
defaultColumnHeight: defaultColumnHeight,
|
|
225
|
-
align: cell.column.columnDef.meta?.align,
|
|
226
|
-
density: density,
|
|
227
|
-
focusState: getFocusState(position),
|
|
228
|
-
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
229
|
-
isFirstColumn: i === 0,
|
|
230
|
-
isLastColumn: i === cells.length - 1,
|
|
231
|
-
description: description,
|
|
232
|
-
color: cellConfig?.textColor ?? undefined,
|
|
233
|
-
backgroundColor: cellConfig?.backgroundColor ?? undefined,
|
|
234
|
-
dataLink: cell.column.columnDef.meta?.dataLink,
|
|
235
|
-
adjacentCellsValuesMap: adjacentCellsValuesMap,
|
|
236
|
-
children: cellConfig?.text || cellContent
|
|
237
|
-
}, cell.id);
|
|
238
|
-
})
|
|
239
|
-
});
|
|
240
|
-
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
]
|
|
241
252
|
})
|
|
242
253
|
});
|
|
243
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, HeaderGroup, Row, flexRender } from '@tanstack/react-table';\nimport { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';\nimport { TableVirtuoso, TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { useRef, useMemo, ReactElement } from 'react';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableCellConfigs, TableProps, TableRowEventOpts } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\nimport { TableFoot } from './TableFoot';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n cellConfigs?: TableCellConfigs;\n rowCount: number;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n cellConfigs,\n pagination,\n onPaginationChange,\n rowCount,\n}: VirtualizedTableProps<TableData>): ReactElement {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props): ReactElement => {\n return (\n <InnerTable\n {...props}\n width={width}\n density={density}\n onKeyDown={keyboardNav.onTableKeyDown}\n onBlur={keyboardNav.onTableBlur}\n />\n );\n },\n TableHead,\n TableFoot,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }): ReactElement | null => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: row.id, index: row.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => onRowClick(e, row.id)}\n density={density}\n onMouseOver={(e) => {\n onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody,\n };\n }, [\n density,\n keyboardNav.onTableKeyDown,\n keyboardNav.onTableBlur,\n onRowClick,\n onRowMouseOut,\n onRowMouseOver,\n rows,\n width,\n ]);\n\n const handleChangePage = (_event: React.MouseEvent<HTMLButtonElement> | null, newPage: number): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ ...pagination, pageIndex: newPage });\n };\n\n const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ pageIndex: 0, pageSize: parseInt(event.target.value, 10) });\n };\n\n return (\n <Box style={{ width, height }}>\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n fixedFooterContent={\n pagination\n ? (): ReactElement => (\n <MuiTableRow sx={{ backgroundColor: (theme) => theme.palette.background.default }}>\n <TablePagination\n colSpan={columns.length}\n count={rowCount}\n page={pagination.pageIndex}\n rowsPerPage={pagination.pageSize}\n onPageChange={handleChangePage}\n onRowsPerPageChange={handleChangeRowsPerPage}\n />\n </MuiTableRow>\n )\n : undefined\n }\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n /* \n IMPORTANT:\n If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)\n Components have no access to any context (Which is intentional and correct)\n We may want to add parameters to a link from neighboring cells in the future as well.\n If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)\n */\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n /* this has been specifically added for the data link, \n therefore, non string and numeric values should be excluded\n */\n const adjacentCellsValuesMap = Object.entries(row.original as Record<string, unknown>)\n ?.filter(([_, value]) => ['string', 'number'].includes(typeof value))\n .reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: String(value),\n }),\n {}\n );\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={cell.column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n dataLink={cell.column.columnDef.meta?.dataLink}\n adjacentCellsValuesMap={adjacentCellsValuesMap}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["flexRender","Box","TablePagination","TableRow","MuiTableRow","TableVirtuoso","useRef","useMemo","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","TableFoot","VirtualizedTable","width","height","density","defaultColumnWidth","defaultColumnHeight","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","cellConfigs","pagination","onPaginationChange","rowCount","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","onBlur","onTableBlur","item","index","rowEventOpts","id","onClick","e","onMouseOver","onMouseOut","handleChangePage","_event","newPage","pageIndex","handleChangeRowsPerPage","event","pageSize","parseInt","target","value","style","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","getSize","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","fixedFooterContent","sx","backgroundColor","theme","palette","background","default","colSpan","count","page","rowsPerPage","onPageChange","onRowsPerPageChange","itemContent","getVisibleCells","cell","cells","cellContext","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","adjacentCellsValuesMap","Object","entries","original","filter","_","includes","reduce","acc","key","String","data-testid","title","text","color","textColor","dataLink"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAmCA,UA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,QAAQ,CAAC,OAAOhE,QAC7DiE,OACC,CAACC,KAAK,CAACC,KAAKnE,MAAM,GAAM,CAAA;gCACtB,GAAGkE,GAAG;gCACN,CAACC,IAAI,EAAEC,OAAOpE;4BAChB,CAAA,GACA,CAAC;wBAGL,qBACE,KAAC/D;4BAECoI,eAAanB,KAAKhE,EAAE;4BACpBoF,OAAO3C,eAAe0B,YAAYkB,QAAQhB;4BAC1CjH,OAAO4G,KAAK7E,MAAM,CAACiD,OAAO,MAAM7E;4BAChCC,qBAAqBA;4BACrB6E,OAAO2B,KAAK7E,MAAM,CAACmD,SAAS,CAACC,IAAI,EAAEF;4BACnC/E,SAASA;4BACTqF,YAAY5D,cAAc0C;4BAC1BmB,gBAAgB,IAAMlE,YAAYmE,WAAW,CAACpB;4BAC9CqB,eAAetB,MAAM;4BACrBuB,cAAcvB,MAAMyC,MAAMpF,MAAM,GAAG;4BACnC4D,aAAaA;4BACb6C,OAAOnB,YAAYoB,aAAatD;4BAChCkB,iBAAiBgB,YAAYhB,mBAAmBlB;4BAChDuD,UAAUxB,KAAK7E,MAAM,CAACmD,SAAS,CAACC,IAAI,EAAEiD;4BACtChB,wBAAwBA;sCAEvBL,YAAYkB,QAAQhB;2BAjBhBL,KAAKhE,EAAE;oBAoBlB;;YAGN;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, flexRender, HeaderGroup, Row } from '@tanstack/react-table';\nimport { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';\nimport { TableComponents, TableVirtuoso, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { ReactElement, useMemo, useRef } from 'react';\nimport { TableToolbar, TableToolbarProps } from './TableToolbar';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableCellConfigs, TableProps, TableRowEventOpts } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\nimport { TableFoot } from './TableFoot';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n cellConfigs?: TableCellConfigs;\n rowCount: number;\n toolbarConfig: Pick<\n TableToolbarProps<TableData>,\n | 'isSearchEnabled'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n | 'isColumnFilterEnabled'\n | 'columns'\n | 'columnFilterMenuMaxHeight'\n >;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n cellConfigs,\n pagination,\n onPaginationChange,\n rowCount,\n toolbarConfig,\n}: VirtualizedTableProps<TableData>): ReactElement {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props): ReactElement => {\n return (\n <InnerTable\n {...props}\n width={width}\n density={density}\n onKeyDown={keyboardNav.onTableKeyDown}\n onBlur={keyboardNav.onTableBlur}\n />\n );\n },\n TableHead,\n TableFoot,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }): ReactElement | null => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: row.id, index: row.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => onRowClick(e, row.id)}\n density={density}\n onMouseOver={(e) => {\n onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody,\n };\n }, [\n density,\n keyboardNav.onTableKeyDown,\n keyboardNav.onTableBlur,\n onRowClick,\n onRowMouseOut,\n onRowMouseOver,\n rows,\n width,\n ]);\n\n const handleChangePage = (_event: React.MouseEvent<HTMLButtonElement> | null, newPage: number): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ ...pagination, pageIndex: newPage });\n };\n\n const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ pageIndex: 0, pageSize: parseInt(event.target.value, 10) });\n };\n\n return (\n <>\n <Box style={{ width, height, display: 'flex', flexDirection: 'column' }}>\n <TableToolbar {...toolbarConfig} width={width} />\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n fixedFooterContent={\n pagination\n ? (): ReactElement => (\n <MuiTableRow sx={{ backgroundColor: (theme) => theme.palette.background.default }}>\n <TablePagination\n colSpan={columns.length}\n count={rowCount}\n page={pagination.pageIndex}\n rowsPerPage={pagination.pageSize}\n onPageChange={handleChangePage}\n onRowsPerPageChange={handleChangeRowsPerPage}\n />\n </MuiTableRow>\n )\n : undefined\n }\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n /*\n IMPORTANT:\n If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)\n Components have no access to any context (Which is intentional and correct)\n We may want to add parameters to a link from neighboring cells in the future as well.\n If this is the case, the value of the neighboring cells should be read from here and be replaced. (Bing discussed at the moment, not decided yet)\n */\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n /* this has been specifically added for the data link,\n therefore, non string and numeric values should be excluded\n */\n const adjacentCellsValuesMap = Object.entries(row.original as Record<string, unknown>)\n ?.filter(([_, value]) => ['string', 'number'].includes(typeof value))\n .reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: String(value),\n }),\n {}\n );\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={cell.column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n dataLink={cell.column.columnDef.meta?.dataLink}\n adjacentCellsValuesMap={adjacentCellsValuesMap}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n </>\n );\n}\n"],"names":["flexRender","Box","TablePagination","TableRow","MuiTableRow","TableVirtuoso","useMemo","useRef","TableToolbar","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","TableFoot","VirtualizedTable","width","height","density","defaultColumnWidth","defaultColumnHeight","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","cellConfigs","pagination","onPaginationChange","rowCount","toolbarConfig","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","onBlur","onTableBlur","item","index","rowEventOpts","id","onClick","e","onMouseOver","onMouseOut","handleChangePage","_event","newPage","pageIndex","handleChangeRowsPerPage","event","pageSize","parseInt","target","value","style","display","flexDirection","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","getSize","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","fixedFooterContent","sx","backgroundColor","theme","palette","background","default","colSpan","count","page","rowsPerPage","onPageChange","onRowsPerPageChange","itemContent","getVisibleCells","cell","cells","cellContext","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","adjacentCellsValuesMap","Object","entries","original","filter","_","includes","reduce","acc","key","String","data-testid","title","text","color","textColor","dataLink"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AA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Ac6B,mBAAmBJ;gCACnC,OAAO,IAAII,sBAAsB,OAAOD,gBAAgB,UAAU;oCAChE,4DAA4D;oCAC5D,6DAA6D;oCAC7D,gBAAgB;oCAChB5B,cAAc4B;gCAChB;gCAEA;;kBAEA,GACA,MAAMG,yBAAyBC,OAAOC,OAAO,CAAC3F,IAAI4F,QAAQ,GACtDC,OAAO,CAAC,CAACC,GAAGjE,MAAM,GAAK;wCAAC;wCAAU;qCAAS,CAACkE,QAAQ,CAAC,OAAOlE,QAC7DmE,OACC,CAACC,KAAK,CAACC,KAAKrE,MAAM,GAAM,CAAA;wCACtB,GAAGoE,GAAG;wCACN,CAACC,IAAI,EAAEC,OAAOtE;oCAChB,CAAA,GACA,CAAC;gCAGL,qBACE,KAAChE;oCAECuI,eAAanB,KAAKlE,EAAE;oCACpBsF,OAAO3C,eAAe0B,YAAYkB,QAAQhB;oCAC1CpH,OAAO+G,KAAK/E,MAAM,CAACmD,OAAO,MAAMhF;oCAChCC,qBAAqBA;oCACrBgF,OAAO2B,KAAK/E,MAAM,CAACqD,SAAS,CAACC,IAAI,EAAEF;oCACnClF,SAASA;oCACTwF,YAAY9D,cAAc4C;oCAC1BmB,gBAAgB,IAAMpE,YAAYqE,WAAW,CAACpB;oCAC9CqB,eAAetB,MAAM;oCACrBuB,cAAcvB,MAAMyC,MAAMtF,MAAM,GAAG;oCACnC8D,aAAaA;oCACb6C,OAAOnB,YAAYoB,aAAatD;oCAChCkB,iBAAiBgB,YAAYhB,mBAAmBlB;oCAChDuD,UAAUxB,KAAK/E,MAAM,CAACqD,SAAS,CAACC,IAAI,EAAEiD;oCACtChB,wBAAwBA;8CAEvBL,YAAYkB,QAAQhB;mCAjBhBL,KAAKlE,EAAE;4BAoBlB;;oBAGN;;;;;AAKV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedTableContainer.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTableContainer.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuC,mBAAmB,IAAI,sBAAsB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"VirtualizedTableContainer.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTableContainer.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuC,mBAAmB,IAAI,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAInH,KAAK,8BAA8B,GAAG,sBAAsB,CAAC;AAE7D,eAAO,MAAM,yBAAyB,wIAIrC,CAAC"}
|
|
@@ -13,11 +13,15 @@
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { TableContainer as MuiTableContainer } from '@mui/material';
|
|
15
15
|
import { forwardRef } from 'react';
|
|
16
|
+
import { combineSx } from '../utils/combine-sx';
|
|
16
17
|
export const VirtualizedTableContainer = /*#__PURE__*/ forwardRef(function VirtualizedTableContainer(props, ref) {
|
|
17
18
|
return /*#__PURE__*/ _jsx(MuiTableContainer, {
|
|
18
19
|
...props,
|
|
19
20
|
tabIndex: -1,
|
|
20
|
-
ref: ref
|
|
21
|
+
ref: ref,
|
|
22
|
+
sx: combineSx({
|
|
23
|
+
flexGrow: 1
|
|
24
|
+
}, props.sx)
|
|
21
25
|
});
|
|
22
26
|
});
|
|
23
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTableContainer.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableContainer as MuiTableContainer, TableContainerProps as MuiTableContainerProps } from '@mui/material';\nimport { forwardRef } from 'react';\n\ntype VirtualizedTableContainerProps = MuiTableContainerProps;\n\nexport const VirtualizedTableContainer = forwardRef<HTMLDivElement, VirtualizedTableContainerProps>(\n function VirtualizedTableContainer(props, ref) {\n return <MuiTableContainer {...props} tabIndex={-1} ref={ref} />;\n }\n);\n"],"names":["TableContainer","MuiTableContainer","forwardRef","VirtualizedTableContainer","props","ref","tabIndex"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,kBAAkBC,iBAAiB,QAAuD,gBAAgB;AACnH,SAASC,UAAU,QAAQ,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTableContainer.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableContainer as MuiTableContainer, TableContainerProps as MuiTableContainerProps } from '@mui/material';\nimport { forwardRef } from 'react';\nimport { combineSx } from '../utils/combine-sx';\n\ntype VirtualizedTableContainerProps = MuiTableContainerProps;\n\nexport const VirtualizedTableContainer = forwardRef<HTMLDivElement, VirtualizedTableContainerProps>(\n function VirtualizedTableContainer(props, ref) {\n return <MuiTableContainer {...props} tabIndex={-1} ref={ref} sx={combineSx({ flexGrow: 1 }, props.sx)} />;\n }\n);\n"],"names":["TableContainer","MuiTableContainer","forwardRef","combineSx","VirtualizedTableContainer","props","ref","tabIndex","sx","flexGrow"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,kBAAkBC,iBAAiB,QAAuD,gBAAgB;AACnH,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,SAAS,QAAQ,sBAAsB;AAIhD,OAAO,MAAMC,0CAA4BF,WACvC,SAASE,0BAA0BC,KAAK,EAAEC,GAAG;IAC3C,qBAAO,KAACL;QAAmB,GAAGI,KAAK;QAAEE,UAAU,CAAC;QAAGD,KAAKA;QAAKE,IAAIL,UAAU;YAAEM,UAAU;QAAE,GAAGJ,MAAMG,EAAE;;AACtG,GACA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnChangeFn, TableOptions } from '@tanstack/react-table';
|
|
2
|
+
export interface UseFuzzySearchResult<TableData> {
|
|
3
|
+
globalFilter: string;
|
|
4
|
+
setGlobalFilter: OnChangeFn<string>;
|
|
5
|
+
fuzzySearchOptions: Pick<TableOptions<TableData>, 'filterFns' | 'globalFilterFn' | 'getFilteredRowModel' | 'filterFromLeafRows' | 'onGlobalFilterChange'>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns fuzzy search state and the corresponding `useReactTable` options.
|
|
9
|
+
* Filter options are disabled when `showSearch` is falsy.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useFuzzySearch<TableData>(isSearchEnabled: boolean | undefined): UseFuzzySearchResult<TableData>;
|
|
12
|
+
//# sourceMappingURL=useFuzzySearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFuzzySearch.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiC,UAAU,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAUhG,MAAM,WAAW,oBAAoB,CAAC,SAAS;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,kBAAkB,EAAE,IAAI,CACtB,YAAY,CAAC,SAAS,CAAC,EACvB,WAAW,GAAG,gBAAgB,GAAG,qBAAqB,GAAG,oBAAoB,GAAG,sBAAsB,CACvG,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,OAAO,GAAG,SAAS,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAc/G"}
|