@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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +46 -0
  3. package/src/bootstrap.spec.tsx +290 -0
  4. package/src/bootstrap.tsx +195 -0
  5. package/src/colors.ts +23 -0
  6. package/src/components/ChartPanel/ChartPanel.logic.spec.ts +358 -0
  7. package/src/components/ChartPanel/ChartPanel.logic.ts +318 -0
  8. package/src/components/ChartPanel/ChartPanel.spec.tsx +331 -0
  9. package/src/components/ChartPanel/ChartPanel.styles.ts +14 -0
  10. package/src/components/ChartPanel/ChartPanel.tsx +151 -0
  11. package/src/components/ConnectionDialog/ConnectionDialog.spec.tsx +767 -0
  12. package/src/components/ConnectionDialog/ConnectionDialog.tsx +652 -0
  13. package/src/components/ConnectionDialog/ConnectionRow.spec.tsx +104 -0
  14. package/src/components/ConnectionDialog/ConnectionRow.tsx +177 -0
  15. package/src/components/EditorToolbar/EditorToolbar.spec.tsx +599 -0
  16. package/src/components/EditorToolbar/EditorToolbar.tsx +259 -0
  17. package/src/components/Explorer/Explorer.spec.tsx +615 -0
  18. package/src/components/Explorer/Explorer.tsx +49 -0
  19. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.spec.ts +715 -0
  20. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +324 -0
  21. package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +450 -0
  22. package/src/components/ExplorerWorkspace/ExplorerWorkspace.styles.ts +478 -0
  23. package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +648 -0
  24. package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +321 -0
  25. package/src/components/ExplorerWorkspace/kqlLanguage.ts +155 -0
  26. package/src/components/ResultsPanel/ElapsedTimer.spec.tsx +51 -0
  27. package/src/components/ResultsPanel/ElapsedTimer.tsx +15 -0
  28. package/src/components/ResultsPanel/HistoryItem.spec.tsx +123 -0
  29. package/src/components/ResultsPanel/HistoryItem.tsx +56 -0
  30. package/src/components/ResultsPanel/ResultSetTab.tsx +18 -0
  31. package/src/components/ResultsPanel/ResultsPanel.spec.tsx +1194 -0
  32. package/src/components/ResultsPanel/ResultsPanel.tsx +321 -0
  33. package/src/components/ResultsPanel/TabButton.tsx +11 -0
  34. package/src/components/ResultsTable/ColumnHeader.tsx +42 -0
  35. package/src/components/ResultsTable/ColumnPickerItem.tsx +16 -0
  36. package/src/components/ResultsTable/FilterCell.tsx +24 -0
  37. package/src/components/ResultsTable/ResultsTable.logic.spec.ts +655 -0
  38. package/src/components/ResultsTable/ResultsTable.logic.ts +264 -0
  39. package/src/components/ResultsTable/ResultsTable.spec.tsx +930 -0
  40. package/src/components/ResultsTable/ResultsTable.styles.ts +108 -0
  41. package/src/components/ResultsTable/ResultsTable.tsx +501 -0
  42. package/src/components/ResultsTable/VirtualCell.spec.tsx +55 -0
  43. package/src/components/ResultsTable/VirtualCell.tsx +32 -0
  44. package/src/components/ResultsTable/VirtualRow.tsx +55 -0
  45. package/src/components/SchemaSidebar/FolderRow.tsx +35 -0
  46. package/src/components/SchemaSidebar/SchemaColumnItem.tsx +41 -0
  47. package/src/components/SchemaSidebar/SchemaContextMenu.spec.tsx +148 -0
  48. package/src/components/SchemaSidebar/SchemaContextMenu.tsx +49 -0
  49. package/src/components/SchemaSidebar/SchemaSidebar.logic.spec.ts +230 -0
  50. package/src/components/SchemaSidebar/SchemaSidebar.logic.ts +74 -0
  51. package/src/components/SchemaSidebar/SchemaSidebar.spec.tsx +1111 -0
  52. package/src/components/SchemaSidebar/SchemaSidebar.tsx +244 -0
  53. package/src/components/SchemaSidebar/SchemaTableItem.tsx +77 -0
  54. package/src/components/TabBar/TabBar.logic.spec.ts +127 -0
  55. package/src/components/TabBar/TabBar.logic.ts +35 -0
  56. package/src/components/TabBar/TabBar.spec.tsx +929 -0
  57. package/src/components/TabBar/TabBar.tsx +284 -0
  58. package/src/components/TabBar/TabItem.tsx +166 -0
  59. package/src/components/VegaChart/VegaChart.spec.tsx +126 -0
  60. package/src/components/VegaChart/VegaChart.tsx +224 -0
  61. package/src/config.spec.ts +44 -0
  62. package/src/config.ts +47 -0
  63. package/src/context/ExplorerColorContext.ts +14 -0
  64. package/src/context/ExplorerStateContext.ts +49 -0
  65. package/src/context/KustoClientContext.ts +12 -0
  66. package/src/context/context.spec.tsx +183 -0
  67. package/src/index.ts +14 -0
  68. package/src/services/cache.spec.ts +31 -0
  69. package/src/services/cache.ts +16 -0
  70. package/src/services/concurrency.spec.ts +139 -0
  71. package/src/services/concurrency.ts +46 -0
  72. package/src/services/kusto.spec.ts +919 -0
  73. package/src/services/kusto.ts +472 -0
  74. package/src/services/queryHistory.spec.ts +287 -0
  75. package/src/services/queryHistory.ts +146 -0
  76. package/src/services/schema.spec.ts +618 -0
  77. package/src/services/schema.ts +294 -0
  78. package/src/services/state-service.spec.ts +670 -0
  79. package/src/services/state-service.ts +602 -0
  80. package/src/services/useKustoQuery.spec.ts +234 -0
  81. package/src/services/useKustoQuery.ts +124 -0
  82. package/src/state/actions.ts +50 -0
  83. package/src/state/index.ts +3 -0
  84. package/src/state/reducer.spec.ts +644 -0
  85. package/src/state/reducer.ts +207 -0
  86. package/src/state/types.ts +54 -0
  87. package/tsconfig.json +7 -0
  88. package/tsconfig.lint.json +4 -0
  89. package/tsconfig.spec.json +7 -0
  90. package/vitest.config.ts +34 -0
