Skip to content

Commit 1ab2240

Browse files
author
Dylan Huang
committed
consolidate filter configurations
1 parent 3be40be commit 1ab2240

File tree

5 files changed

+47
-64
lines changed

5 files changed

+47
-64
lines changed

vite-app/src/GlobalState.tsx

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ const DEFAULT_PIVOT_CONFIG: PivotConfig = {
1111
selectedColumnFields: ["$.input_metadata.completion_params.model"],
1212
selectedValueField: "$.evaluation_result.score",
1313
selectedAggregator: "avg",
14-
filters: [],
1514
};
1615

17-
// Default table filter configuration
18-
const DEFAULT_TABLE_FILTER_CONFIG: FilterGroup[] = [];
16+
// Default filter configuration
17+
const DEFAULT_FILTER_CONFIG: FilterGroup[] = [];
1918

2019
// Default pagination configuration
2120
const DEFAULT_PAGINATION_CONFIG = {
@@ -31,10 +30,10 @@ export class GlobalState {
3130
expandedRows: Record<string, boolean> = {};
3231
// Pivot configuration
3332
pivotConfig: PivotConfig;
34-
// Table filter configuration
35-
tableFilterConfig: FilterGroup[];
36-
// Debounced, actually applied table filter configuration (for performance while typing)
37-
appliedTableFilterConfig: FilterGroup[];
33+
// Unified filter configuration for both pivot and table views
34+
filterConfig: FilterGroup[];
35+
// Debounced, actually applied filter configuration (for performance while typing)
36+
appliedFilterConfig: FilterGroup[];
3837
// Pagination configuration
3938
currentPage: number;
4039
pageSize: number;
@@ -49,19 +48,18 @@ export class GlobalState {
4948

5049
// Debounce timers for localStorage saves and filter application
5150
private savePivotConfigTimer: ReturnType<typeof setTimeout> | null = null;
52-
private saveTableFilterConfigTimer: ReturnType<typeof setTimeout> | null =
53-
null;
51+
private saveFilterConfigTimer: ReturnType<typeof setTimeout> | null = null;
5452
private savePaginationConfigTimer: ReturnType<typeof setTimeout> | null =
5553
null;
56-
private applyTableFilterTimer: ReturnType<typeof setTimeout> | null = null;
54+
private applyFilterTimer: ReturnType<typeof setTimeout> | null = null;
5755

5856
constructor() {
5957
// Load pivot config from localStorage or use defaults
6058
this.pivotConfig = this.loadPivotConfig();
61-
// Load table filter config from localStorage or use defaults
62-
this.tableFilterConfig = this.loadTableFilterConfig();
59+
// Load filter config from localStorage or use defaults
60+
this.filterConfig = this.loadFilterConfig();
6361
// Initialize applied filter config with current value
64-
this.appliedTableFilterConfig = this.tableFilterConfig.slice();
62+
this.appliedFilterConfig = this.filterConfig.slice();
6563
// Load pagination config from localStorage or use defaults
6664
const paginationConfig = this.loadPaginationConfig();
6765
this.currentPage = paginationConfig.currentPage;
@@ -84,21 +82,18 @@ export class GlobalState {
8482
return { ...DEFAULT_PIVOT_CONFIG };
8583
}
8684

87-
// Load table filter configuration from localStorage
88-
private loadTableFilterConfig(): FilterGroup[] {
85+
// Load filter configuration from localStorage
86+
private loadFilterConfig(): FilterGroup[] {
8987
try {
90-
const stored = localStorage.getItem("tableFilterConfig");
88+
const stored = localStorage.getItem("filterConfig");
9189
if (stored) {
9290
const parsed = JSON.parse(stored);
93-
return Array.isArray(parsed) ? parsed : DEFAULT_TABLE_FILTER_CONFIG;
91+
return Array.isArray(parsed) ? parsed : DEFAULT_FILTER_CONFIG;
9492
}
9593
} catch (error) {
96-
console.warn(
97-
"Failed to load table filter config from localStorage:",
98-
error
99-
);
94+
console.warn("Failed to load filter config from localStorage:", error);
10095
}
101-
return DEFAULT_TABLE_FILTER_CONFIG;
96+
return DEFAULT_FILTER_CONFIG;
10297
}
10398

10499
// Load pagination configuration from localStorage
@@ -116,7 +111,7 @@ export class GlobalState {
116111
error
117112
);
118113
}
119-
return { ...DEFAULT_PAGINATION_CONFIG };
114+
return DEFAULT_PAGINATION_CONFIG;
120115
}
121116

122117
// Save pivot configuration to localStorage
@@ -131,21 +126,14 @@ export class GlobalState {
131126
}, 200);
132127
}
133128

134-
// Save table filter configuration to localStorage
135-
private saveTableFilterConfig() {
136-
if (this.saveTableFilterConfigTimer)
137-
clearTimeout(this.saveTableFilterConfigTimer);
138-
this.saveTableFilterConfigTimer = setTimeout(() => {
129+
// Save filter configuration to localStorage
130+
private saveFilterConfig() {
131+
if (this.saveFilterConfigTimer) clearTimeout(this.saveFilterConfigTimer);
132+
this.saveFilterConfigTimer = setTimeout(() => {
139133
try {
140-
localStorage.setItem(
141-
"tableFilterConfig",
142-
JSON.stringify(this.tableFilterConfig)
143-
);
134+
localStorage.setItem("filterConfig", JSON.stringify(this.filterConfig));
144135
} catch (error) {
145-
console.warn(
146-
"Failed to save table filter config to localStorage:",
147-
error
148-
);
136+
console.warn("Failed to save filter config to localStorage:", error);
149137
}
150138
}, 200);
151139
}
@@ -178,15 +166,15 @@ export class GlobalState {
178166
this.savePivotConfig();
179167
}
180168

181-
// Update table filter configuration and save to localStorage
182-
updateTableFilterConfig(filters: FilterGroup[]) {
183-
this.tableFilterConfig = filters;
184-
this.saveTableFilterConfig();
169+
// Update filter configuration and save to localStorage
170+
updateFilterConfig(filters: FilterGroup[]) {
171+
this.filterConfig = filters;
172+
this.saveFilterConfig();
185173

186174
// Debounce application of filters to avoid re-filtering on every keystroke
187-
if (this.applyTableFilterTimer) clearTimeout(this.applyTableFilterTimer);
188-
this.applyTableFilterTimer = setTimeout(() => {
189-
this.appliedTableFilterConfig = this.tableFilterConfig.slice();
175+
if (this.applyFilterTimer) clearTimeout(this.applyFilterTimer);
176+
this.applyFilterTimer = setTimeout(() => {
177+
this.appliedFilterConfig = this.filterConfig.slice();
190178
}, 150);
191179
}
192180

@@ -205,18 +193,15 @@ export class GlobalState {
205193

206194
// Reset pivot configuration to defaults
207195
resetPivotConfig() {
208-
this.pivotConfig = {
209-
...DEFAULT_PIVOT_CONFIG,
210-
filters: [], // Ensure filters is an empty array of FilterGroups
211-
};
196+
this.pivotConfig = { ...DEFAULT_PIVOT_CONFIG };
212197
this.savePivotConfig();
213198
}
214199

215-
// Reset table filter configuration to defaults
216-
resetTableFilterConfig() {
217-
this.tableFilterConfig = [...DEFAULT_TABLE_FILTER_CONFIG];
218-
this.appliedTableFilterConfig = [...DEFAULT_TABLE_FILTER_CONFIG];
219-
this.saveTableFilterConfig();
200+
// Reset filter configuration to defaults
201+
resetFilterConfig() {
202+
this.filterConfig = [...DEFAULT_FILTER_CONFIG];
203+
this.appliedFilterConfig = [...DEFAULT_FILTER_CONFIG];
204+
this.saveFilterConfig();
220205
}
221206

222207
// Reset pagination configuration to defaults
@@ -315,20 +300,20 @@ export class GlobalState {
315300
}
316301

317302
get filteredFlattenedDataset() {
318-
if (this.appliedTableFilterConfig.length === 0) {
303+
if (this.appliedFilterConfig.length === 0) {
319304
return this.flattenedDataset;
320305
}
321306

322-
const filterFunction = createFilterFunction(this.appliedTableFilterConfig)!;
307+
const filterFunction = createFilterFunction(this.appliedFilterConfig)!;
323308
return this.flattenedDataset.filter(filterFunction);
324309
}
325310

326311
get filteredOriginalDataset() {
327-
if (this.appliedTableFilterConfig.length === 0) {
312+
if (this.appliedFilterConfig.length === 0) {
328313
return this.sortedDataset;
329314
}
330315

331-
const filterFunction = createFilterFunction(this.appliedTableFilterConfig)!;
316+
const filterFunction = createFilterFunction(this.appliedFilterConfig)!;
332317
return this.sortedIds
333318
.filter((id) => filterFunction(this.flattenedById[id]))
334319
.map((id) => this.dataset[id]);

vite-app/src/components/EvaluationRow.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ const RolloutId = observer(
121121
return (
122122
<span className="font-mono text-gray-900 whitespace-nowrap">
123123
{rolloutId}
124-
<CopyButton text={rolloutId} />
125124
</span>
126125
);
127126
}

vite-app/src/components/EvaluationTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const EvaluationTable = observer(() => {
4848
};
4949

5050
const handleFiltersChange = (filters: any[]) => {
51-
state.updateTableFilterConfig(filters);
51+
state.updateFilterConfig(filters);
5252
};
5353

5454
return (
@@ -59,7 +59,7 @@ export const EvaluationTable = observer(() => {
5959
<div className="flex items-center gap-4">
6060
<h3 className="text-sm font-medium text-gray-700">Table Filters</h3>
6161
<div className="text-xs text-gray-600">
62-
{state.tableFilterConfig.length > 0 ? (
62+
{state.filterConfig.length > 0 ? (
6363
<>
6464
Showing {totalRows} of {state.sortedDataset.length} rows
6565
{totalRows !== state.sortedDataset.length && (
@@ -74,7 +74,7 @@ export const EvaluationTable = observer(() => {
7474
</div>
7575
<div className="bg-white rounded-lg">
7676
<FilterSelector
77-
filters={state.tableFilterConfig}
77+
filters={state.filterConfig}
7878
onFiltersChange={handleFiltersChange}
7979
availableKeys={state.flattenedDatasetKeys}
8080
title=""

vite-app/src/components/PivotTab.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const PivotTab = observer(() => {
148148
};
149149

150150
const updateFilters = (filters: FilterGroup[]) => {
151-
state.updatePivotConfig({ filters });
151+
state.updateFilterConfig(filters);
152152
};
153153

154154
const createFieldHandler = (
@@ -246,7 +246,7 @@ const PivotTab = observer(() => {
246246
/>
247247

248248
<FilterSelector
249-
filters={pivotConfig.filters}
249+
filters={state.filterConfig}
250250
onFiltersChange={updateFilters}
251251
availableKeys={availableKeys}
252252
title="Filters"
@@ -287,7 +287,7 @@ const PivotTab = observer(() => {
287287
}
288288
showRowTotals
289289
showColumnTotals
290-
filter={createFilterFunction(pivotConfig.filters)}
290+
filter={createFilterFunction(state.filterConfig)}
291291
/>
292292
</div>
293293
);

vite-app/src/types/filters.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ export interface PivotConfig {
2424
selectedColumnFields: string[];
2525
selectedValueField: string;
2626
selectedAggregator: string;
27-
filters: FilterGroup[];
2827
}

0 commit comments

Comments
 (0)