Compare commits

...

1 Commits

Author SHA1 Message Date
Ashwin Bhatkal
de6fbfeb2d fix(dashboard): keep ALL on a dynamic variable that holds a value outside its list 2026-10-19 13:02:38 +05:30
4 changed files with 55 additions and 1 deletions

View File

@@ -193,6 +193,40 @@ describe('ValueSelector', () => {
expect(onSearch).toHaveBeenLastCalledWith('pay');
});
it('commits ALL even when the selection holds a value outside the list', async () => {
// A search pick, or one an older time window offered: ALL must still go out as
// `__all__`, not as a list that filters the panels to the truncated options.
const onChange = jest.fn();
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
render(
<ValueSelector
options={OPTIONS}
variableType="dynamic"
multiSelect
showAllOption
selection={{ value: ['searched'], allSelected: false }}
onChange={onChange}
emptyFallback={{ value: null, allSelected: true }}
testId="variable-select-env"
dynamic={{
values: OPTIONS,
relatedValues: [],
complete: false,
onSearch: jest.fn(),
onSearchReset: jest.fn(),
}}
/>,
);
await openDropdown();
await user.click(screen.getByText('ALL'));
await user.keyboard('{Escape}');
expect(onChange).toHaveBeenLastCalledWith(
expect.objectContaining({ allSelected: true }),
);
});
});
describe('clearing', () => {

View File

@@ -12,6 +12,7 @@ function commit(
values,
options: OPTIONS,
showAllOption: true,
isDynamic: false,
emptyFallback: FALLBACK,
...overrides,
});
@@ -60,6 +61,20 @@ describe('selectionFromCommittedValues', () => {
});
});
// A dynamic ALL is sent as `__all__`, so reading it as a list would filter the
// panels down to the truncated option set.
it('reads every option PLUS a value outside the list as ALL for a dynamic variable', () => {
expect(
commit([...OPTIONS, 'searched'], { isDynamic: true }).allSelected,
).toBe(true);
});
it('does not read a dynamic subset PLUS a value outside the list as ALL', () => {
expect(
commit(['checkout', 'searched'], { isDynamic: true }).allSelected,
).toBe(false);
});
// Derived from the values + options at commit time, never from the old selection.
it('recomputes the marker: a typed value the data now offers is a normal pick', () => {
expect(

View File

@@ -102,6 +102,7 @@ function ValueSelector({
values,
options,
showAllOption,
isDynamic: !!dynamic,
emptyFallback,
});

View File

@@ -51,6 +51,7 @@ interface CommittedValues {
values: string[];
options: string[];
showAllOption: boolean;
isDynamic: boolean;
emptyFallback: VariableSelection;
}
@@ -62,6 +63,7 @@ export function selectionFromCommittedValues({
values,
options,
showAllOption,
isDynamic,
emptyFallback,
}: CommittedValues): VariableSelection {
if (values.length === 0) {
@@ -71,10 +73,12 @@ export function selectionFromCommittedValues({
const customValues = values.filter((value) => !options.includes(value));
// ALL re-materializes to the option set, so a set carrying a typed value is not ALL
// — the next refetch would expand it back and drop what the user typed.
// A dynamic ALL travels as `__all__` and is never re-materialized, so a value outside
// its truncated list (a search pick, an older window's pick) loses nothing.
const allSelected =
showAllOption &&
options.length > 0 &&
customValues.length === 0 &&
(isDynamic || customValues.length === 0) &&
options.every((option) => values.includes(option));
return {