Skip to content

Commit a85feb0

Browse files
committed
Improve filter bar component enablement
1 parent 682bffb commit a85feb0

1 file changed

Lines changed: 39 additions & 4 deletions

File tree

extensions/mssql/src/webviews/pages/TableExplorer/TableExplorerFilterBar.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,37 @@ export const TableExplorerFilterBar: React.FC<TableExplorerFilterBarProps> = ({
377377
onClear();
378378
};
379379

380+
// Check if there are any valid filters that can be applied
381+
const hasValidFilters = rows.some(
382+
(r) => r.column && (operatorTakesValue(r.operator) ? r.value !== "" : true),
383+
);
384+
385+
// Check if current filters differ from the initialFilters (last applied)
386+
const hasChanges = React.useMemo(() => {
387+
const currentValid = rows.filter(
388+
(r) => r.column && (operatorTakesValue(r.operator) ? r.value !== "" : true),
389+
);
390+
391+
// Different number of filters = changed
392+
if (currentValid.length !== initialFilters.length) {
393+
return true;
394+
}
395+
396+
// Compare each filter
397+
return currentValid.some((row, i) => {
398+
const initial = initialFilters[i];
399+
if (!initial) {
400+
return true;
401+
}
402+
return (
403+
row.column !== initial.column ||
404+
row.operator !== initial.operator ||
405+
row.value !== initial.value ||
406+
row.conjunction !== initial.conjunction
407+
);
408+
});
409+
}, [rows, initialFilters]);
410+
380411
return (
381412
<div className={classes.container}>
382413
{rows.map((row, i) => (
@@ -461,9 +492,6 @@ export const TableExplorerFilterBar: React.FC<TableExplorerFilterBarProps> = ({
461492
</div>
462493
))}
463494
<div className={classes.actions}>
464-
<Button appearance="primary" size="small" onClick={handleApply} disabled={disabled}>
465-
{loc.tableExplorer.filterApply}
466-
</Button>
467495
<Button
468496
appearance="transparent"
469497
size="small"
@@ -472,11 +500,18 @@ export const TableExplorerFilterBar: React.FC<TableExplorerFilterBarProps> = ({
472500
disabled={disabled}>
473501
{loc.tableExplorer.filterAdd}
474502
</Button>
503+
<Button
504+
appearance="primary"
505+
size="small"
506+
onClick={handleApply}
507+
disabled={disabled || !hasValidFilters || !hasChanges}>
508+
{loc.tableExplorer.filterApply}
509+
</Button>
475510
<Button
476511
appearance="transparent"
477512
size="small"
478513
onClick={handleClear}
479-
disabled={disabled}>
514+
disabled={disabled || !hasValidFilters}>
480515
{loc.tableExplorer.filterClear}
481516
</Button>
482517
</div>

0 commit comments

Comments
 (0)