Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(drive): show active filter counts and preserve menu selections (#7568)
Peter Chinmane142c6230c10
diff --git a/apps/web/src/components/view-shell/ListDropdowns.test.tsx b/apps/web/src/components/view-shell/ListDropdowns.test.tsxindex 5f55003567..988477610f 100644--- a/apps/web/src/components/view-shell/ListDropdowns.test.tsx+++ b/apps/web/src/components/view-shell/ListDropdowns.test.tsx@@ -11,7 +11,7 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';import { SearchableMultiSelect } from '../../features/next-soup/soup-view/filters-bar/searchable-multi-select';import { Dropdown } from '../ui/components/Dropdown';import type { AiFilterOutcome } from './AiFilterInput';-import { ListFilterDropdown } from './ListDropdowns';+import { ListFilterCountBadge, ListFilterDropdown } from './ListDropdowns';// Exercise the actual menus/comboboxes without initializing the app UI barrel.vi.mock('@ui', async () => ({@@ -105,6 +105,14 @@ function selectOption(element: HTMLElement, shiftKey = false) {);}+function pressOption(element: HTMLElement, shiftKey: boolean) {+ fireEvent(+ element,+ new MouseEvent('pointerdown', { button: 0, bubbles: true, shiftKey })+ );+ selectOption(element, shiftKey);+}+async function openSubmenu() {const trigger = await screen.findByRole('menuitem', { name: 'Assignee' });await waitFor(() => expect(document.activeElement).toBe(trigger));@@ -604,3 +612,95 @@ it('ignores Enter on an empty description and leaves the option rows reachable',expect(onSubmit).not.toHaveBeenCalled();expect(screen.getByRole('menuitem', { name: 'Assignee' })).toBeTruthy();});++it('keeps an option selectable when the group list is rebuilt mid-press', async () => {+ const [selected, setSelected] = createSignal<string[]>([]);+ const [revision, setRevision] = createSignal(0);+ const [open, setOpen] = createSignal(true);+ // Callers derive groups from queries and flags, so an unrelated settle can+ // hand the menu an equivalent-but-new array at any point in a press.+ const groups = () => {+ void revision();++ return [+ {+ id: 'people',+ label: 'Assignee',+ options: [+ { id: 'alice', label: 'Alice' },+ { id: 'bob', label: 'Bob' },+ ],+ },+ ];+ };+ render(() => (+ <ListFilterDropdown+ label="Filter tasks"+ open={open()}+ onOpenChange={setOpen}+ groups={groups()}+ isSelected={(_, id) => selected().includes(id)}+ onSelectionChange={(_, id, checked) =>+ setSelected((ids) =>+ checked ? [...ids, id] : ids.filter((value) => value !== id)+ )+ }+ />+ ));+ await openSubmenu();+ const option = await screen.findByRole('menuitemcheckbox', { name: 'Alice' });+ option.addEventListener('pointerdown', () => setRevision((n) => n + 1));++ pressOption(option, true);+ expect(selected()).toEqual(['alice']);+ expect(open()).toBe(true);+});++it('ties each group row to its id rather than its position', async () => {+ // Groups appear and disappear from the middle of the list, so a row reused+ // positionally would carry one group's open submenu over to another.+ const [withPriority, setWithPriority] = createSignal(false);+ const groups = () => [+ ...(withPriority()+ ? [+ {+ id: 'priority',+ label: 'Priority',+ options: [{ id: 'high', label: 'High' }],+ },+ ]+ : []),+ {+ id: 'people',+ label: 'Assignee',+ options: [{ id: 'alice', label: 'Alice' }],+ },+ ];+ render(() => (+ <ListFilterDropdown+ label="Filter tasks"+ open+ groups={groups()}+ isSelected={() => false}+ onSelectionChange={() => {}}+ />+ ));+ const assigneeRow = await screen.findByRole('menuitem', { name: 'Assignee' });++ setWithPriority(true);++ expect(screen.getByRole('menuitem', { name: 'Priority' })).toBeTruthy();+ expect(screen.getByRole('menuitem', { name: 'Assignee' })).toBe(assigneeRow);+});++it('shows the applied filter count only while filters are active', () => {+ const [count, setCount] = createSignal(0);+ const { container } = render(() => <ListFilterCountBadge count={count()} />);+ expect(container.textContent).toBe('');++ setCount(2);+ expect(container.textContent).toBe('2');++ setCount(0);+ expect(container.textContent).toBe('');+});diff --git a/apps/web/src/components/view-shell/ListDropdowns.tsx b/apps/web/src/components/view-shell/ListDropdowns.tsxindex 25a4dd81bc..2791d48040 100644--- a/apps/web/src/components/view-shell/ListDropdowns.tsx+++ b/apps/web/src/components/view-shell/ListDropdowns.tsx@@ -9,6 +9,7 @@ import BoardIcon from '@phosphor/kanban.svg';import ListIcon from '@phosphor/list-bullets.svg';import SortIcon from '@phosphor/sort-ascending.svg';import GroupIcon from '@phosphor/stack.svg';+import { Key } from '@solid-primitives/keyed';import { cn, Dropdown } from '@ui';import { batch, createSignal, For, type JSX, Show } from 'solid-js';import { AiFilterInput, type AiFilterInputProps } from './AiFilterInput';@@ -211,6 +212,21 @@ export type ListFilterDropdownProps<contentClass?: string;} & ListDropdownOpenProps;+/**+ * Overlays the number of applied filters on a `ListFilterDropdown` trigger, so+ * a collapsed menu still reveals that the list is filtered. Render it as a+ * sibling of the dropdown inside a `relative` wrapper.+ */+export function ListFilterCountBadge(props: { count: number }) {+ return (+ <Show when={props.count > 0}>+ <span class="pointer-events-none absolute -top-0.5 right-0 z-10 flex size-4 translate-x-1/2 items-center justify-center rounded-full bg-accent text-xxs font-medium leading-none text-surface">+ {props.count}+ </span>+ </Show>+ );+}+export function ListFilterDropdown<TGroupId extends string,TOptionId extends string,@@ -281,51 +297,62 @@ export function ListFilterDropdown<)}</Show><Dropdown.Group>- <For each={props.groups}>+ {/*+ * Keyed by group id, not by reference: callers derive their groups+ * from queries and flags, so an equivalent-but-new array can arrive+ * mid-interaction, and keying by reference would dispose the row and+ * its open submenu portal instead of updating them in place. Id is+ * still the right boundary — groups come and go from the middle of+ * the list, and a row must not carry one group's open submenu or+ * search text over to another.+ */}+ <Key each={props.groups} by="id">{(group) => (<Show- when={group.searchPlaceholder}+ when={group().searchPlaceholder}fallback={<FilterSubmenu- label={group.label}- selectionMode={group.selectionMode}- active={isGroupActive(group)}- options={group.options}- isSelected={(id) => props.isSelected(group.id, id)}+ label={group().label}+ selectionMode={group().selectionMode}+ active={isGroupActive(group())}+ options={group().options}+ isSelected={(id) => props.isSelected(group().id, id)}onSelect={(id) =>props.onSelectionChange(- group.id,+ group().id,id,- group.selectionMode === 'single' ||- !props.isSelected(group.id, id)+ group().selectionMode === 'single' ||+ !props.isSelected(group().id, id))}closeOnSelect={- group.selectionMode === 'single' ? true : 'unless-shift'+ group().selectionMode === 'single' ? true : 'unless-shift'}- contentClass={group.contentClass}+ contentClass={group().contentClass}/>}><SearchableFilterSubmenuonSelectionComplete={() => setOpen(false)}- label={group.label}- active={isGroupActive(group)}- options={() => group.options}+ label={group().label}+ active={isGroupActive(group())}+ options={() => group().options}activeIds={() =>- group.options- .filter((option) => props.isSelected(group.id, option.id))+ group()+ .options.filter((option) =>+ props.isSelected(group().id, option.id)+ ).map((option) => option.id)}onChange={(ids) =>batch(() => {- for (const option of group.options) {+ for (const option of group().options) {const selected = ids.includes(option.id);if (- selected !== props.isSelected(group.id, option.id)+ selected !== props.isSelected(group().id, option.id)) {props.onSelectionChange(- group.id,+ group().id,option.id,selected);@@ -333,11 +360,11 @@ export function ListFilterDropdown<}})}- placeholder={group.searchPlaceholder}+ placeholder={group().searchPlaceholder}/></Show>)}- </For>+ </Key></Dropdown.Group><Show when={props.onClear}>{(onClear) => (diff --git a/apps/web/src/components/view-shell/index.ts b/apps/web/src/components/view-shell/index.tsindex a98c8bb59a..cc1c98a477 100644--- a/apps/web/src/components/view-shell/index.ts+++ b/apps/web/src/components/view-shell/index.ts@@ -9,6 +9,7 @@ export {} from './collapsed-sections';export {type ListControlOption,+ ListFilterCountBadge,ListFilterDropdown,type ListFilterDropdownProps,type ListFilterGroup,diff --git a/apps/web/src/features/drive-view/views/drive-filter-menu.tsx b/apps/web/src/features/drive-view/views/drive-filter-menu.tsxindex 01b61124b3..fdf68a7811 100644--- a/apps/web/src/features/drive-view/views/drive-filter-menu.tsx+++ b/apps/web/src/features/drive-view/views/drive-filter-menu.tsx@@ -1,4 +1,5 @@import {+ ListFilterCountBadge,ListFilterDropdown,useViewControlHotkeys,} from '@app/components/view-shell';@@ -28,14 +29,17 @@ export function DriveFilterMenu() {});return (- <ListFilterDropdown- label="Filter files"- open={open()}- onOpenChange={setOpen}- groups={filters.groups()}- onClear={filters.clear}- isSelected={filters.isSelected}- onSelectionChange={filters.setSelected}- />+ <div class="relative shrink-0">+ <ListFilterDropdown+ label="Filter files"+ open={open()}+ onOpenChange={setOpen}+ groups={filters.groups()}+ onClear={filters.clear}+ isSelected={filters.isSelected}+ onSelectionChange={filters.setSelected}+ />+ <ListFilterCountBadge count={filters.activeCount()} />+ </div>);}diff --git a/apps/web/src/features/email-view/components/EmailControls.tsx b/apps/web/src/features/email-view/components/EmailControls.tsxindex 1cda5aa1bb..93db95004a 100644--- a/apps/web/src/features/email-view/components/EmailControls.tsx+++ b/apps/web/src/features/email-view/components/EmailControls.tsx@@ -1,4 +1,7 @@-import { ListFilterDropdown } from '@app/components/view-shell';+import {+ ListFilterCountBadge,+ ListFilterDropdown,+} from '@app/components/view-shell';import { TOKENS } from '@core/hotkey/tokens';import { isTouchDevice } from '@core/mobile/isTouchDevice';import ColumnsIcon from '@phosphor/columns.svg';@@ -42,11 +45,7 @@ export function EmailControls(props: EmailControlsProps) {onSelectionChange={filters.setSelected}onClear={filters.clear}/>- <Show when={filters.activeCount() > 0}>- <span class="pointer-events-none absolute -top-0.5 right-0 z-10 flex size-4 translate-x-1/2 items-center justify-center rounded-full bg-accent text-xxs font-medium leading-none text-surface">- {filters.activeCount()}- </span>- </Show>+ <ListFilterCountBadge count={filters.activeCount()} /></div></div>);diff --git a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsxindex d3c884fd5c..5de24deea3 100644--- a/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx+++ b/apps/web/src/features/next-soup/soup-view/filters-bar/filter-menu.tsx@@ -1,5 +1,6 @@import CaretRightIcon from '@phosphor/caret-right.svg';import CheckIcon from '@phosphor/check.svg';+import { Key } from '@solid-primitives/keyed';import { debounce } from '@solid-primitives/scheduled';import { cn, Dropdown } from '@ui';import type { SelectionDismissal } from '@ui/utils/selectionDismissal';@@ -7,7 +8,6 @@ import {type Accessor,createEffect,createSignal,- For,type JSX,onCleanup,Show,@@ -285,19 +285,22 @@ export function FilterSubmenu<TId extends string>(props: {<Showwhen={props.selectionMode === 'single'}fallback={- <For each={props.options}>+ // Keyed by option id, not by reference: callers rebuild their+ // option arrays whenever an upstream query or flag settles, and+ // disposing a row mid-press would swallow the selection.+ <Key each={props.options} by="id">{(option) => (<FilterOptionItem- label={option.label}- icon={option.icon}- content={option.content}- disabled={option.disabled}- active={props.isSelected(option.id)}- onSelect={() => props.onSelect(option.id)}+ label={option().label}+ icon={option().icon}+ content={option().content}+ disabled={option().disabled}+ active={props.isSelected(option().id)}+ onSelect={() => props.onSelect(option().id)}closeOnSelect={props.closeOnSelect}/>)}- </For>+ </Key>}><Dropdown.RadioGroup@@ -309,31 +312,31 @@ export function FilterSubmenu<TId extends string>(props: {if (option) props.onSelect(option.id);}}>- <For each={props.options}>+ <Key each={props.options} by="id">{(option) => (<Dropdown.RadioItem- value={option.id}- disabled={option.disabled}+ value={option().id}+ disabled={option().disabled}closeOnSelect={props.closeOnSelect === 'unless-shift'? true: props.closeOnSelect}>- <Show when={option.icon}>+ <Show when={option().icon}><span class="size-4 flex items-center justify-center shrink-0">- {option.icon?.()}+ {option().icon?.()}</span></Show><span class="flex-1">- {option.content?.() ?? option.label}+ {option().content?.() ?? option().label}</span><Dropdown.ItemIndicator><CheckIcon class="size-3.5 text-accent" /></Dropdown.ItemIndicator></Dropdown.RadioItem>)}- </For>+ </Key></Dropdown.RadioGroup></Show></Dropdown.Group>diff --git a/apps/web/src/features/projects/views/projects-collection.test.tsx b/apps/web/src/features/projects/views/projects-collection.test.tsxindex a05527ceb8..6c54a5fd44 100644--- a/apps/web/src/features/projects/views/projects-collection.test.tsx+++ b/apps/web/src/features/projects/views/projects-collection.test.tsx@@ -52,6 +52,7 @@ vi.mock('@app/components/view-shell', () => ({ListSortDropdown: () => null,ListGroupDropdown: () => null,ListFilterDropdown: () => null,+ ListFilterCountBadge: () => null,ViewLayoutDropdown: (props: {label: string;layouts: ('list' | 'board' | 'gantt')[];diff --git a/apps/web/src/features/projects/views/projects-collection.tsx b/apps/web/src/features/projects/views/projects-collection.tsxindex 0e4b99c54f..003880ea69 100644--- a/apps/web/src/features/projects/views/projects-collection.tsx+++ b/apps/web/src/features/projects/views/projects-collection.tsx@@ -4,6 +4,7 @@ import { ganttGroupPlacement } from '@app/components/gantt/gantt-group-placementimport { useListInteractions } from '@app/components/list';import { ListViewport } from '@app/components/list/ListViewport';import {+ ListFilterCountBadge,ListFilterDropdown,type ListFilterGroup,ListGroupDropdown,@@ -509,11 +510,7 @@ export function ProjectsCollection(props: {}}onClear={clearFilters}/>- <Show when={activeCount()}>- <span class="pointer-events-none absolute -top-0.5 right-0 z-10 flex size-4 translate-x-1/2 items-center justify-center rounded-full bg-accent text-xxs font-medium leading-none text-surface">- {activeCount()}- </span>- </Show>+ <ListFilterCountBadge count={activeCount()} /></div><Dropdown><Dropdown.Triggerdiff --git a/apps/web/src/features/reviews-view/components/ReviewsControls.tsx b/apps/web/src/features/reviews-view/components/ReviewsControls.tsxindex 709c0f830b..f0d947bc60 100644--- a/apps/web/src/features/reviews-view/components/ReviewsControls.tsx+++ b/apps/web/src/features/reviews-view/components/ReviewsControls.tsx@@ -1,5 +1,6 @@import {type ListControlOption,+ ListFilterCountBadge,ListFilterDropdown,type ListFilterGroup,ListSortDropdown,@@ -16,7 +17,7 @@ import { PR_ORIGIN_LABELS, PR_ORIGIN_TOOLS } from '@block-pr/data/pr-origin';import { MobileDrawer } from '@components/app/mobile/MobileDrawer';import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { Accordion } from '@kobalte/core/accordion';-import { createSignal, For, Show } from 'solid-js';+import { createSignal, For } from 'solid-js';import { UNKNOWN_ORIGIN } from '../reviews-filter';import type {ReviewsFilterId,@@ -199,11 +200,7 @@ export function ReviewsControls(props: ReviewsControlProps) {onSelectionChange={props.onFilterChange}onClear={props.onClearFilters}/>- <Show when={activeCount() > 0}>- <span class="pointer-events-none absolute -top-0.5 right-0 z-10 flex size-4 translate-x-1/2 items-center justify-center rounded-full bg-accent text-xxs font-medium leading-none text-surface">- {activeCount()}- </span>- </Show>+ <ListFilterCountBadge count={activeCount()} /></div></div>);diff --git a/apps/web/src/features/tasks-view/components/TasksControls.tsx b/apps/web/src/features/tasks-view/components/TasksControls.tsxindex 4042b84048..af5b69c3bf 100644--- a/apps/web/src/features/tasks-view/components/TasksControls.tsx+++ b/apps/web/src/features/tasks-view/components/TasksControls.tsx@@ -1,4 +1,5 @@import {+ ListFilterCountBadge,ListFilterDropdown,ListGroupDropdown,ListSortDropdown,@@ -129,11 +130,7 @@ function DesktopTasksControls() {onSubmit: filters.applyDescription,}}/>- <Show when={filters.activeCount() > 0}>- <span class="pointer-events-none absolute -top-0.5 right-0 z-10 flex size-4 translate-x-1/2 items-center justify-center rounded-full bg-accent text-xxs font-medium leading-none text-surface">- {filters.activeCount()}- </span>- </Show>+ <ListFilterCountBadge count={filters.activeCount()} /></div></div>);diff --git a/docs/agent-guide/files.md b/docs/agent-guide/files.mdindex 42c6bf5cfb..2067ebec9a 100644--- a/docs/agent-guide/files.md+++ b/docs/agent-guide/files.md@@ -103,8 +103,12 @@ and **Created by** submenus alongside **Files** for Default, All files, and Emaiattachments. Options within a group match any selected option; different groupscombine to narrow the results. Created by is hidden while My Filesis restricted to your own files. Recent offers only file-scope filtering.-Hold Shift while selecting or deselecting Type options to keep the submenu open-and combine several file types without reopening it. Desktop filter submenus allow a+The desktop Filter trigger shows the number of active filters, matching the+mobile drawer; clearing all filters removes the badge. Hold Shift while selecting+or deselecting Type options to keep the submenu open and combine several file+types without reopening it. A normal selection closes the menu. Verify the badge+tracks consecutive selections (1 → 2 → 1), including when filter groups refresh+while the menu is open. Desktop filter submenus allow a250 ms grace period when the mouse crosses the parent menu's padding; enteringthe submenu cancels the pending close. While the mouse heads toward an opensubmenu, including one that opens to the left, the categories it crosses on the