@@ -0,0 +1,259 @@
1
+ import { Text, Button, Tooltip, tokens, Dropdown, Option, OptionGroup, makeStyles } from '@fluentui/react-components';
2
+ import {
3
+ PlayRegular,
4
+ StopRegular,
5
+ ArrowRepeatAllRegular,
6
+ TextAlignLeftRegular,
7
+ KeyboardRegular,
8
+ DismissRegular,
9
+ } from '@fluentui/react-icons';
10
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
+
12
+ import { listDatabases, getPersistedDatabases } from '../../services/schema';
13
+ import { ConnectionDialog } from '../ConnectionDialog/ConnectionDialog';
14
+ import type { KustoConnection } from '../ExplorerWorkspace/ExplorerWorkspace.logic';
15
+ import { saveConnections, saveActiveConnectionId } from '../ExplorerWorkspace/ExplorerWorkspace.logic';
16
+ import { KEYBOARD_SHORTCUTS } from '../ExplorerWorkspace/ExplorerWorkspace.logic';
17
+ import { useExplorerStyles } from '../ExplorerWorkspace/ExplorerWorkspace.styles';
18
+ import { useExplorerState, useExplorerDispatch } from '../../context/ExplorerStateContext';
19
+ import { useKustoClient } from '../../context/KustoClientContext';
20
+ import { useExplorerColors } from '../../context/ExplorerColorContext';
21
+
22
+ const stopIcon = <StopRegular />;
23
+ const playIcon = <PlayRegular />;
24
+ const arrowRepeatIcon = <ArrowRepeatAllRegular />;
25
+ const textAlignIcon = <TextAlignLeftRegular />;
26
+ const keyboardIcon = <KeyboardRegular />;
27
+ const dismissIcon = <DismissRegular />;
28
+
29
+ const cancelButtonStyle = { backgroundColor: tokens.colorPaletteRedBackground3 } as const;
30
+ const connectionDropdownStyle = { minWidth: '180px', maxWidth: '280px', overflow: 'hidden' } as const;
31
+ const dbDropdownStyle = { minWidth: '100px', maxWidth: '200px', overflow: 'hidden' } as const;
32
+ const connectionOptionStyle = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } as const;
33
+ const connectionDotStyle = (color: string) => ({ display: 'inline-block', width: '8px', height: '8px', borderRadius: '50%', backgroundColor: color, marginRight: '6px', flexShrink: 0 }) as const;
34
+ const modalHeaderStyle = { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '12px' } as const;
35
+ const shortcutRowStyle = { display: 'flex', justifyContent: 'space-between', padding: '6px 0', borderBottom: `1px solid ${tokens.colorNeutralStroke2}`, fontSize: '13px' } as const;
36
+ const shortcutActionStyle = { color: tokens.colorNeutralForeground1 } as const;
37
+ const shortcutCodeStyle = { backgroundColor: tokens.colorNeutralBackground3, padding: '2px 6px', borderRadius: '3px', fontSize: '11px', fontFamily: 'Consolas, Monaco, monospace', color: tokens.colorNeutralForeground2 } as const;
38
+
39
+ const stopPropagation = (e: React.MouseEvent) => e.stopPropagation();
40
+ const stopPropagationKeyDown = (e: React.KeyboardEvent) => e.stopPropagation();
41
+
42
+ const useDropdownStyles = makeStyles({
43
+ listbox: {
44
+ width: 'auto !important' as unknown as string,
45
+ minWidth: '200px',
46
+ maxWidth: '400px',
47
+ },
48
+ });
49
+
50
+ export interface EditorToolbarProps {
51
+ showCancel: boolean;
52
+ onRun: () => void;
53
+ onCancel: () => void;
54
+ onRecall: () => void;
55
+ onFormat: () => void;
56
+ connections: KustoConnection[];
57
+ focusedConnection: KustoConnection;
58
+ }
59
+
60
+ export function EditorToolbar({ showCancel, onRun, onCancel, onRecall, onFormat, connections, focusedConnection }: EditorToolbarProps) {
61
+ const styles = useExplorerStyles();
62
+ const { hasSelection, canRecall, loading, activeTabId, splitTabId, focusedPane } = useExplorerState();
63
+ const dispatch = useExplorerDispatch();
64
+ const client = useKustoClient();
65
+ const { semantic } = useExplorerColors();
66
+ const dropdownStyles = useDropdownStyles();
67
+ const listboxProp = useMemo(() => ({ className: dropdownStyles.listbox }), [dropdownStyles.listbox]);
68
+
69
+ const backdropStyle = useMemo(() => ({ position: 'fixed' as const, top: 0, left: 0, right: 0, bottom: 0, backgroundColor: semantic.backdrop, zIndex: 1000, display: 'flex', alignItems: 'center', justifyContent: 'center' }) as const, [semantic.backdrop]);
70
+ const modalStyle = useMemo(() => ({ backgroundColor: tokens.colorNeutralBackground1, borderRadius: '8px', padding: '16px 20px', minWidth: '320px', boxShadow: `0 8px 32px ${semantic.shadowMedium}` }) as const, [semantic.shadowMedium]);
71
+
72
+ const [showShortcuts, setShowShortcuts] = React.useState(false);
73
+ const [showConnDialog, setShowConnDialog] = useState(false);
74
+
75
+ // Database dropdown state (uses persistent cache for instant load)
76
+ const [dbCache, setDbCache] = useState<Record<string, string[]>>(() => {
77
+ const initial: Record<string, string[]> = {};
78
+ for (const conn of connections) {
79
+ const cached = getPersistedDatabases(conn.clusterUrl);
80
+ if (cached) {
81
+ initial[conn.clusterUrl] = cached;
82
+ }
83
+ }
84
+ return initial;
85
+ });
86
+ const [dbLoading, setDbLoading] = useState(false);
87
+ const lastLoadedCluster = useRef('');
88
+
89
+ const databases = dbCache[focusedConnection.clusterUrl] ?? [];
90
+ const selectedDb = useMemo(() => focusedConnection.database ? [focusedConnection.database] : [], [focusedConnection.database]);
91
+
92
+ // Lazy-load databases when the dropdown opens
93
+ const handleDbDropdownOpen = useCallback((_: unknown, data: { open: boolean }) => {
94
+ if (!data.open) {
95
+ return;
96
+ }
97
+ const url = focusedConnection.clusterUrl;
98
+ if (dbCache[url] || lastLoadedCluster.current === url) {
99
+ return;
100
+ }
101
+ lastLoadedCluster.current = url;
102
+ setDbLoading(true);
103
+ void listDatabases(client, url).then((dbs) => {
104
+ setDbCache((prev) => ({ ...prev, [url]: dbs }));
105
+ }).finally(() => setDbLoading(false));
106
+ }, [client, focusedConnection.clusterUrl, dbCache]);
107
+
108
+ const handleDbChange = useCallback((_: unknown, data: { optionValue?: string }) => {
109
+ if (!data.optionValue) {
110
+ return;
111
+ }
112
+ // Update the connection's database in the connections array and persist
113
+ const updated = connections.map((c) =>
114
+ c.id === focusedConnection.id ? { ...c, database: data.optionValue! } : c,
115
+ );
116
+ saveConnections(updated);
117
+ dispatch({ type: 'SET_CONNECTIONS', connections: updated });
118
+ }, [connections, focusedConnection.id, dispatch]);
119
+
120
+ // Reset db cache when connection changes
121
+ useEffect(() => {
122
+ lastLoadedCluster.current = '';
123
+ }, [focusedConnection.id]);
124
+
125
+ const openShortcuts = useCallback(() => setShowShortcuts(true), []);
126
+ const closeShortcuts = useCallback(() => setShowShortcuts(false), []);
127
+ const closeConnDialog = useCallback(() => setShowConnDialog(false), []);
128
+ const handleBackdropKeyDown = useCallback((e: React.KeyboardEvent) => {
129
+ if (e.key === 'Escape' || e.key === 'Enter' || e.key === ' ') {
130
+ closeShortcuts();
131
+ }
132
+ }, [closeShortcuts]);
133
+
134
+ const handleConnectionChange = useCallback((_: unknown, data: { optionValue?: string }) => {
135
+ if (data.optionValue === '__manage__') {
136
+ setShowConnDialog(true);
137
+ return;
138
+ }
139
+ if (data.optionValue) {
140
+ saveActiveConnectionId(data.optionValue);
141
+ const tabId = focusedPane === 'primary' ? activeTabId : splitTabId;
142
+ if (tabId) {
143
+ dispatch({ type: 'SET_TAB_CONNECTION', tabId, connectionId: data.optionValue });
144
+ }
145
+ }
146
+ }, [dispatch, focusedPane, activeTabId, splitTabId]);
147
+
148
+ const connectionDropdownValue = focusedConnection.name;
149
+
150
+ const connectionDropdownBorderStyle = useMemo(
151
+ () => ({ ...connectionDropdownStyle, borderLeft: `3px solid ${focusedConnection.color}` }),
152
+ [focusedConnection.color],
153
+ );
154
+
155
+ const selectedOptions = useMemo(() => [focusedConnection.id], [focusedConnection.id]);
156
+
157
+ return (
158
+ <>
159
+ <div className={styles.toolbar}>
160
+ <div className={styles.toolbarLeft}>
161
+ {showCancel ? (
162
+ <Button appearance="primary" icon={stopIcon}
163
+ onClick={onCancel} size="small" style={cancelButtonStyle}>
164
+ Cancel
165
+ </Button>
166
+ ) : (
167
+ <Tooltip content={hasSelection ? 'Run Selection (Ctrl+Shift+Enter)' : 'Run Query (Ctrl+Shift+Enter)'} relationship="label">
168
+ <Button appearance="primary" icon={playIcon}
169
+ onClick={onRun} size="small">
170
+ {hasSelection ? 'Run Selection' : 'Run'}
171
+ </Button>
172
+ </Tooltip>
173
+ )}
174
+ <Tooltip content={canRecall ? 'Recall cached results (Ctrl+Shift+R)' : 'No cached results for current query'} relationship="label">
175
+ <Button appearance="subtle" icon={arrowRepeatIcon}
176
+ onClick={onRecall} disabled={loading || !canRecall} size="small">
177
+ Recall
178
+ </Button>
179
+ </Tooltip>
180
+ <Tooltip content="Format query (Ctrl+Shift+F)" relationship="label">
181
+ <Button appearance="subtle" icon={textAlignIcon}
182
+ onClick={onFormat} size="small" />
183
+ </Tooltip>
184
+ </div>
185
+ <div className={styles.toolbarRight}>
186
+ <Tooltip content="Keyboard shortcuts" relationship="label">
187
+ <Button appearance="subtle" icon={keyboardIcon} size="small"
188
+ onClick={openShortcuts} />
189
+ </Tooltip>
190
+ <Dropdown
191
+ size="small"
192
+ style={connectionDropdownBorderStyle}
193
+ listbox={listboxProp}
194
+ positioning="below-end"
195
+ value={connectionDropdownValue}
196
+ selectedOptions={selectedOptions}
197
+ onOptionSelect={handleConnectionChange}
198
+ >
199
+ <OptionGroup>
200
+ {connections.map((c) => (
201
+ <Option key={c.id} value={c.id} text={c.name}>
202
+ <span style={connectionDotStyle(c.color)} />
203
+ <span style={connectionOptionStyle}>{c.name}</span>
204
+ </Option>
205
+ ))}
206
+ </OptionGroup>
207
+ <OptionGroup>
208
+ <Option key="__manage__" value="__manage__" text="Manage">⚙ Manage…</Option>
209
+ </OptionGroup>
210
+ </Dropdown>
211
+ <Dropdown
212
+ size="small"
213
+ style={dbDropdownStyle}
214
+ listbox={listboxProp}
215
+ positioning="below-end"
216
+ value={focusedConnection.database || 'Select DB…'}
217
+ selectedOptions={selectedDb}
218
+ onOptionSelect={handleDbChange}
219
+ onOpenChange={handleDbDropdownOpen}
220
+ >
221
+ {focusedConnection.database && databases.length === 0 && !dbLoading && (
222
+ <Option key={focusedConnection.database} value={focusedConnection.database} text={focusedConnection.database}>
223
+ {focusedConnection.database}
224
+ </Option>
225
+ )}
226
+ {databases.map((db) => (
227
+ <Option key={db} value={db} text={db}>{db}</Option>
228
+ ))}
229
+ {dbLoading && (
230
+ <Option key="__loading__" value="" text="Loading…" disabled>Loading…</Option>
231
+ )}
232
+ </Dropdown>
233
+ </div>
234
+ </div>
235
+
236
+ {showConnDialog && <ConnectionDialog onClose={closeConnDialog} />}
237
+
238
+ {showShortcuts && (
239
+ <div style={backdropStyle} role="dialog"
240
+ onClick={closeShortcuts} onKeyDown={handleBackdropKeyDown}>
241
+ <div style={modalStyle}
242
+ role="dialog"
243
+ onClick={stopPropagation} onKeyDown={stopPropagationKeyDown}>
244
+ <div style={modalHeaderStyle}>
245
+ <Text weight="semibold" size={400}>Keyboard Shortcuts</Text>
246
+ <Button appearance="subtle" icon={dismissIcon} size="small" onClick={closeShortcuts} />
247
+ </div>
248
+ {KEYBOARD_SHORTCUTS.map((s) => (
249
+ <div key={s.keys} style={shortcutRowStyle}>
250
+ <span style={shortcutActionStyle}>{s.action}</span>
251
+ <code style={shortcutCodeStyle}>{s.keys}</code>
252
+ </div>
253
+ ))}
254
+ </div>
255
+ </div>
256
+ )}
257
+ </>
258
+ );
259
+ }