@perses-dev/components 0.54.0-beta.1 → 0.54.0-beta.3
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/AlignSelector/AlignSelector.js +1 -1
- package/dist/AlignSelector/AlignSelector.js.map +1 -1
- package/dist/ColorPicker/ColorPicker.js +1 -1
- package/dist/ColorPicker/ColorPicker.js.map +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js +1 -1
- package/dist/ColorPicker/OptionsColorPicker.js.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js +1 -1
- package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/DragAndDrop/DragAndDropList.js +1 -1
- package/dist/DragAndDrop/DragAndDropList.js.map +1 -1
- package/dist/DragAndDrop/DragButton.js +1 -1
- package/dist/DragAndDrop/DragButton.js.map +1 -1
- package/dist/DragAndDrop/DropIndicator.js +1 -1
- package/dist/DragAndDrop/DropIndicator.js.map +1 -1
- package/dist/Drawer/Drawer.js +1 -1
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/EChart/EChart.js +1 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/ErrorAlert.js +1 -1
- package/dist/ErrorAlert.js.map +1 -1
- package/dist/FormEditor/FormActions.js +1 -1
- package/dist/FormEditor/FormActions.js.map +1 -1
- package/dist/FormatControls/FormatControls.js +1 -1
- package/dist/FormatControls/FormatControls.js.map +1 -1
- package/dist/JSONEditor.js +1 -1
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Legend/CompactLegend.js +1 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.js +1 -1
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/LegendColorBadge.js +1 -1
- package/dist/Legend/LegendColorBadge.js.map +1 -1
- package/dist/Legend/ListLegend.js +1 -1
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.js +1 -1
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/Legend/TableLegend.d.ts.map +1 -1
- package/dist/Legend/TableLegend.js +18 -4
- package/dist/Legend/TableLegend.js.map +1 -1
- package/dist/LinksEditor/LinkEditorForm.js +1 -1
- package/dist/LinksEditor/LinkEditorForm.js.map +1 -1
- package/dist/LinksEditor/LinksEditor.js +1 -1
- package/dist/LinksEditor/LinksEditor.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
- package/dist/Overlay/Overlay.js +1 -1
- package/dist/Overlay/Overlay.js.map +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +1 -1
- package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
- package/dist/SortSelector/SortSelectorButtons.js +1 -1
- package/dist/SortSelector/SortSelectorButtons.js.map +1 -1
- package/dist/Table/InnerTable.js +1 -1
- package/dist/Table/InnerTable.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 +25 -12
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableBody.js +1 -1
- package/dist/Table/TableBody.js.map +1 -1
- package/dist/Table/TableCell.js +1 -1
- package/dist/Table/TableCell.js.map +1 -1
- package/dist/Table/TableCheckbox.js +1 -1
- package/dist/Table/TableCheckbox.js.map +1 -1
- package/dist/Table/TableFoot.js +1 -1
- package/dist/Table/TableFoot.js.map +1 -1
- package/dist/Table/TableHead.js +1 -1
- package/dist/Table/TableHead.js.map +1 -1
- package/dist/Table/TableHeaderCell.d.ts +20 -1
- package/dist/Table/TableHeaderCell.d.ts.map +1 -1
- package/dist/Table/TableHeaderCell.js +56 -24
- package/dist/Table/TableHeaderCell.js.map +1 -1
- package/dist/Table/TableRow.js +1 -1
- package/dist/Table/TableRow.js.map +1 -1
- package/dist/Table/TableToolbar.d.ts +13 -1
- package/dist/Table/TableToolbar.d.ts.map +1 -1
- package/dist/Table/TableToolbar.js +15 -4
- package/dist/Table/TableToolbar.js.map +1 -1
- package/dist/Table/VirtualizedTable.d.ts +6 -4
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +151 -128
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/VirtualizedTableContainer.js +1 -1
- package/dist/Table/VirtualizedTableContainer.js.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.d.ts +5 -3
- package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -1
- package/dist/Table/hooks/useFuzzySearch.js +32 -13
- package/dist/Table/hooks/useFuzzySearch.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +42 -2
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js +37 -19
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js +1 -1
- package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js +25 -2
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesLabelsStack.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js +1 -1
- package/dist/TimeSeriesTooltip/SeriesMarker.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeZoneSelector.js +1 -1
- package/dist/TimeZoneSelector.js.map +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js +1 -1
- package/dist/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
- package/dist/TransformsEditor/TransformEditor.js +1 -1
- package/dist/TransformsEditor/TransformEditor.js.map +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
- package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
- package/dist/TransformsEditor/TransformsEditor.js +1 -1
- package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js +1 -1
- package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js +1 -1
- package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
- package/dist/YAxisLabel.js +1 -1
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/Legend/TableLegend.js +16 -2
- package/dist/cjs/Table/Table.js +24 -11
- package/dist/cjs/Table/TableHeaderCell.js +54 -22
- package/dist/cjs/Table/TableToolbar.js +13 -2
- package/dist/cjs/Table/VirtualizedTable.js +150 -127
- package/dist/cjs/Table/hooks/useFuzzySearch.js +30 -11
- package/dist/cjs/Table/model/table-model.js +43 -19
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +23 -0
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/value-mapping.js +16 -0
- package/dist/cjs/theme/typography.js +1 -1
- package/dist/cjs/utils/format.js +20 -0
- package/dist/cjs/utils/index.js +4 -0
- package/dist/cjs/utils/mathjs.js +14 -3
- package/dist/cjs/utils/regexp.js +54 -0
- package/dist/cjs/utils/time-series-data.js +141 -0
- package/dist/cjs/utils/transform-data.js +157 -0
- package/dist/cjs/utils/value-mapping.js +105 -0
- package/dist/context/ChartsProvider.js +1 -1
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/context/ItemActionsProvider.js +1 -1
- package/dist/context/ItemActionsProvider.js.map +1 -1
- package/dist/context/SelectionProvider.js +1 -1
- package/dist/context/SelectionProvider.js.map +1 -1
- package/dist/context/SnackbarProvider.js +1 -1
- package/dist/context/SnackbarProvider.js.map +1 -1
- package/dist/context/TimeZoneProvider.js +1 -1
- package/dist/context/TimeZoneProvider.js.map +1 -1
- package/dist/controls/TextField.js +1 -1
- package/dist/controls/TextField.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/value-mapping.d.ts +35 -0
- package/dist/model/value-mapping.d.ts.map +1 -0
- package/dist/model/value-mapping.js +15 -0
- package/dist/model/value-mapping.js.map +1 -0
- package/dist/test/render.js +1 -1
- package/dist/test/render.js.map +1 -1
- package/dist/theme/typography.js +1 -1
- package/dist/theme/typography.js.map +1 -1
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +17 -0
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mathjs.d.ts +8 -1
- package/dist/utils/mathjs.d.ts.map +1 -1
- package/dist/utils/mathjs.js +5 -2
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/regexp.d.ts +11 -0
- package/dist/utils/regexp.d.ts.map +1 -0
- package/dist/utils/regexp.js +42 -0
- package/dist/utils/regexp.js.map +1 -0
- package/dist/utils/request-interpolation.d.ts +1 -1
- package/dist/utils/request-interpolation.d.ts.map +1 -1
- package/dist/utils/request-interpolation.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +15 -0
- package/dist/utils/time-series-data.d.ts.map +1 -0
- package/dist/utils/time-series-data.js +130 -0
- package/dist/utils/time-series-data.js.map +1 -0
- package/dist/utils/transform-data.d.ts +7 -0
- package/dist/utils/transform-data.d.ts.map +1 -0
- package/dist/utils/transform-data.js +214 -0
- package/dist/utils/transform-data.js.map +1 -0
- package/dist/utils/value-mapping.d.ts +3 -0
- package/dist/utils/value-mapping.d.ts.map +1 -0
- package/dist/utils/value-mapping.js +97 -0
- package/dist/utils/value-mapping.js.map +1 -0
- package/package.json +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
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';
|
|
@@ -28,7 +28,7 @@ import { TableFoot } from './TableFoot';
|
|
|
28
28
|
// Separating out the virtualized table because we may want a paginated table
|
|
29
29
|
// in the future that does not need virtualization, and we'd likely lay them
|
|
30
30
|
// out differently.
|
|
31
|
-
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, toolbarConfig }) {
|
|
31
|
+
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, columnSizing, columnSizingInfo, cellConfigs, pagination, onPaginationChange, rowCount, toolbarConfig }) {
|
|
32
32
|
const virtuosoRef = useRef(null);
|
|
33
33
|
// Use a ref for these values because they are only needed for keyboard
|
|
34
34
|
// focus interactions and setting them on state will lead to a significant
|
|
@@ -116,140 +116,163 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, d
|
|
|
116
116
|
pageSize: parseInt(event.target.value, 10)
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Instead of calling `column.getSize()` on every render for every header
|
|
121
|
+
* and especially every data cell (very expensive),
|
|
122
|
+
* we will calculate all column sizes at once at the root table level in a useMemo
|
|
123
|
+
* and pass the column sizes down as CSS variables to the <table> element.
|
|
124
|
+
*/ const columnSizeVars = useMemo(()=>{
|
|
125
|
+
const colSizes = {};
|
|
126
|
+
headers.forEach((headerGroup)=>{
|
|
127
|
+
headerGroup.headers.filter((header)=>header.column.getCanResize()).forEach((header)=>{
|
|
128
|
+
colSizes[`--header-${header.id}-size`] = header.getSize();
|
|
129
|
+
colSizes[`--col-${header.column.id}-size`] = header.column.getSize();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
return colSizes;
|
|
133
|
+
// We want to recalculate column sizes whenever column sizes or column resizing info changes.
|
|
134
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
135
|
+
}, [
|
|
136
|
+
columnSizingInfo,
|
|
137
|
+
columnSizing,
|
|
138
|
+
headers
|
|
139
|
+
]);
|
|
140
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
141
|
+
style: {
|
|
142
|
+
width,
|
|
143
|
+
height,
|
|
144
|
+
...columnSizeVars
|
|
145
|
+
},
|
|
146
|
+
children: [
|
|
147
|
+
/*#__PURE__*/ _jsx(TableToolbar, {
|
|
148
|
+
...toolbarConfig,
|
|
149
|
+
width: width
|
|
150
|
+
}),
|
|
151
|
+
/*#__PURE__*/ _jsx(TableVirtuoso, {
|
|
152
|
+
ref: virtuosoRef,
|
|
153
|
+
totalCount: rows.length,
|
|
154
|
+
components: VirtuosoTableComponents,
|
|
155
|
+
// Note: this value is impacted by overscan. See this issue if overscan
|
|
156
|
+
// is added.
|
|
157
|
+
// https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138
|
|
158
|
+
rangeChanged: setVisibleRange,
|
|
159
|
+
fixedHeaderContent: ()=>{
|
|
160
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
161
|
+
children: headers.map((headerGroup)=>{
|
|
162
|
+
return /*#__PURE__*/ _jsx(TableRow, {
|
|
163
|
+
density: density,
|
|
164
|
+
children: headerGroup.headers.map((header, i, headers)=>{
|
|
165
|
+
const column = header.column;
|
|
166
|
+
const position = {
|
|
167
|
+
row: 0,
|
|
168
|
+
column: i
|
|
169
|
+
};
|
|
170
|
+
const isSorted = column.getIsSorted();
|
|
171
|
+
const nextSorting = column.getNextSortingOrder();
|
|
172
|
+
return /*#__PURE__*/ _jsx(TableHeaderCell, {
|
|
173
|
+
onSort: column.getCanSort() ? column.getToggleSortingHandler() : undefined,
|
|
174
|
+
sortDirection: typeof isSorted === 'string' ? isSorted : undefined,
|
|
175
|
+
nextSortDirection: typeof nextSorting === 'string' ? nextSorting : undefined,
|
|
176
|
+
width: header.column.getCanResize() ? `calc(var(--header-${header?.id}-size) * 1px)` : column.getSize() || defaultColumnWidth,
|
|
177
|
+
defaultColumnHeight: defaultColumnHeight,
|
|
178
|
+
align: column.columnDef.meta?.align,
|
|
179
|
+
variant: "head",
|
|
180
|
+
density: density,
|
|
181
|
+
description: column.columnDef.meta?.headerDescription,
|
|
182
|
+
focusState: getFocusState(position),
|
|
183
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
184
|
+
isFirstColumn: i === 0,
|
|
185
|
+
isLastColumn: i === headers.length - 1,
|
|
186
|
+
resizeConfig: header.column.getCanResize() ? {
|
|
187
|
+
resizeHandler: header.getResizeHandler(),
|
|
188
|
+
resetSizeHandler: header.column.resetSize,
|
|
189
|
+
isResizing: header.column.getIsResizing()
|
|
190
|
+
} : undefined,
|
|
191
|
+
children: flexRender(column.columnDef.header, header.getContext())
|
|
192
|
+
}, header.id);
|
|
193
|
+
})
|
|
194
|
+
}, headerGroup.id);
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ _jsx(MuiTableRow, {
|
|
199
|
+
sx: {
|
|
200
|
+
backgroundColor: (theme)=>theme.palette.background.default
|
|
201
|
+
},
|
|
202
|
+
children: /*#__PURE__*/ _jsx(TablePagination, {
|
|
203
|
+
colSpan: columns.length,
|
|
204
|
+
count: rowCount,
|
|
205
|
+
page: pagination.pageIndex,
|
|
206
|
+
rowsPerPage: pagination.pageSize,
|
|
207
|
+
onPageChange: handleChangePage,
|
|
208
|
+
onRowsPerPageChange: handleChangeRowsPerPage
|
|
209
|
+
})
|
|
210
|
+
}) : undefined,
|
|
211
|
+
itemContent: (index)=>{
|
|
212
|
+
const row = rows[index];
|
|
213
|
+
if (!row) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
217
|
+
children: row.getVisibleCells().map((cell, i, cells)=>{
|
|
218
|
+
const position = {
|
|
219
|
+
row: index + 1,
|
|
220
|
+
column: i
|
|
221
|
+
};
|
|
222
|
+
const cellContext = cell.getContext();
|
|
223
|
+
const cellConfig = cellConfigs?.[cellContext.cell.id];
|
|
224
|
+
const cellRenderFn = cell.column.columnDef.cell;
|
|
225
|
+
const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;
|
|
226
|
+
/*
|
|
203
227
|
IMPORTANT:
|
|
204
228
|
If Variables exist in the link, they should have been translated by the plugin already. (Being developed at the moment)
|
|
205
229
|
Components have no access to any context (Which is intentional and correct)
|
|
206
230
|
We may want to add parameters to a link from neighboring cells in the future as well.
|
|
207
231
|
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
232
|
*/ const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
233
|
+
let description = undefined;
|
|
234
|
+
if (typeof cellDescriptionDef === 'function') {
|
|
235
|
+
// If the cell description is a function, set the value using
|
|
236
|
+
// the function.
|
|
237
|
+
description = cellDescriptionDef(cellContext);
|
|
238
|
+
} else if (cellDescriptionDef && typeof cellContent === 'string') {
|
|
239
|
+
// If the cell description is `true` AND the cell content is
|
|
240
|
+
// a string (and thus viable as a `title` attribute), use the
|
|
241
|
+
// cell content.
|
|
242
|
+
description = cellContent;
|
|
243
|
+
}
|
|
244
|
+
/* this has been specifically added for the data link,
|
|
221
245
|
therefore, non string and numeric values should be excluded
|
|
222
246
|
*/ const adjacentCellsValuesMap = Object.entries(row.original)?.filter(([_, value])=>[
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
})
|
|
247
|
+
'string',
|
|
248
|
+
'number'
|
|
249
|
+
].includes(typeof value)).reduce((acc, [key, value])=>({
|
|
250
|
+
...acc,
|
|
251
|
+
[key]: String(value)
|
|
252
|
+
}), {});
|
|
253
|
+
return /*#__PURE__*/ _jsx(TableCell, {
|
|
254
|
+
"data-testid": cell.id,
|
|
255
|
+
title: description || cellConfig?.text || cellContent,
|
|
256
|
+
width: cell.column.getCanResize() ? `calc(var(--col-${cell.column.id}-size) * 1px)` : cell.column.getSize() || defaultColumnWidth,
|
|
257
|
+
defaultColumnHeight: defaultColumnHeight,
|
|
258
|
+
align: cell.column.columnDef.meta?.align,
|
|
259
|
+
density: density,
|
|
260
|
+
focusState: getFocusState(position),
|
|
261
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
262
|
+
isFirstColumn: i === 0,
|
|
263
|
+
isLastColumn: i === cells.length - 1,
|
|
264
|
+
description: description,
|
|
265
|
+
color: cellConfig?.textColor ?? undefined,
|
|
266
|
+
backgroundColor: cellConfig?.backgroundColor ?? undefined,
|
|
267
|
+
dataLink: cell.column.columnDef.meta?.dataLink,
|
|
268
|
+
adjacentCellsValuesMap: adjacentCellsValuesMap,
|
|
269
|
+
children: cellConfig?.text || cellContent
|
|
270
|
+
}, cell.id);
|
|
271
|
+
})
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
]
|
|
253
276
|
});
|
|
254
277
|
}
|
|
255
278
|
|
|
@@ -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, 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;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAiBA,UAAU,QAA0B,wBAAwB;AAC7E,SAASC,GAAG,EAAEC,eAAe,EAAEC,YAAYC,WAAW,QAAQ,gBAAgB;AAC9E,SAA0BC,aAAa,QAAiD,iBAAiB;AACzG,SAAuBC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACtD,SAASC,YAAY,QAA2B,iBAAiB;AACjE,SAASL,QAAQ,QAAQ,aAAa;AACtC,SAASM,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAwB,cAAc;AACxD,SAASC,yBAAyB,QAAQ,8BAA8B;AAExE,SAASC,8BAA8B,QAAQ,yCAAyC;AACxF,SAASC,SAAS,QAAQ,cAAc;AA4BxC,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,iBAA4B,EAC1CC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,kBAAkB,EAClBC,mBAAmB,EACnBC,UAAU,EACVC,cAAc,EACdC,aAAa,EACbC,IAAI,EACJC,OAAO,EACPC,OAA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nC8D,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
|
+
{"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, ColumnSizingInfoState, ColumnSizingState, 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' | 'defaultColumnHeight' | 'defaultColumnWidth'>\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 columnSizing: ColumnSizingState;\n columnSizingInfo: ColumnSizingInfoState;\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 | 'isExpandAllEnabled'\n | 'isAllExpanded'\n | 'onExpandAllChange'\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 columnSizing,\n columnSizingInfo,\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 /**\n * Instead of calling `column.getSize()` on every render for every header\n * and especially every data cell (very expensive),\n * we will calculate all column sizes at once at the root table level in a useMemo\n * and pass the column sizes down as CSS variables to the <table> element.\n */\n const columnSizeVars = useMemo(() => {\n const colSizes: { [key: string]: number } = {};\n headers.forEach((headerGroup) => {\n headerGroup.headers\n .filter((header) => header.column.getCanResize())\n .forEach((header) => {\n colSizes[`--header-${header.id}-size`] = header.getSize();\n colSizes[`--col-${header.column.id}-size`] = header.column.getSize();\n });\n });\n return colSizes;\n // We want to recalculate column sizes whenever column sizes or column resizing info changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [columnSizingInfo, columnSizing, headers]);\n\n return (\n <Box style={{ width, height, ...columnSizeVars }}>\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={\n header.column.getCanResize()\n ? `calc(var(--header-${header?.id}-size) * 1px)`\n : column.getSize() || defaultColumnWidth\n }\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 resizeConfig={\n header.column.getCanResize()\n ? {\n resizeHandler: header.getResizeHandler(),\n resetSizeHandler: header.column.resetSize,\n isResizing: header.column.getIsResizing(),\n }\n : undefined\n }\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={\n cell.column.getCanResize()\n ? `calc(var(--col-${cell.column.id}-size) * 1px)`\n : cell.column.getSize() || defaultColumnWidth\n }\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","useMemo","useRef","TableToolbar","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","TableFoot","VirtualizedTable","width","height","density","defaultColumnWidth","defaultColumnHeight","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","columnSizing","columnSizingInfo","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","columnSizeVars","colSizes","forEach","headerGroup","filter","header","getCanResize","getSize","style","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","resizeConfig","resizeHandler","getResizeHandler","resetSizeHandler","resetSize","isResizing","getIsResizing","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","_","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,SAA2DA,UAAU,QAA0B,wBAAwB;AACvH,SAASC,GAAG,EAAEC,eAAe,EAAEC,YAAYC,WAAW,QAAQ,gBAAgB;AAC9E,SAA0BC,aAAa,QAAiD,iBAAiB;AACzG,SAAuBC,OAAO,EAAEC,MAAM,QAAQ,QAAQ;AACtD,SAASC,YAAY,QAA2B,iBAAiB;AACjE,SAASL,QAAQ,QAAQ,aAAa;AACtC,SAASM,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAwB,cAAc;AACxD,SAASC,yBAAyB,QAAQ,8BAA8B;AAExE,SAASC,8BAA8B,QAAQ,yCAAyC;AACxF,SAASC,SAAS,QAAQ,cAAc;AAiCxC,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,iBAA4B,EAC1CC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,kBAAkB,EAClBC,mBAAmB,EACnBC,UAAU,EACVC,cAAc,EACdC,aAAa,EACbC,IAAI,EACJC,OAAO,EACPC,OAAO,EACPC,YAAY,EACZC,gBAAgB,EAChBC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC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apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
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
16
|
import { combineSx } from '../utils/combine-sx';
|
|
@@ -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';\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
|
|
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"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExpandedState, TableOptions } from '@tanstack/react-table';
|
|
2
|
+
import { SetStateAction } from 'react';
|
|
3
|
+
import { FuzzyMatchThreshold } from '@perses-dev/components';
|
|
2
4
|
export interface UseFuzzySearchResult<TableData> {
|
|
3
5
|
globalFilter: string;
|
|
4
|
-
setGlobalFilter:
|
|
6
|
+
setGlobalFilter: (value: string) => void;
|
|
5
7
|
fuzzySearchOptions: Pick<TableOptions<TableData>, 'filterFns' | 'globalFilterFn' | 'getFilteredRowModel' | 'filterFromLeafRows' | 'onGlobalFilterChange'>;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Returns fuzzy search state and the corresponding `useReactTable` options.
|
|
9
11
|
* Filter options are disabled when `showSearch` is falsy.
|
|
10
12
|
*/
|
|
11
|
-
export declare function useFuzzySearch<TableData>(isSearchEnabled: boolean | undefined): UseFuzzySearchResult<TableData>;
|
|
13
|
+
export declare function useFuzzySearch<TableData>(isSearchEnabled: boolean | undefined, threshold: FuzzyMatchThreshold, expanded: ExpandedState, setExpanded: (value: SetStateAction<ExpandedState>) => void): UseFuzzySearchResult<TableData>;
|
|
12
14
|
//# sourceMappingURL=useFuzzySearch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFuzzySearch.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"useFuzzySearch.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAiC,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEnG,OAAO,EAAE,cAAc,EAAyB,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAU7D,MAAM,WAAW,oBAAoB,CAAC,SAAS;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,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,EACtC,eAAe,EAAE,OAAO,GAAG,SAAS,EACpC,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,aAAa,CAAC,KAAK,IAAI,GAC1D,oBAAoB,CAAC,SAAS,CAAC,CA8BjC"}
|
|
@@ -11,31 +11,50 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { getFilteredRowModel } from '@tanstack/react-table';
|
|
14
|
-
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
15
|
-
import { useState } from 'react';
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
14
|
+
import { rankings, rankItem } from '@tanstack/match-sorter-utils';
|
|
15
|
+
import { useCallback, useState } from 'react';
|
|
16
|
+
const getFuzzyFilterFunction = (threshold)=>(row, columnId, value, addMeta)=>{
|
|
17
|
+
const itemRank = rankItem(row.getValue(columnId), value, {
|
|
18
|
+
threshold: rankings[threshold]
|
|
19
|
+
});
|
|
20
|
+
addMeta({
|
|
21
|
+
itemRank
|
|
22
|
+
});
|
|
23
|
+
return itemRank.passed;
|
|
24
|
+
};
|
|
23
25
|
/**
|
|
24
26
|
* Returns fuzzy search state and the corresponding `useReactTable` options.
|
|
25
27
|
* Filter options are disabled when `showSearch` is falsy.
|
|
26
|
-
*/ export function useFuzzySearch(isSearchEnabled) {
|
|
28
|
+
*/ export function useFuzzySearch(isSearchEnabled, threshold, expanded, setExpanded) {
|
|
27
29
|
const [globalFilter, setGlobalFilter] = useState('');
|
|
30
|
+
const [prevExpandedState, setPrevExpandedState] = useState(expanded);
|
|
31
|
+
// expand all rows when a search query is entered, and restore previous expansion state when the query is cleared
|
|
32
|
+
const handleGlobalFilterChange = useCallback((value)=>{
|
|
33
|
+
setGlobalFilter((prev)=>{
|
|
34
|
+
if (!prev) {
|
|
35
|
+
setPrevExpandedState(expanded);
|
|
36
|
+
setExpanded(true);
|
|
37
|
+
} else if (prev && !value) {
|
|
38
|
+
setExpanded(prevExpandedState);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
});
|
|
42
|
+
}, [
|
|
43
|
+
expanded,
|
|
44
|
+
prevExpandedState,
|
|
45
|
+
setExpanded
|
|
46
|
+
]);
|
|
28
47
|
return {
|
|
29
48
|
globalFilter,
|
|
30
|
-
setGlobalFilter,
|
|
49
|
+
setGlobalFilter: handleGlobalFilterChange,
|
|
31
50
|
fuzzySearchOptions: {
|
|
32
51
|
filterFns: {
|
|
33
|
-
fuzzy:
|
|
52
|
+
fuzzy: getFuzzyFilterFunction(threshold)
|
|
34
53
|
},
|
|
35
54
|
globalFilterFn: isSearchEnabled ? 'fuzzy' : undefined,
|
|
36
55
|
getFilteredRowModel: isSearchEnabled ? getFilteredRowModel() : undefined,
|
|
37
56
|
filterFromLeafRows: isSearchEnabled,
|
|
38
|
-
onGlobalFilterChange:
|
|
57
|
+
onGlobalFilterChange: handleGlobalFilterChange
|
|
39
58
|
}
|
|
40
59
|
};
|
|
41
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"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 { FilterFn, getFilteredRowModel,
|
|
1
|
+
{"version":3,"sources":["../../../src/Table/hooks/useFuzzySearch.ts"],"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 { ExpandedState, FilterFn, getFilteredRowModel, TableOptions } from '@tanstack/react-table';\nimport { rankings, rankItem } from '@tanstack/match-sorter-utils';\nimport { SetStateAction, useCallback, useState } from 'react';\nimport { FuzzyMatchThreshold } from '@perses-dev/components';\n\nconst getFuzzyFilterFunction =\n (threshold: FuzzyMatchThreshold): FilterFn<unknown> =>\n (row, columnId, value, addMeta) => {\n const itemRank = rankItem(row.getValue(columnId), value, { threshold: rankings[threshold] });\n addMeta({ itemRank });\n return itemRank.passed;\n };\n\nexport interface UseFuzzySearchResult<TableData> {\n globalFilter: string;\n setGlobalFilter: (value: string) => void;\n fuzzySearchOptions: Pick<\n TableOptions<TableData>,\n 'filterFns' | 'globalFilterFn' | 'getFilteredRowModel' | 'filterFromLeafRows' | 'onGlobalFilterChange'\n >;\n}\n\n/**\n * Returns fuzzy search state and the corresponding `useReactTable` options.\n * Filter options are disabled when `showSearch` is falsy.\n */\nexport function useFuzzySearch<TableData>(\n isSearchEnabled: boolean | undefined,\n threshold: FuzzyMatchThreshold,\n expanded: ExpandedState,\n setExpanded: (value: SetStateAction<ExpandedState>) => void\n): UseFuzzySearchResult<TableData> {\n const [globalFilter, setGlobalFilter] = useState('');\n const [prevExpandedState, setPrevExpandedState] = useState<ExpandedState>(expanded);\n\n // expand all rows when a search query is entered, and restore previous expansion state when the query is cleared\n const handleGlobalFilterChange = useCallback(\n (value: string): void => {\n setGlobalFilter((prev) => {\n if (!prev) {\n setPrevExpandedState(expanded);\n setExpanded(true);\n } else if (prev && !value) {\n setExpanded(prevExpandedState);\n }\n return value;\n });\n },\n [expanded, prevExpandedState, setExpanded]\n );\n return {\n globalFilter,\n setGlobalFilter: handleGlobalFilterChange,\n fuzzySearchOptions: {\n filterFns: { fuzzy: getFuzzyFilterFunction(threshold) },\n globalFilterFn: isSearchEnabled ? 'fuzzy' : undefined,\n getFilteredRowModel: isSearchEnabled ? getFilteredRowModel() : undefined,\n filterFromLeafRows: isSearchEnabled,\n onGlobalFilterChange: handleGlobalFilterChange,\n },\n };\n}\n"],"names":["getFilteredRowModel","rankings","rankItem","useCallback","useState","getFuzzyFilterFunction","threshold","row","columnId","value","addMeta","itemRank","getValue","passed","useFuzzySearch","isSearchEnabled","expanded","setExpanded","globalFilter","setGlobalFilter","prevExpandedState","setPrevExpandedState","handleGlobalFilterChange","prev","fuzzySearchOptions","filterFns","fuzzy","globalFilterFn","undefined","filterFromLeafRows","onGlobalFilterChange"],"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,SAAkCA,mBAAmB,QAAsB,wBAAwB;AACnG,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,+BAA+B;AAClE,SAAyBC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAG9D,MAAMC,yBACJ,CAACC,YACD,CAACC,KAAKC,UAAUC,OAAOC;QACrB,MAAMC,WAAWT,SAASK,IAAIK,QAAQ,CAACJ,WAAWC,OAAO;YAAEH,WAAWL,QA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