[Bug Report] Filtered 'Select All' in EnvModal discards selections from other filters
Bug Description
In the environment management modal (EnvModal.js), when environments are filtered using the search input, checking or unchecking the "Select All" checkbox overwrites or wipes all selections across the modal rather than scoping the operation to the visible filtered environments.
Specifically, in js/modals/EnvModal.js:
<input
type="checkbox"
style={{ marginRight: '8px' }}
disabled={!canWrite || selectableEnvs.length === 0}
checked={isAllSelected}
onChange={(ev) => {
setSelectedEnvs(ev.target.checked ? selectableEnvs : []);
}}
/>- When checking "Select All" with a filter active,
setSelectedEnvs(selectableEnvs)directly overwritesselectedEnvswith only the filtered items, silently discarding any environments previously selected under other search filters. - When unchecking "Select All" with a filter active,
setSelectedEnvs([])clears the entire selection across all environments in the modal, rather than deselecting only the visible filtered environments.
Individual environment checkboxes correctly preserve other selections via functional updates:
onChange={(ev) => {
if (ev.target.checked) {
setSelectedEnvs((prev) => Array.from(new Set([...prev, env])));
} else {
setSelectedEnvs((prev) => prev.filter((e) => e !== env));
}
}}However, the "Select All" checkbox does not use the existing selections and resets the state completely.
Reproduction Steps
- Launch Visdom with multiple environments (e.g.,
model_a_1,model_a_2,model_b_1,model_b_2). - Open the "Manage Environments" modal.
- In "Filter environments...", type
model_a. - Select
model_a_1(or click "Select All" to select allmodel_aenvironments). - In "Filter environments...", change the search term to
model_b. - Click "Select All" to include the
model_benvironments for batch deletion. - Observe that
model_a_1has been discarded fromselectedEnvs; onlymodel_benvironments are now selected. - Alternatively, with
model_a_1selected andmodel_bfiltered with "Select All" checked, uncheck "Select All". Notice all selections across all environments are cleared to[].
Expected behavior
- Checking "Select All" with a filter applied should add the visible selectable environments to the existing selection (union):
setSelectedEnvs((prev) => Array.from(new Set([...prev, ...selectableEnvs]))) - Unchecking "Select All" with a filter applied should only remove the visible selectable environments from the existing selection:
setSelectedEnvs((prev) => prev.filter((env) => !selectableSet.has(env)))
Client logs:
No errors are thrown in the console, but the state selectedEnvs is incorrectly overwritten/cleared.
Server logs: N/A (Frontend state management issue).
Additional context Environment filtering and batch deletion were introduced in #1791. The intention was to allow users to efficiently filter and delete runs matching naming patterns in batches; however, the inability to combine or refine selections across successive filter queries hinders batch operations.
Source: fossasia/visdom