@mhjuma/traverse 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +46 -0
- package/src/bootstrap.spec.tsx +290 -0
- package/src/bootstrap.tsx +195 -0
- package/src/colors.ts +23 -0
- package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
- package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
- package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
- package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
- package/src/components/ChartPanel/ChartPanel.tsx +151 -0
- package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
- package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
- package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
- package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
- package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
- package/src/components/Explorer/Explorer.spec.tsx +615 -0
- package/src/components/Explorer/Explorer.tsx +49 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
- package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
- package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
- package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
- package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
- package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
- package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
- package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
- package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
- package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
- package/src/components/ResultsPanel/TabButton.tsx +11 -0
- package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
- package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
- package/src/components/ResultsTable/FilterCell.tsx +24 -0
- package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
- package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
- package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
- package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
- package/src/components/ResultsTable/ResultsTable.tsx +501 -0
- package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
- package/src/components/ResultsTable/VirtualCell.tsx +32 -0
- package/src/components/ResultsTable/VirtualRow.tsx +55 -0
- package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
- package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
- package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
- package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
- package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
- package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
- package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
- package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
- package/src/components/TabBar/TabBar.logic.ts +35 -0
- package/src/components/TabBar/TabBar.spec.tsx +929 -0
- package/src/components/TabBar/TabBar.tsx +284 -0
- package/src/components/TabBar/TabItem.tsx +166 -0
- package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
- package/src/components/VegaChart/VegaChart.tsx +224 -0
- package/src/config.spec.ts +44 -0
- package/src/config.ts +47 -0
- package/src/context/ExplorerColorContext.ts +14 -0
- package/src/context/ExplorerStateContext.ts +49 -0
- package/src/context/KustoClientContext.ts +12 -0
- package/src/context/context.spec.tsx +183 -0
- package/src/index.ts +14 -0
- package/src/services/cache.spec.ts +31 -0
- package/src/services/cache.ts +16 -0
- package/src/services/concurrency.spec.ts +139 -0
- package/src/services/concurrency.ts +46 -0
- package/src/services/kusto.spec.ts +919 -0
- package/src/services/kusto.ts +472 -0
- package/src/services/queryHistory.spec.ts +287 -0
- package/src/services/queryHistory.ts +146 -0
- package/src/services/schema.spec.ts +618 -0
- package/src/services/schema.ts +294 -0
- package/src/services/state-service.spec.ts +670 -0
- package/src/services/state-service.ts +602 -0
- package/src/services/useKustoQuery.spec.ts +234 -0
- package/src/services/useKustoQuery.ts +124 -0
- package/src/state/actions.ts +50 -0
- package/src/state/index.ts +3 -0
- package/src/state/reducer.spec.ts +644 -0
- package/src/state/reducer.ts +207 -0
- package/src/state/types.ts +54 -0
- package/tsconfig.json +7 -0
- package/tsconfig.lint.json +4 -0
- package/tsconfig.spec.json +7 -0
- package/vitest.config.ts +34 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { makeStyles, tokens } from '@fluentui/react-components';
|
|
2
|
+
|
|
3
|
+
const EXPAND_COL_WIDTH = 24;
|
|
4
|
+
|
|
5
|
+
export const useStyles = makeStyles({
|
|
6
|
+
container: { display: 'flex', flexDirection: 'column', flex: 1, minHeight: 0, overflow: 'hidden' },
|
|
7
|
+
toolbar: { display: 'flex', alignItems: 'center', gap: '6px', padding: '4px 8px', borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, backgroundColor: tokens.colorNeutralBackground2, flexShrink: 0 },
|
|
8
|
+
searchInput: { maxWidth: '280px', fontSize: '11px' },
|
|
9
|
+
highlightInput: { maxWidth: '250px', fontSize: '11px' },
|
|
10
|
+
bodyArea: { display: 'flex', flex: 1, minHeight: 0, overflow: 'hidden' },
|
|
11
|
+
scrollContainer: { flex: 1, minHeight: 0 },
|
|
12
|
+
thead: { position: 'sticky' as const, top: 0, zIndex: 2 },
|
|
13
|
+
thRow: { display: 'flex' },
|
|
14
|
+
th: {
|
|
15
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '4px 8px',
|
|
16
|
+
backgroundColor: tokens.colorNeutralBackground3, borderBottom: `1px solid ${tokens.colorNeutralStroke1}`,
|
|
17
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke2}`, borderTop: 'none', borderLeft: 'none',
|
|
18
|
+
color: tokens.colorNeutralForeground2, outline: 'none',
|
|
19
|
+
fontWeight: '600', fontSize: '11px', cursor: 'pointer', userSelect: 'none' as const,
|
|
20
|
+
whiteSpace: 'nowrap' as const, boxSizing: 'border-box' as const, flexShrink: 0,
|
|
21
|
+
'&:hover': { backgroundColor: tokens.colorNeutralBackground4 },
|
|
22
|
+
},
|
|
23
|
+
thExpand: {
|
|
24
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
25
|
+
width: `${EXPAND_COL_WIDTH}px`, minWidth: `${EXPAND_COL_WIDTH}px`, maxWidth: `${EXPAND_COL_WIDTH}px`,
|
|
26
|
+
padding: '4px 0', backgroundColor: tokens.colorNeutralBackground3,
|
|
27
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke1}`, borderRight: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
28
|
+
boxSizing: 'border-box' as const, flexShrink: 0,
|
|
29
|
+
},
|
|
30
|
+
thLabel: { display: 'flex', alignItems: 'center', gap: '4px', overflow: 'hidden' },
|
|
31
|
+
thName: { overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
32
|
+
filterRow: { display: 'flex' },
|
|
33
|
+
filterCell: {
|
|
34
|
+
padding: '2px 4px', backgroundColor: tokens.colorNeutralBackground3,
|
|
35
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke1}`, borderRight: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
36
|
+
boxSizing: 'border-box' as const, flexShrink: 0,
|
|
37
|
+
},
|
|
38
|
+
filterInput: { width: '100%', fontSize: '10px' },
|
|
39
|
+
tr: { display: 'flex', '&:hover': { backgroundColor: tokens.colorNeutralBackground2 } },
|
|
40
|
+
trDetailOpen: { display: 'flex', backgroundColor: 'rgba(0, 120, 212, 0.06)' },
|
|
41
|
+
trExprHighlight: { display: 'flex', backgroundColor: 'rgba(255, 200, 0, 0.12)', '&:hover': { backgroundColor: 'rgba(255, 200, 0, 0.2)' } },
|
|
42
|
+
td: {
|
|
43
|
+
padding: '3px 8px', borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
44
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke2}`, color: tokens.colorNeutralForeground1,
|
|
45
|
+
whiteSpace: 'nowrap' as const, overflow: 'hidden', textOverflow: 'ellipsis',
|
|
46
|
+
boxSizing: 'border-box' as const, flexShrink: 0, cursor: 'default',
|
|
47
|
+
userSelect: 'none' as const, fontFamily: 'Consolas, Monaco, monospace', fontSize: '12px',
|
|
48
|
+
},
|
|
49
|
+
tdSelected: {
|
|
50
|
+
padding: '3px 8px', borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
51
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke2}`, color: tokens.colorNeutralForeground1,
|
|
52
|
+
whiteSpace: 'nowrap' as const, overflow: 'hidden', textOverflow: 'ellipsis',
|
|
53
|
+
boxSizing: 'border-box' as const, flexShrink: 0, cursor: 'default',
|
|
54
|
+
userSelect: 'none' as const, fontFamily: 'Consolas, Monaco, monospace', fontSize: '12px',
|
|
55
|
+
backgroundColor: 'rgba(0, 120, 212, 0.15)',
|
|
56
|
+
},
|
|
57
|
+
expandBtn: {
|
|
58
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
59
|
+
width: `${EXPAND_COL_WIDTH}px`, minWidth: `${EXPAND_COL_WIDTH}px`, maxWidth: `${EXPAND_COL_WIDTH}px`,
|
|
60
|
+
padding: '0', borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
61
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke2}`, boxSizing: 'border-box' as const,
|
|
62
|
+
borderTop: 'none', borderLeft: 'none', backgroundColor: 'transparent', outline: 'none',
|
|
63
|
+
flexShrink: 0, cursor: 'pointer', color: tokens.colorNeutralForeground3,
|
|
64
|
+
'&:hover': { color: tokens.colorBrandForeground1 },
|
|
65
|
+
},
|
|
66
|
+
colPickerList: { display: 'flex', flexDirection: 'column', gap: '2px', maxHeight: '300px', overflow: 'auto', padding: '4px', minWidth: '180px' },
|
|
67
|
+
colPickerActions: { display: 'flex', gap: '4px', padding: '4px 4px 0', borderTop: `1px solid ${tokens.colorNeutralStroke2}`, marginTop: '4px' },
|
|
68
|
+
activeFilter: { color: tokens.colorBrandForeground1 },
|
|
69
|
+
sortIcon: { fontSize: '10px', flexShrink: 0 },
|
|
70
|
+
statusBar: {
|
|
71
|
+
display: 'flex', alignItems: 'center', gap: '12px', padding: '2px 8px',
|
|
72
|
+
borderTop: `1px solid ${tokens.colorNeutralStroke2}`, backgroundColor: tokens.colorNeutralBackground2,
|
|
73
|
+
fontSize: '10px', color: tokens.colorNeutralForeground3, flexShrink: 0, flexWrap: 'wrap' as const,
|
|
74
|
+
},
|
|
75
|
+
statusLeft: { display: 'flex', gap: '12px', alignItems: 'center' },
|
|
76
|
+
statusRight: { display: 'flex', gap: '12px', alignItems: 'center', marginLeft: 'auto' },
|
|
77
|
+
statHighlight: { color: tokens.colorBrandForeground1, fontWeight: '600' },
|
|
78
|
+
detailPanel: {
|
|
79
|
+
display: 'flex', flexDirection: 'column', overflow: 'hidden',
|
|
80
|
+
borderLeft: `1px solid ${tokens.colorNeutralStroke1}`, backgroundColor: tokens.colorNeutralBackground2,
|
|
81
|
+
},
|
|
82
|
+
detailDragHandle: {
|
|
83
|
+
width: '4px', cursor: 'col-resize', backgroundColor: tokens.colorNeutralStroke1, flexShrink: 0,
|
|
84
|
+
'&:hover': { width: '6px', backgroundColor: tokens.colorBrandBackground },
|
|
85
|
+
},
|
|
86
|
+
detailHeader: {
|
|
87
|
+
display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '6px 10px',
|
|
88
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, fontWeight: '600', fontSize: '11px',
|
|
89
|
+
color: tokens.colorNeutralForeground2, flexShrink: 0, gap: '4px',
|
|
90
|
+
},
|
|
91
|
+
detailHeaderLeft: { display: 'flex', alignItems: 'center', gap: '4px' },
|
|
92
|
+
detailBody: { flex: 1, overflow: 'auto', padding: '4px 0' },
|
|
93
|
+
detailRow: {
|
|
94
|
+
display: 'flex', padding: '3px 10px', fontSize: '11px', fontFamily: 'Consolas, Monaco, monospace',
|
|
95
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, gap: '8px',
|
|
96
|
+
'&:hover': { backgroundColor: tokens.colorNeutralBackground3 },
|
|
97
|
+
},
|
|
98
|
+
detailKey: { width: '140px', minWidth: '140px', flexShrink: 0, color: tokens.colorNeutralForeground3, fontWeight: '600', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' as const, borderRight: `1px solid ${tokens.colorNeutralStroke2}`, paddingRight: '8px' },
|
|
99
|
+
detailValue: { flex: 1, color: tokens.colorNeutralForeground1, wordBreak: 'break-all' as const, whiteSpace: 'pre-wrap' as const, minWidth: 0 },
|
|
100
|
+
detailListRow: {
|
|
101
|
+
display: 'flex', flexDirection: 'column', padding: '4px 10px', fontSize: '11px', fontFamily: 'Consolas, Monaco, monospace',
|
|
102
|
+
borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, gap: '1px',
|
|
103
|
+
'&:hover': { backgroundColor: tokens.colorNeutralBackground3 },
|
|
104
|
+
},
|
|
105
|
+
detailListKey: { color: tokens.colorNeutralForeground3, fontWeight: '600', fontSize: '10px' },
|
|
106
|
+
detailListValue: { color: tokens.colorNeutralForeground1, wordBreak: 'break-all' as const, whiteSpace: 'pre-wrap' as const },
|
|
107
|
+
detailMonaco: { flex: 1, minHeight: 0 },
|
|
108
|
+
});
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Input,
|
|
3
|
+
Button,
|
|
4
|
+
Tooltip,
|
|
5
|
+
Popover,
|
|
6
|
+
PopoverTrigger,
|
|
7
|
+
PopoverSurface,
|
|
8
|
+
} from '@fluentui/react-components';
|
|
9
|
+
import {
|
|
10
|
+
SearchRegular,
|
|
11
|
+
ColumnTripleRegular,
|
|
12
|
+
EyeOffRegular,
|
|
13
|
+
FilterRegular,
|
|
14
|
+
DismissRegular,
|
|
15
|
+
DismissCircleRegular,
|
|
16
|
+
HighlightRegular,
|
|
17
|
+
CodeRegular,
|
|
18
|
+
TableSimpleRegular,
|
|
19
|
+
TextBulletListRegular,
|
|
20
|
+
} from '@fluentui/react-icons';
|
|
21
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
22
|
+
import { useState, useMemo, useCallback, useRef, useEffect, lazy, Suspense } from 'react';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
parseHighlightExpr,
|
|
26
|
+
matchesHighlight,
|
|
27
|
+
computeAggregates,
|
|
28
|
+
computeDateDelta,
|
|
29
|
+
computeColumnWidths,
|
|
30
|
+
sortRows,
|
|
31
|
+
filterRows,
|
|
32
|
+
findEmptyColumns,
|
|
33
|
+
buildSelectionTsv,
|
|
34
|
+
} from './ResultsTable.logic';
|
|
35
|
+
import type { SortDir, CellRange } from './ResultsTable.logic';
|
|
36
|
+
import { useStyles } from './ResultsTable.styles';
|
|
37
|
+
import { useExplorerColors } from '../../context/ExplorerColorContext';
|
|
38
|
+
import { ColumnHeader } from './ColumnHeader';
|
|
39
|
+
import { FilterCell } from './FilterCell';
|
|
40
|
+
import { VirtualRow } from './VirtualRow';
|
|
41
|
+
import { ColumnPickerItem } from './ColumnPickerItem';
|
|
42
|
+
|
|
43
|
+
// Lazy-load Monaco — only used in JSON detail view
|
|
44
|
+
const Editor = lazy(() => import('@monaco-editor/react'));
|
|
45
|
+
|
|
46
|
+
const ROW_HEIGHT = 28;
|
|
47
|
+
const EXPAND_COL_WIDTH = 24;
|
|
48
|
+
const MIN_DETAIL_WIDTH = 200;
|
|
49
|
+
const MAX_DETAIL_WIDTH = 800;
|
|
50
|
+
|
|
51
|
+
// --- Styles ---
|
|
52
|
+
|
|
53
|
+
// --- Module-level constants ---
|
|
54
|
+
|
|
55
|
+
const searchIcon = <SearchRegular fontSize={14} />;
|
|
56
|
+
const dismissSmallIcon = <DismissRegular fontSize={12} />;
|
|
57
|
+
const filterIcon = <FilterRegular />;
|
|
58
|
+
const eyeOffIcon = <EyeOffRegular />;
|
|
59
|
+
const columnTripleIcon = <ColumnTripleRegular />;
|
|
60
|
+
const highlightIcon = <HighlightRegular fontSize={14} />;
|
|
61
|
+
const dismissCircleIcon = <DismissCircleRegular />;
|
|
62
|
+
const tableSimpleIcon = <TableSimpleRegular />;
|
|
63
|
+
const textBulletListIcon = <TextBulletListRegular />;
|
|
64
|
+
const codeIcon = <CodeRegular />;
|
|
65
|
+
|
|
66
|
+
const flexOneStyle = { flex: 1 };
|
|
67
|
+
const minWidthAutoStyle = { minWidth: 'auto' };
|
|
68
|
+
const minWidthAutoPaddingZeroStyle = { minWidth: 'auto', padding: 0 };
|
|
69
|
+
const overflowAutoStyle = { overflow: 'auto' };
|
|
70
|
+
const fullHeightStyle = { height: '100%' };
|
|
71
|
+
const expandColPlaceholderStyle = { width: EXPAND_COL_WIDTH, minWidth: EXPAND_COL_WIDTH, flexShrink: 0 };
|
|
72
|
+
|
|
73
|
+
const monacoOptions = {
|
|
74
|
+
readOnly: true,
|
|
75
|
+
minimap: { enabled: false },
|
|
76
|
+
lineNumbers: 'off' as const,
|
|
77
|
+
scrollBeyondLastLine: false,
|
|
78
|
+
folding: true,
|
|
79
|
+
fontSize: 12,
|
|
80
|
+
wordWrap: 'on' as const,
|
|
81
|
+
padding: { top: 8, bottom: 8 },
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const monacoFallback = <div style={fullHeightStyle} />;
|
|
85
|
+
|
|
86
|
+
interface Props {
|
|
87
|
+
columns: string[];
|
|
88
|
+
rows: Record<string, unknown>[];
|
|
89
|
+
headerLeft?: React.ReactNode;
|
|
90
|
+
headerRight?: React.ReactNode;
|
|
91
|
+
isDark?: boolean;
|
|
92
|
+
columnTypes?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function ResultsTable({ columns, rows, headerLeft, headerRight, isDark, columnTypes }: Props) {
|
|
96
|
+
const styles = useStyles();
|
|
97
|
+
const { semantic } = useExplorerColors();
|
|
98
|
+
const scrollRef = useRef<HTMLDivElement>(null);
|
|
99
|
+
const isDraggingCells = useRef(false);
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const id = 'traverse-scrollbar-style';
|
|
103
|
+
if (!document.getElementById(id)) {
|
|
104
|
+
const style = document.createElement('style');
|
|
105
|
+
style.id = id;
|
|
106
|
+
style.textContent = `
|
|
107
|
+
.traverse-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
108
|
+
.traverse-scroll::-webkit-scrollbar-track { background: transparent; }
|
|
109
|
+
.traverse-scroll::-webkit-scrollbar-thumb { background: ${semantic.scrollThumb}; border-radius: 4px; }
|
|
110
|
+
.traverse-scroll::-webkit-scrollbar-thumb:hover { background: ${semantic.scrollThumbHover}; }
|
|
111
|
+
`;
|
|
112
|
+
document.head.appendChild(style);
|
|
113
|
+
}
|
|
114
|
+
}, [semantic.scrollThumb, semantic.scrollThumbHover]);
|
|
115
|
+
|
|
116
|
+
// --- State ---
|
|
117
|
+
const [globalSearch, setGlobalSearch] = useState('');
|
|
118
|
+
const [columnFilters, setColumnFilters] = useState<Record<string, string>>({});
|
|
119
|
+
const [sortColumn, setSortColumn] = useState<string | null>(null);
|
|
120
|
+
const [sortDir, setSortDir] = useState<SortDir>(null);
|
|
121
|
+
const [hiddenColumns, setHiddenColumns] = useState<Set<string>>(new Set());
|
|
122
|
+
const [hideEmpty, setHideEmpty] = useState(false);
|
|
123
|
+
const [showFilters, setShowFilters] = useState(false);
|
|
124
|
+
const [selection, setSelection] = useState<CellRange | null>(null);
|
|
125
|
+
const [detailRowIdx, setDetailRowIdx] = useState<number | null>(null);
|
|
126
|
+
const [detailWidth, setDetailWidth] = useState(320);
|
|
127
|
+
const [detailMode, setDetailMode] = useState<'table' | 'list' | 'json'>('table');
|
|
128
|
+
const [highlightExpr, setHighlightExpr] = useState('');
|
|
129
|
+
const previousDatasetRef = useRef<{ columns: string[]; rows: Record<string, unknown>[] } | null>(null);
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!previousDatasetRef.current) {
|
|
133
|
+
previousDatasetRef.current = { columns, rows };
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (previousDatasetRef.current.columns === columns && previousDatasetRef.current.rows === rows) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
previousDatasetRef.current = { columns, rows };
|
|
140
|
+
setGlobalSearch('');
|
|
141
|
+
setColumnFilters({});
|
|
142
|
+
setSortColumn(null);
|
|
143
|
+
setSortDir(null);
|
|
144
|
+
setHiddenColumns(new Set());
|
|
145
|
+
setHideEmpty(false);
|
|
146
|
+
setShowFilters(false);
|
|
147
|
+
setSelection(null);
|
|
148
|
+
setDetailRowIdx(null);
|
|
149
|
+
setHighlightExpr('');
|
|
150
|
+
scrollRef.current?.scrollTo({ top: 0 });
|
|
151
|
+
}, [columns, rows]);
|
|
152
|
+
|
|
153
|
+
// --- Derived data ---
|
|
154
|
+
const emptyColumns = useMemo(() => findEmptyColumns(columns, rows), [columns, rows]);
|
|
155
|
+
|
|
156
|
+
const visibleColumns = useMemo(() =>
|
|
157
|
+
columns.filter((c) => !hiddenColumns.has(c) && !(hideEmpty && emptyColumns.has(c))),
|
|
158
|
+
[columns, hiddenColumns, hideEmpty, emptyColumns]);
|
|
159
|
+
|
|
160
|
+
const columnWidths = useMemo(() => {
|
|
161
|
+
const widthArr = computeColumnWidths(visibleColumns, rows, columnTypes);
|
|
162
|
+
const widths: Record<string, number> = {};
|
|
163
|
+
visibleColumns.forEach((col, i) => { widths[col] = widthArr[i]; });
|
|
164
|
+
return widths;
|
|
165
|
+
}, [visibleColumns, rows, columnTypes]);
|
|
166
|
+
|
|
167
|
+
const filteredRows = useMemo(
|
|
168
|
+
() => filterRows(rows, visibleColumns, globalSearch, columnFilters),
|
|
169
|
+
[rows, globalSearch, columnFilters, visibleColumns],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const sortedRows = useMemo(
|
|
173
|
+
() => sortRows(filteredRows, sortColumn, sortDir),
|
|
174
|
+
[filteredRows, sortColumn, sortDir],
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const parsedHighlight = useMemo(() => parseHighlightExpr(highlightExpr), [highlightExpr]);
|
|
178
|
+
|
|
179
|
+
// --- Selection aggregates ---
|
|
180
|
+
const selectionStats = useMemo((): { cells: number; aggs: Record<string, string>; dateDelta: string | null } | null => {
|
|
181
|
+
if (!selection) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
const minRow = Math.min(selection.startRow, selection.endRow);
|
|
185
|
+
const maxRow = Math.max(selection.startRow, selection.endRow);
|
|
186
|
+
const minCol = Math.min(selection.startCol, selection.endCol);
|
|
187
|
+
const maxCol = Math.max(selection.startCol, selection.endCol);
|
|
188
|
+
const cellCount = (maxRow - minRow + 1) * (maxCol - minCol + 1);
|
|
189
|
+
if (cellCount < 2) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const nums: number[] = [];
|
|
193
|
+
const dateStrs: string[] = [];
|
|
194
|
+
for (let r = minRow; r <= maxRow && r < sortedRows.length; r++) {
|
|
195
|
+
for (let c = minCol; c <= maxCol && c < visibleColumns.length; c++) {
|
|
196
|
+
const v = sortedRows[r][visibleColumns[c]];
|
|
197
|
+
if (v === null || v === undefined || v === '') {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const n = Number(v);
|
|
201
|
+
if (!isNaN(n)) {
|
|
202
|
+
nums.push(n);
|
|
203
|
+
}
|
|
204
|
+
const s = String(v as string | number);
|
|
205
|
+
if (s.match(/^\d{4}-\d{2}-\d{2}/) && !isNaN(new Date(s).getTime())) {
|
|
206
|
+
dateStrs.push(s);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return { cells: cellCount, aggs: computeAggregates(nums), dateDelta: computeDateDelta(dateStrs) };
|
|
211
|
+
}, [selection, sortedRows, visibleColumns]);
|
|
212
|
+
|
|
213
|
+
const detailData = useMemo(() => {
|
|
214
|
+
if (detailRowIdx === null || detailRowIdx >= sortedRows.length) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return sortedRows[detailRowIdx];
|
|
218
|
+
}, [detailRowIdx, sortedRows]);
|
|
219
|
+
|
|
220
|
+
const detailJson = useMemo(() => {
|
|
221
|
+
if (!detailData) {
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
return JSON.stringify(detailData, null, 2);
|
|
225
|
+
}, [detailData]);
|
|
226
|
+
|
|
227
|
+
const virtualizer = useVirtualizer({
|
|
228
|
+
count: sortedRows.length,
|
|
229
|
+
getScrollElement: () => scrollRef.current,
|
|
230
|
+
estimateSize: () => ROW_HEIGHT,
|
|
231
|
+
overscan: 20,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// --- Handlers ---
|
|
235
|
+
const toggleSort = useCallback((col: string) => {
|
|
236
|
+
setSortColumn((prev) => {
|
|
237
|
+
if (prev !== col) { setSortDir('asc'); return col; }
|
|
238
|
+
setSortDir((d) => d === 'asc' ? 'desc' : d === 'desc' ? null : 'asc');
|
|
239
|
+
return prev;
|
|
240
|
+
});
|
|
241
|
+
}, []);
|
|
242
|
+
|
|
243
|
+
const setFilter = useCallback((col: string, value: string) => {
|
|
244
|
+
setColumnFilters((prev) => ({ ...prev, [col]: value }));
|
|
245
|
+
}, []);
|
|
246
|
+
|
|
247
|
+
const toggleColumn = useCallback((col: string) => {
|
|
248
|
+
setHiddenColumns((prev) => { const next = new Set(prev); if (next.has(col)) next.delete(col); else next.add(col); return next; });
|
|
249
|
+
}, []);
|
|
250
|
+
|
|
251
|
+
const handleCellMouseDown = useCallback((rowIdx: number, colIdx: number, e: React.MouseEvent) => {
|
|
252
|
+
scrollRef.current?.focus();
|
|
253
|
+
if (e.shiftKey && selection) {
|
|
254
|
+
setSelection({ startRow: selection.startRow, startCol: selection.startCol, endRow: rowIdx, endCol: colIdx });
|
|
255
|
+
} else {
|
|
256
|
+
setSelection({ startRow: rowIdx, startCol: colIdx, endRow: rowIdx, endCol: colIdx });
|
|
257
|
+
isDraggingCells.current = true;
|
|
258
|
+
}
|
|
259
|
+
}, [selection]);
|
|
260
|
+
|
|
261
|
+
const handleCellMouseEnter = useCallback((rowIdx: number, colIdx: number) => {
|
|
262
|
+
if (!isDraggingCells.current || !selection) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
setSelection((prev) => prev ? { ...prev, endRow: rowIdx, endCol: colIdx } : null);
|
|
266
|
+
}, [selection]);
|
|
267
|
+
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
const onUp = () => { isDraggingCells.current = false; };
|
|
270
|
+
document.addEventListener('mouseup', onUp);
|
|
271
|
+
return () => document.removeEventListener('mouseup', onUp);
|
|
272
|
+
}, []);
|
|
273
|
+
|
|
274
|
+
const handleHeaderColClick = useCallback((colIdx: number) => {
|
|
275
|
+
scrollRef.current?.focus();
|
|
276
|
+
setSelection({ startRow: 0, startCol: colIdx, endRow: sortedRows.length - 1, endCol: colIdx });
|
|
277
|
+
}, [sortedRows.length]);
|
|
278
|
+
|
|
279
|
+
const handleCopy = useCallback((e: React.ClipboardEvent<HTMLDivElement>) => {
|
|
280
|
+
const selectionText = buildSelectionTsv(sortedRows, visibleColumns, selection);
|
|
281
|
+
if (!selectionText) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
e.preventDefault();
|
|
285
|
+
e.clipboardData.setData('text/plain', selectionText);
|
|
286
|
+
}, [selection, sortedRows, visibleColumns]);
|
|
287
|
+
|
|
288
|
+
// Detail panel resize
|
|
289
|
+
const onDetailDragStart = useCallback((e: React.MouseEvent) => {
|
|
290
|
+
e.preventDefault();
|
|
291
|
+
const startX = e.clientX;
|
|
292
|
+
const startWidth = detailWidth;
|
|
293
|
+
const onMove = (ev: MouseEvent) => {
|
|
294
|
+
const delta = startX - ev.clientX;
|
|
295
|
+
setDetailWidth(Math.max(MIN_DETAIL_WIDTH, Math.min(MAX_DETAIL_WIDTH, startWidth + delta)));
|
|
296
|
+
};
|
|
297
|
+
const onUp = () => { document.removeEventListener('mousemove', onMove); document.removeEventListener('mouseup', onUp); };
|
|
298
|
+
document.addEventListener('mousemove', onMove);
|
|
299
|
+
document.addEventListener('mouseup', onUp);
|
|
300
|
+
}, [detailWidth]);
|
|
301
|
+
|
|
302
|
+
// --- Toolbar handlers ---
|
|
303
|
+
const handleGlobalSearchChange = useCallback((_: unknown, d: { value: string }) => setGlobalSearch(d.value), []);
|
|
304
|
+
const clearGlobalSearch = useCallback(() => setGlobalSearch(''), []);
|
|
305
|
+
const toggleFilters = useCallback(() => setShowFilters((p) => !p), []);
|
|
306
|
+
const toggleHideEmpty = useCallback(() => setHideEmpty((p) => !p), []);
|
|
307
|
+
const handleHighlightChange = useCallback((_: unknown, d: { value: string }) => setHighlightExpr(d.value), []);
|
|
308
|
+
const clearHighlight = useCallback(() => setHighlightExpr(''), []);
|
|
309
|
+
const showAllColumns = useCallback(() => setHiddenColumns(new Set()), []);
|
|
310
|
+
const hideAllColumns = useCallback(() => setHiddenColumns(new Set(columns)), [columns]);
|
|
311
|
+
const setDetailModeTable = useCallback(() => setDetailMode('table'), []);
|
|
312
|
+
const setDetailModeList = useCallback(() => setDetailMode('list'), []);
|
|
313
|
+
const setDetailModeJson = useCallback(() => setDetailMode('json'), []);
|
|
314
|
+
const closeDetail = useCallback(() => setDetailRowIdx(null), []);
|
|
315
|
+
|
|
316
|
+
// --- Memoized JSX for Input contentBefore/contentAfter ---
|
|
317
|
+
const searchContentAfter = useMemo(() =>
|
|
318
|
+
globalSearch ? <Button appearance="transparent" icon={dismissSmallIcon} size="small" onClick={clearGlobalSearch} style={minWidthAutoPaddingZeroStyle} /> : undefined,
|
|
319
|
+
[globalSearch, clearGlobalSearch]);
|
|
320
|
+
|
|
321
|
+
const highlightContentAfter = useMemo(() =>
|
|
322
|
+
highlightExpr ? <Button appearance="transparent" icon={dismissSmallIcon} size="small" onClick={clearHighlight} style={minWidthAutoPaddingZeroStyle} /> : undefined,
|
|
323
|
+
[highlightExpr, clearHighlight]);
|
|
324
|
+
|
|
325
|
+
// --- Memoized styles ---
|
|
326
|
+
const hasActiveFilters = Object.values(columnFilters).some((v) => v.length > 0);
|
|
327
|
+
const totalWidth = useMemo(() => EXPAND_COL_WIDTH + visibleColumns.reduce((sum, col) => sum + columnWidths[col], 0), [visibleColumns, columnWidths]);
|
|
328
|
+
const innerTableStyle = useMemo(() => ({ minWidth: totalWidth, fontFamily: 'Consolas, Monaco, monospace', fontSize: '12px' }), [totalWidth]);
|
|
329
|
+
const theadStyle = useMemo(() => ({ width: totalWidth }), [totalWidth]);
|
|
330
|
+
const totalHeight = virtualizer.getTotalSize();
|
|
331
|
+
const virtualizerContainerStyle = useMemo(() => ({ height: totalHeight, position: 'relative' as const }), [totalHeight]);
|
|
332
|
+
const detailPanelStyle = useMemo(() => ({ width: detailWidth, minWidth: detailWidth }), [detailWidth]);
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<div className={styles.container}>
|
|
336
|
+
<div className={styles.toolbar}>
|
|
337
|
+
{headerLeft}
|
|
338
|
+
<div style={flexOneStyle} />
|
|
339
|
+
<Input className={styles.searchInput} contentBefore={searchIcon} placeholder="Search..." size="small"
|
|
340
|
+
value={globalSearch} onChange={handleGlobalSearchChange} contentAfter={searchContentAfter} />
|
|
341
|
+
<Tooltip content="Toggle column filters" relationship="label">
|
|
342
|
+
<Button appearance="subtle" icon={filterIcon} className={hasActiveFilters || showFilters ? styles.activeFilter : undefined}
|
|
343
|
+
size="small" onClick={toggleFilters} />
|
|
344
|
+
</Tooltip>
|
|
345
|
+
<Tooltip content="Hide empty columns" relationship="label">
|
|
346
|
+
<Button appearance="subtle" icon={eyeOffIcon} className={hideEmpty ? styles.activeFilter : undefined}
|
|
347
|
+
size="small" onClick={toggleHideEmpty} />
|
|
348
|
+
</Tooltip>
|
|
349
|
+
<Popover>
|
|
350
|
+
<PopoverTrigger>
|
|
351
|
+
<Tooltip content="Choose columns" relationship="label">
|
|
352
|
+
<Button appearance="subtle" icon={columnTripleIcon} size="small" />
|
|
353
|
+
</Tooltip>
|
|
354
|
+
</PopoverTrigger>
|
|
355
|
+
<PopoverSurface>
|
|
356
|
+
<div className={styles.colPickerList}>
|
|
357
|
+
{columns.map((col) => (
|
|
358
|
+
<ColumnPickerItem key={col} col={col} isEmpty={emptyColumns.has(col)}
|
|
359
|
+
isHidden={hiddenColumns.has(col)} toggleColumn={toggleColumn} />
|
|
360
|
+
))}
|
|
361
|
+
</div>
|
|
362
|
+
<div className={styles.colPickerActions}>
|
|
363
|
+
<Button size="small" appearance="subtle" onClick={showAllColumns}>Show all</Button>
|
|
364
|
+
<Button size="small" appearance="subtle" onClick={hideAllColumns}>Hide all</Button>
|
|
365
|
+
</div>
|
|
366
|
+
</PopoverSurface>
|
|
367
|
+
</Popover>
|
|
368
|
+
<Input className={styles.highlightInput} contentBefore={highlightIcon}
|
|
369
|
+
placeholder="Highlight: col op val" size="small" value={highlightExpr}
|
|
370
|
+
onChange={handleHighlightChange} contentAfter={highlightContentAfter} />
|
|
371
|
+
{headerRight}
|
|
372
|
+
</div>
|
|
373
|
+
|
|
374
|
+
<div className={styles.bodyArea}>
|
|
375
|
+
<div className={`${styles.scrollContainer} traverse-scroll`} ref={scrollRef} style={overflowAutoStyle}
|
|
376
|
+
role="grid" tabIndex={0} onCopy={handleCopy}>
|
|
377
|
+
<div style={innerTableStyle}>
|
|
378
|
+
<div className={styles.thead} style={theadStyle}>
|
|
379
|
+
<div className={styles.thRow}>
|
|
380
|
+
<div className={styles.thExpand} />
|
|
381
|
+
{visibleColumns.map((col, colIdx) => (
|
|
382
|
+
<ColumnHeader key={col} col={col} colIdx={colIdx} width={columnWidths[col]}
|
|
383
|
+
colType={columnTypes?.[col]} sortColumn={sortColumn} sortDir={sortDir}
|
|
384
|
+
toggleSort={toggleSort} handleHeaderColClick={handleHeaderColClick} styles={styles} />
|
|
385
|
+
))}
|
|
386
|
+
</div>
|
|
387
|
+
{showFilters && (
|
|
388
|
+
<div className={styles.filterRow}>
|
|
389
|
+
<div style={expandColPlaceholderStyle} />
|
|
390
|
+
{visibleColumns.map((col) => (
|
|
391
|
+
<FilterCell key={col} col={col} width={columnWidths[col]}
|
|
392
|
+
value={columnFilters[col] ?? ''} setFilter={setFilter} styles={styles} />
|
|
393
|
+
))}
|
|
394
|
+
</div>
|
|
395
|
+
)}
|
|
396
|
+
</div>
|
|
397
|
+
<div style={virtualizerContainerStyle}>
|
|
398
|
+
{virtualizer.getVirtualItems().map((vRow) => {
|
|
399
|
+
const row = sortedRows[vRow.index];
|
|
400
|
+
const isDetailOpen = detailRowIdx === vRow.index;
|
|
401
|
+
const exprMatch = parsedHighlight ? matchesHighlight(row, parsedHighlight) : false;
|
|
402
|
+
return (
|
|
403
|
+
<VirtualRow key={vRow.key} vRow={vRow} row={row}
|
|
404
|
+
isDetailOpen={isDetailOpen} exprMatch={exprMatch}
|
|
405
|
+
visibleColumns={visibleColumns} columnWidths={columnWidths}
|
|
406
|
+
selection={selection} totalWidth={totalWidth} styles={styles}
|
|
407
|
+
setDetailRowIdx={setDetailRowIdx} handleCellMouseDown={handleCellMouseDown}
|
|
408
|
+
handleCellMouseEnter={handleCellMouseEnter} />
|
|
409
|
+
);
|
|
410
|
+
})}
|
|
411
|
+
</div>
|
|
412
|
+
</div>
|
|
413
|
+
</div>
|
|
414
|
+
|
|
415
|
+
{/* Detail panel */}
|
|
416
|
+
{detailData && (
|
|
417
|
+
<>
|
|
418
|
+
<div className={styles.detailDragHandle} role="separator" onMouseDown={onDetailDragStart} />
|
|
419
|
+
<div className={styles.detailPanel} style={detailPanelStyle}>
|
|
420
|
+
<div className={styles.detailHeader}>
|
|
421
|
+
<div className={styles.detailHeaderLeft}>
|
|
422
|
+
<span>Row {(detailRowIdx ?? 0) + 1}</span>
|
|
423
|
+
<Tooltip content="Table view" relationship="label">
|
|
424
|
+
<Button appearance="subtle" icon={tableSimpleIcon} size="small"
|
|
425
|
+
className={detailMode === 'table' ? styles.activeFilter : undefined}
|
|
426
|
+
onClick={setDetailModeTable} style={minWidthAutoStyle} />
|
|
427
|
+
</Tooltip>
|
|
428
|
+
<Tooltip content="List view" relationship="label">
|
|
429
|
+
<Button appearance="subtle" icon={textBulletListIcon} size="small"
|
|
430
|
+
className={detailMode === 'list' ? styles.activeFilter : undefined}
|
|
431
|
+
onClick={setDetailModeList} style={minWidthAutoStyle} />
|
|
432
|
+
</Tooltip>
|
|
433
|
+
<Tooltip content="JSON view" relationship="label">
|
|
434
|
+
<Button appearance="subtle" icon={codeIcon} size="small"
|
|
435
|
+
className={detailMode === 'json' ? styles.activeFilter : undefined}
|
|
436
|
+
onClick={setDetailModeJson} style={minWidthAutoStyle} />
|
|
437
|
+
</Tooltip>
|
|
438
|
+
</div>
|
|
439
|
+
<Button appearance="subtle" icon={dismissCircleIcon} size="small"
|
|
440
|
+
onClick={closeDetail} style={minWidthAutoStyle} />
|
|
441
|
+
</div>
|
|
442
|
+
{detailMode === 'table' && (
|
|
443
|
+
<div className={styles.detailBody}>
|
|
444
|
+
{columns.map((col) => {
|
|
445
|
+
const val = detailData[col];
|
|
446
|
+
const display = val === null || val === undefined ? ''
|
|
447
|
+
: typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val as string | number | boolean);
|
|
448
|
+
return (
|
|
449
|
+
<div key={col} className={styles.detailRow}>
|
|
450
|
+
<span className={styles.detailKey} title={col}>{col}</span>
|
|
451
|
+
<span className={styles.detailValue}>{display}</span>
|
|
452
|
+
</div>
|
|
453
|
+
);
|
|
454
|
+
})}
|
|
455
|
+
</div>
|
|
456
|
+
)}
|
|
457
|
+
{detailMode === 'list' && (
|
|
458
|
+
<div className={styles.detailBody}>
|
|
459
|
+
{columns.map((col) => {
|
|
460
|
+
const val = detailData[col];
|
|
461
|
+
const display = val === null || val === undefined ? ''
|
|
462
|
+
: typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val as string | number | boolean);
|
|
463
|
+
return (
|
|
464
|
+
<div key={col} className={styles.detailListRow}>
|
|
465
|
+
<span className={styles.detailListKey}>{col}</span>
|
|
466
|
+
<span className={styles.detailListValue}>{display}</span>
|
|
467
|
+
</div>
|
|
468
|
+
);
|
|
469
|
+
})}
|
|
470
|
+
</div>
|
|
471
|
+
)}
|
|
472
|
+
{detailMode === 'json' && (
|
|
473
|
+
<div className={styles.detailMonaco}>
|
|
474
|
+
<Suspense fallback={monacoFallback}>
|
|
475
|
+
<Editor height="100%" language="json" theme={isDark ? 'vs-dark' : 'vs'}
|
|
476
|
+
value={detailJson} options={monacoOptions} />
|
|
477
|
+
</Suspense>
|
|
478
|
+
</div>
|
|
479
|
+
)}
|
|
480
|
+
</div>
|
|
481
|
+
</>
|
|
482
|
+
)}
|
|
483
|
+
</div>
|
|
484
|
+
|
|
485
|
+
<div className={styles.statusBar}>
|
|
486
|
+
<div className={styles.statusLeft}>
|
|
487
|
+
<span>{sortedRows.length.toLocaleString()} / {rows.length.toLocaleString()} rows</span>
|
|
488
|
+
<span>{visibleColumns.length} / {columns.length} columns</span>
|
|
489
|
+
{parsedHighlight && <span>Highlighting: {highlightExpr}</span>}
|
|
490
|
+
</div>
|
|
491
|
+
{selectionStats && (
|
|
492
|
+
<div className={styles.statusRight}>
|
|
493
|
+
<span className={styles.statHighlight}>Selected: {selectionStats.cells} cells</span>
|
|
494
|
+
{Object.entries(selectionStats.aggs).map(([key, val]) => <span key={key}>{key}: {val}</span>)}
|
|
495
|
+
{selectionStats.dateDelta && <span>Δ Time: {selectionStats.dateDelta}</span>}
|
|
496
|
+
</div>
|
|
497
|
+
)}
|
|
498
|
+
</div>
|
|
499
|
+
</div>
|
|
500
|
+
);
|
|
501
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import { act } from 'react';
|
|
6
|
+
import { VirtualCell } from './VirtualCell';
|
|
7
|
+
|
|
8
|
+
vi.mock('../../context/ExplorerColorContext', () => ({
|
|
9
|
+
useExplorerColors: () => ({ semantic: {}, chart: { palette: [] } }),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
let container: HTMLDivElement;
|
|
13
|
+
let root: ReturnType<typeof createRoot>;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
if (root) {
|
|
22
|
+
act(() => { root.unmount(); });
|
|
23
|
+
}
|
|
24
|
+
if (container) {
|
|
25
|
+
container.remove();
|
|
26
|
+
}
|
|
27
|
+
vi.restoreAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('VirtualCell', () => {
|
|
31
|
+
it('renders cell value and fires mouse handlers', () => {
|
|
32
|
+
const handleMouseDown = vi.fn();
|
|
33
|
+
const handleMouseEnter = vi.fn();
|
|
34
|
+
container = document.createElement('div');
|
|
35
|
+
document.body.appendChild(container);
|
|
36
|
+
root = createRoot(container);
|
|
37
|
+
|
|
38
|
+
const mockStyles = new Proxy({}, { get: (_, p) => String(p) }) as never;
|
|
39
|
+
const row = { Col1: 'hello' };
|
|
40
|
+
|
|
41
|
+
act(() => {
|
|
42
|
+
root.render(React.createElement(VirtualCell, {
|
|
43
|
+
col: 'Col1', colIdx: 0, rowIdx: 2, row, width: 100,
|
|
44
|
+
selected: false, styles: mockStyles,
|
|
45
|
+
handleCellMouseDown: handleMouseDown, handleCellMouseEnter: handleMouseEnter,
|
|
46
|
+
}));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(container.textContent).toContain('hello');
|
|
50
|
+
|
|
51
|
+
const cell = container.querySelector('[role="gridcell"]');
|
|
52
|
+
act(() => { cell?.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); });
|
|
53
|
+
expect(handleMouseDown).toHaveBeenCalledWith(2, 0, expect.anything());
|
|
54
|
+
});
|
|
55
|
+
});
|