Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(task): find in view on the Tasks page with Mod+F (#22960)

Rdmclin2326ed792a75e
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index d50ab3985ec..2274d3c20f5 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -2832,6 +2832,9 @@
"taskList.filter.window.month": "Past month",
"taskList.filter.window.quarter": "Past 3 months",
"taskList.filter.window.week": "Past week",
+ "taskList.find.clear": "Clear search",
+ "taskList.find.open": "Find in view",
+ "taskList.find.placeholder": "Find in view…",
"taskList.form.columns": "Columns",
"taskList.form.completedTasks": "Completed & canceled",
"taskList.form.grouping": "Grouping",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index a8e4b9ab3ec..1431ecb6f6d 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -2832,6 +2832,9 @@
"taskList.filter.window.month": "过去 1 个月",
"taskList.filter.window.quarter": "过去 3 个月",
"taskList.filter.window.week": "过去 1 周",
+ "taskList.find.clear": "清除搜索",
+ "taskList.find.open": "在当前视图中查找",
+ "taskList.find.placeholder": "在当前视图中查找…",
"taskList.form.columns": "列",
"taskList.form.completedTasks": "已完成与已取消",
"taskList.form.grouping": "分组",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index c084bff06eb..569e9a32fd0 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -4434,5 +4434,8 @@ export default {
'taskProject.searchPlaceholder': 'Search projects…',
'taskProject.unavailable': 'Unavailable project',
'taskList.filter.field.label': 'Label',
+ 'taskList.find.clear': 'Clear search',
+ 'taskList.find.open': 'Find in view',
+ 'taskList.find.placeholder': 'Find in view…',
'taskList.groupBy.labelGroup': 'Label: {{name}}',
};
diff --git a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
index 3b53bab4f10..1d1826030d1 100644
--- a/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
+++ b/src/features/AgentTasks/AgentTaskList/AgentTasksPage.tsx
@@ -37,9 +37,11 @@ import CreateTaskInlineEntry from './CreateTaskInlineEntry';
import EmptyState from './EmptyState';
import {
pickOfferedTaskFilter,
+ setTaskFilterContent,
TaskFilterBar,
TaskFilterButton,
taskListFilterScopeKey,
+ TaskListFind,
useTaskFilterFields,
useTaskListFilter,
} from './filter';
@@ -470,6 +472,10 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
}, [agentId, canCreateTask, navigate, projectId]);
const handleClearFilter = useCallback(() => setFilter(() => undefined), [setFilter]);
+ const handleFindChange = useCallback(
+ (content: string) => setFilter((prev) => setTaskFilterContent(prev, content)),
+ [setFilter],
+ );
const filterEmptyAction = hasFilter ? (
<Button onClick={handleClearFilter}>{t('taskList.filter.clearAll')}</Button>
) : undefined;
@@ -520,6 +526,9 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
mobileSurface: isMobileSurface(),
projectId,
});
+ // Find is a keyboard-first desktop entry; the narrow header keeps the filter menu's
+ // "Content contains" for the same condition.
+ const showFind = !isMobile && (headerVisibility.showViewOptions || hasFilter);
const headerLeft = (
<Flexbox horizontal align={'center'} gap={8}>
@@ -550,6 +559,7 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
left={headerLeft}
right={
<Flexbox horizontal align={'center'} gap={4}>
+ {showFind && <TaskListFind content={filter?.content} onChange={handleFindChange} />}
{(headerVisibility.showViewOptions || hasFilter) && (
<TaskFilterButton fields={filterFields} filter={filter} setFilter={setFilter} />
)}
@@ -597,7 +607,12 @@ const AgentTasksPage = memo<AgentTasksPageProps>(({ agentId, headerActions, proj
},
}}
/>
- <TaskFilterBar fields={filterFields} filter={filter} setFilter={setFilter} />
+ <TaskFilterBar
+ fields={filterFields}
+ filter={filter}
+ hideContent={showFind}
+ setFilter={setFilter}
+ />
{isMineBoard ? (
<Flexbox flex={1} style={{ overflowX: 'auto', overflowY: 'hidden' }}>
<KanbanBoard
diff --git a/src/features/AgentTasks/AgentTaskList/filter/TaskFilterBar.tsx b/src/features/AgentTasks/AgentTaskList/filter/TaskFilterBar.tsx
index fb60df428c4..17198ceb38e 100644
--- a/src/features/AgentTasks/AgentTaskList/filter/TaskFilterBar.tsx
+++ b/src/features/AgentTasks/AgentTaskList/filter/TaskFilterBar.tsx
@@ -27,12 +27,14 @@ import {
setTaskFilterContent,
setTaskFilterDateWindow,
showsTaskFilterValuesInline,
+ taskFilterBarConditions,
taskFilterSetOperatorKey,
type TaskFilterValue,
toggleTaskFilterOperator,
toggleTaskFilterValue,
} from './taskFilterState';
import type { TaskFilterFieldDef, TaskFilterSetFieldDef } from './useTaskFilterFields';
+import { TASK_FILTER_CONTENT_COMMIT_DELAY_MS } from './useTaskListFind';
const styles = stylex.create({
bar: {
@@ -58,6 +60,8 @@ const styles = stylex.create({
contentInput: {
backgroundColor: 'transparent',
borderStyle: 'none',
+ // The chip's own frame replaces the global ring; keyboard focus still shows inside it.
+ boxShadow: { 'default': 'none', ':focus-visible': `inset 0 0 0 1px ${cssVar.colorPrimary}` },
color: cssVar.colorText,
fontSize: 12,
outline: 'none',
@@ -86,12 +90,11 @@ const styles = stylex.create({
},
});
-/** Content typed into the chip is committed after this pause, like a search box. */
-const CONTENT_COMMIT_DELAY_MS = 400;
-
interface TaskFilterBarProps {
fields: TaskFilterFieldDef[];
filter?: TaskListFilter;
+ /** The header's find box shows the `content` condition, so the bar leaves it out. */
+ hideContent?: boolean;
setFilter: (updater: (prev: TaskListFilter | undefined) => TaskListFilter | undefined) => void;
}
@@ -138,7 +141,7 @@ const ContentInput = memo<{ onCommit: (value: string) => void; value: string }>(
useEffect(() => setDraft(value), [value]);
useEffect(() => {
if (draft.trim() === value) return;
- const timer = setTimeout(() => onCommit(draft), CONTENT_COMMIT_DELAY_MS);
+ const timer = setTimeout(() => onCommit(draft), TASK_FILTER_CONTENT_COMMIT_DELAY_MS);
return () => clearTimeout(timer);
}, [draft, onCommit, value]);
@@ -163,155 +166,162 @@ ContentInput.displayName = 'TaskFilterContentInput';
* `[field] [operator] [values] [×]`. The operator flips on click, the values
* reopen the value menu, × drops the condition; "Clear" drops them all.
*/
-const TaskFilterBar = memo<TaskFilterBarProps>(({ fields, filter, setFilter }) => {
- const { t } = useTranslation('chat');
-
- if (!filter) return null;
+const TaskFilterBar = memo<TaskFilterBarProps>(
+ ({ fields, filter: activeFilter, hideContent = false, setFilter }) => {
+ const { t } = useTranslation('chat');
- const removeButton = (field: Parameters<typeof removeTaskFilterField>[1]) => (
- <Segment
- title={t('taskList.filter.remove')}
- onClick={() => setFilter((prev) => removeTaskFilterField(prev, field))}
- >
- <Icon icon={XIcon} size={12} />
- </Segment>
- );
-
- const renderSetChip = (field: TaskFilterSetFieldDef) => {
- const set = filter[field.key] as TaskListFilterSet<TaskFilterValue> | undefined;
- if (!set) return null;
- const selected = set.values.map(
- (value) =>
- field.options.find((option) => option.value === value) ?? {
- // A value whose option is gone (a deleted agent, a member who left)
- // still renders, so it can be seen and removed.
- icon: undefined,
- label: t('taskList.filter.unknownValue'),
- value,
- },
- );
- const summary = showsTaskFilterValuesInline(selected.length)
- ? selected.map((option) => option.label).join(', ')
- : t('taskList.filter.valueCount', { count: selected.length });
- const valueItems: DropdownItem[] = field.options.map((option) => ({
- checked: isTaskFilterValueSelected(filter, field.key, option.value),
- closeOnClick: false,
- icon: option.icon,
- key: `${field.key}:${option.value}`,
- label: option.label,
- onCheckedChange: () =>
- setFilter((prev) => toggleTaskFilterValue(prev, field.key, option.value)),
- type: 'checkbox' as const,
- }));
+ // Nothing left to show as a chip: a lone "Clear" would only repeat the find box.
+ const filter = taskFilterBarConditions(activeFilter, hideContent);
+ if (!filter) return null;
- return (
- <span
- {...stylex.props(styles.chip)}
- data-testid={`task-filter-chip-${field.key}`}
- key={field.key}
+ const removeButton = (field: Parameters<typeof removeTaskFilterField>[1]) => (
+ <Segment
+ title={t('taskList.filter.remove')}
+ onClick={() => setFilter((prev) => removeTaskFilterField(prev, field))}
>
- <Segment>
- <Icon color={cssVarJs.colorTextSecondary} icon={field.icon} size={14} />
- {field.label}
- </Segment>
- <Segment
- secondary
- onClick={() => setFilter((prev) => toggleTaskFilterOperator(prev, field.key))}
- >
- {t(taskFilterSetOperatorKey(set.operator, set.values.length))}
- </Segment>
- <DropdownMenu items={valueItems}>
- <span
- {...stylex.props(styles.segment, styles.segmentButton)}
- role={'button'}
- tabIndex={0}
- >
- {showsTaskFilterValuesInline(selected.length) &&
- selected.map((option) => (
- <span key={String(option.value)} style={{ display: 'inline-flex' }}>
- {option.icon}
- </span>
- ))}
- {summary}
- </span>
- </DropdownMenu>
- {removeButton(field.key)}
- </span>
+ <Icon icon={XIcon} size={12} />
+ </Segment>
);
- };
- const renderDateChip = (field: {
- icon: TaskFilterFieldDef['icon'];
- key: TaskListFilterDateField;
- label: string;
- }) => {
- const date = filter[field.key];
- if (!date) return null;
- const windowItems: DropdownItem[] = TASK_LIST_FILTER_DATE_WINDOWS.map((window) => ({
- checked: date.window === window,
- key: `${field.key}:${window}`,
- label: t(`taskList.filter.window.${window}`),
- onCheckedChange: () => setFilter((prev) => setTaskFilterDateWindow(prev, field.key, window)),
- type: 'checkbox' as const,
- }));
+ const renderSetChip = (field: TaskFilterSetFieldDef) => {
+ const set = filter[field.key] as TaskListFilterSet<TaskFilterValue> | undefined;
+ if (!set) return null;
+ const selected = set.values.map(
+ (value) =>
+ field.options.find((option) => option.value === value) ?? {
+ // A value whose option is gone (a deleted agent, a member who left)
+ // still renders, so it can be seen and removed.
+ icon: undefined,
+ label: t('taskList.filter.unknownValue'),
+ value,
+ },
+ );
+ const summary = showsTaskFilterValuesInline(selected.length)
+ ? selected.map((option) => option.label).join(', ')
+ : t('taskList.filter.valueCount', { count: selected.length });
+ const valueItems: DropdownItem[] = field.options.map((option) => ({
+ checked: isTaskFilterValueSelected(filter, field.key, option.value),
+ closeOnClick: false,
+ icon: option.icon,
+ key: `${field.key}:${option.value}`,
+ label: option.label,
+ onCheckedChange: () =>
+ setFilter((prev) => toggleTaskFilterValue(prev, field.key, option.value)),
+ type: 'checkbox' as const,
+ }));
- return (
- <span
- {...stylex.props(styles.chip)}
- data-testid={`task-filter-chip-${field.key}`}
- key={field.key}
- >
- <Segment>
- <Icon color={cssVarJs.colorTextSecondary} icon={field.icon} size={14} />
- {field.label}
- </Segment>
- <Segment
- secondary
- onClick={() => setFilter((prev) => toggleTaskFilterOperator(prev, field.key))}
+ return (
+ <span
+ {...stylex.props(styles.chip)}
+ data-testid={`task-filter-chip-${field.key}`}
+ key={field.key}
>
- {t(
- date.operator === 'before'
- ? 'taskList.filter.operator.before'
- : 'taskList.filter.operator.within',
- )}
- </Segment>
- <DropdownMenu items={windowItems}>
- <span
- {...stylex.props(styles.segment, styles.segmentButton)}
- role={'button'}
- tabIndex={0}
+ <Segment>
+ <Icon color={cssVarJs.colorTextSecondary} icon={field.icon} size={14} />
+ {field.label}
+ </Segment>
+ <Segment
+ secondary
+ onClick={() => setFilter((prev) => toggleTaskFilterOperator(prev, field.key))}
>
- {t(`taskList.filter.window.${date.window}`)}
- </span>
- </DropdownMenu>
- {removeButton(field.key)}
- </span>
- );
- };
+ {t(taskFilterSetOperatorKey(set.operator, set.values.length))}
+ </Segment>
+ <DropdownMenu items={valueItems}>
+ <span
+ {...stylex.props(styles.segment, styles.segmentButton)}
+ role={'button'}
+ tabIndex={0}
+ >
+ {showsTaskFilterValuesInline(selected.length) &&
+ selected.map((option) => (
+ <span key={String(option.value)} style={{ display: 'inline-flex' }}>
+ {option.icon}
+ </span>
+ ))}
+ {summary}
+ </span>
+ </DropdownMenu>
+ {removeButton(field.key)}
+ </span>
+ );
+ };
- return (
- <Flexbox horizontal align={'center'} {...stylex.props(styles.bar)} gap={6}>
- {fields.map((field) => (field.kind === 'set' ? renderSetChip(field) : renderDateChip(field)))}
- {filter.content && (
- <span {...stylex.props(styles.chip)} data-testid={'task-filter-chip-content'}>
+ const renderDateChip = (field: {
+ icon: TaskFilterFieldDef['icon'];
+ key: TaskListFilterDateField;
+ label: string;
+ }) => {
+ const date = filter[field.key];
+ if (!date) return null;
+ const windowItems: DropdownItem[] = TASK_LIST_FILTER_DATE_WINDOWS.map((window) => ({
+ checked: date.window === window,
+ key: `${field.key}:${window}`,
+ label: t(`taskList.filter.window.${window}`),
+ onCheckedChange: () =>
+ setFilter((prev) => setTaskFilterDateWindow(prev, field.key, window)),
+ type: 'checkbox' as const,
+ }));
+
+ return (
+ <span
+ {...stylex.props(styles.chip)}
+ data-testid={`task-filter-chip-${field.key}`}
+ key={field.key}
+ >
<Segment>
- <Icon color={cssVarJs.colorTextSecondary} icon={TextSearchIcon} size={14} />
- {t('taskList.filter.field.content')}
+ <Icon color={cssVarJs.colorTextSecondary} icon={field.icon} size={14} />
+ {field.label}
</Segment>
- <Segment secondary>{t('taskList.filter.operator.contains')}</Segment>
- <ContentInput
- value={filter.content}
- onCommit={(value) => setFilter((prev) => setTaskFilterContent(prev, value))}
- />
- {removeButton('content')}
+ <Segment
+ secondary
+ onClick={() => setFilter((prev) => toggleTaskFilterOperator(prev, field.key))}
+ >
+ {t(
+ date.operator === 'before'
+ ? 'taskList.filter.operator.before'
+ : 'taskList.filter.operator.within',
+ )}
+ </Segment>
+ <DropdownMenu items={windowItems}>
+ <span
+ {...stylex.props(styles.segment, styles.segmentButton)}
+ role={'button'}
+ tabIndex={0}
+ >
+ {t(`taskList.filter.window.${date.window}`)}
+ </span>
+ </DropdownMenu>
+ {removeButton(field.key)}
</span>
- )}
- <Button size={'small'} type={'text'} onClick={() => setFilter(() => undefined)}>
- {t('taskList.filter.clear')}
- </Button>
- </Flexbox>
- );
-});
+ );
+ };
+
+ return (
+ <Flexbox horizontal align={'center'} {...stylex.props(styles.bar)} gap={6}>
+ {fields.map((field) =>
+ field.kind === 'set' ? renderSetChip(field) : renderDateChip(field),
+ )}
+ {filter.content && (
+ <span {...stylex.props(styles.chip)} data-testid={'task-filter-chip-content'}>
+ <Segment>
+ <Icon color={cssVarJs.colorTextSecondary} icon={TextSearchIcon} size={14} />
+ {t('taskList.filter.field.content')}
+ </Segment>
+ <Segment secondary>{t('taskList.filter.operator.contains')}</Segment>
+ <ContentInput
+ value={filter.content}
+ onCommit={(value) => setFilter((prev) => setTaskFilterContent(prev, value))}
+ />
+ {removeButton('content')}
+ </span>
+ )}
+ <Button size={'small'} type={'text'} onClick={() => setFilter(() => undefined)}>
+ {t('taskList.filter.clear')}
+ </Button>
+ </Flexbox>
+ );
+ },
+);
TaskFilterBar.displayName = 'TaskFilterBar';
diff --git a/src/features/AgentTasks/AgentTaskList/filter/TaskListFind.tsx b/src/features/AgentTasks/AgentTaskList/filter/TaskListFind.tsx
new file mode 100644
index 00000000000..e57a614c3a1
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/filter/TaskListFind.tsx
@@ -0,0 +1,117 @@
+'use client';
+
+import { HotkeyEnum, HotkeyScopeEnum } from '@lobechat/const/hotkeys';
+import { ActionIcon, Icon, Input } from '@lobehub/ui';
+import { SearchIcon, XIcon } from 'lucide-react';
+import type { KeyboardEvent } from 'react';
+import { memo, useEffect, useRef } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';
+import { useHotkeyById } from '@/hooks/useHotkeys/useHotkeyById';
+import { useUserStore } from '@/store/user';
+import { settingsSelectors } from '@/store/user/selectors';
+
+import { useTaskListFind } from './useTaskListFind';
+
+interface TaskListFindProps {
+ /** The list's `content` filter: what the box shows and edits. */
+ content?: string;
+ onChange: (content: string) => void;
+}
+
+/**
+ * "Find in view" of the Tasks page, after Linear: Mod+F opens a search box in
+ * the header that narrows the current view by text. It edits the same
+ * server-side `content` condition the filter menu offers, so every collection
+ * (list, board, scheduled, "My tasks") narrows the same way, and a condition
+ * picked from the menu shows here too.
+ *
+ * Mod+F reuses the "find" binding the conversation and the task detail own
+ * (one key, one meaning: find in what is open), so a rebind moves all three.
+ */
+const TaskListFind = memo<TaskListFindProps>(({ content, onChange }) => {
+ const { t } = useTranslation('chat');
+ const findHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.FindInTopic));
+ const inputRef = useRef<HTMLInputElement>(null);
+ const { blur, clearAndClose, commit, draft, expanded, focus, focusRequest, openFind, setDraft } =
+ useTaskListFind({ content, onChange });
+
+ useHotkeyById(HotkeyEnum.FindInTopic, openFind, {
+ enableOnContentEditable: true,
+ enabled: true,
+ scopes: [HotkeyScopeEnum.Global],
+ });
+
+ useEffect(() => {
+ if (focusRequest === 0) return;
+ // The box mounts in the same commit that opens it; focus once it is there.
+ const timer = setTimeout(() => {
+ inputRef.current?.focus();
+ inputRef.current?.select();
+ });
+ return () => clearTimeout(timer);
+ }, [focusRequest]);
+
+ const close = () => {
+ clearAndClose();
+ inputRef.current?.blur();
+ };
+
+ const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ event.stopPropagation();
+ close();
+ } else if (event.key === 'Enter') {
+ event.preventDefault();
+ commit();
+ }
+ };
+
+ if (!expanded) {
+ return (
+ <ActionIcon
+ icon={SearchIcon}
+ size={DESKTOP_HEADER_ICON_SMALL_SIZE}
+ title={t('taskList.find.open')}
+ tooltipProps={{ hotkey: findHotkey, placement: 'bottom' }}
+ onClick={openFind}
+ />
+ );
+ }
+
+ return (
+ <Input
+ aria-label={t('taskList.find.placeholder')}
+ data-testid={'task-list-find'}
+ placeholder={t('taskList.find.placeholder')}
+ prefix={<Icon icon={SearchIcon} size={14} />}
+ ref={inputRef}
+ size={'small'}
+ style={{ width: 220 }}
+ value={draft}
+ variant={'filled'}
+ suffix={
+ draft ? (
+ <ActionIcon
+ icon={XIcon}
+ size={'small'}
+ title={t('taskList.find.clear')}
+ onClick={close}
+ // Keep the input focused until the click lands, so its blur does not close first.
+ onMouseDown={(event) => event.preventDefault()}
+ />
+ ) : undefined
+ }
+ onBlur={blur}
+ onChange={(event) => setDraft(event.target.value)}
+ onFocus={focus}
+ onKeyDown={handleKeyDown}
+ />
+ );
+});
+
+TaskListFind.displayName = 'TaskListFind';
+
+export default TaskListFind;
diff --git a/src/features/AgentTasks/AgentTaskList/filter/index.ts b/src/features/AgentTasks/AgentTaskList/filter/index.ts
index b5d6249889b..dca5e13bf39 100644
--- a/src/features/AgentTasks/AgentTaskList/filter/index.ts
+++ b/src/features/AgentTasks/AgentTaskList/filter/index.ts
@@ -1,5 +1,10 @@
export { default as TaskFilterBar } from './TaskFilterBar';
export { default as TaskFilterButton } from './TaskFilterButton';
-export { pickOfferedTaskFilter, taskListFilterScopeKey } from './taskFilterState';
+export {
+ pickOfferedTaskFilter,
+ setTaskFilterContent,
+ taskListFilterScopeKey,
+} from './taskFilterState';
+export { default as TaskListFind } from './TaskListFind';
export { useTaskFilterFields } from './useTaskFilterFields';
export { useTaskListFilter } from './useTaskListFilter';
diff --git a/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.test.ts b/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.test.ts
index f3cc5917ebe..f919b18bfed 100644
--- a/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.test.ts
+++ b/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.test.ts
@@ -8,6 +8,7 @@ import {
setTaskFilterContent,
setTaskFilterDateWindow,
showsTaskFilterValuesInline,
+ taskFilterBarConditions,
taskFilterSetOperatorKey,
taskListFilterScopeKey,
toggleTaskFilterOperator,
@@ -146,3 +147,20 @@ describe('set chip display', () => {
expect(showsTaskFilterValuesInline(3)).toBe(false);
});
});
+
+describe('taskFilterBarConditions', () => {
+ const status = { operator: 'is' as const, values: ['running'] };
+
+ it('keeps every condition when the header has no find box', () => {
+ expect(taskFilterBarConditions({ content: 'deploy' }, false)).toEqual({ content: 'deploy' });
+ });
+
+ it('leaves the content condition to the find box', () => {
+ expect(taskFilterBarConditions({ content: 'deploy', status }, true)).toEqual({ status });
+ });
+
+ it('has nothing to render when the find box holds the only condition', () => {
+ expect(taskFilterBarConditions({ content: 'deploy' }, true)).toBeUndefined();
+ expect(taskFilterBarConditions(undefined, true)).toBeUndefined();
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.ts b/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.ts
index c28a656cd6b..27699f7ee5f 100644
--- a/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.ts
+++ b/src/features/AgentTasks/AgentTaskList/filter/taskFilterState.ts
@@ -136,6 +136,16 @@ export const removeTaskFilterField = (
return normalizeTaskListFilter(rest);
};
+/**
+ * The conditions the chip bar under the header renders. With the header's find
+ * box up, the `content` condition lives there instead of in a second chip.
+ */
+export const taskFilterBarConditions = (
+ filter: TaskListFilter | undefined,
+ hideContent: boolean,
+): TaskListFilter | undefined =>
+ hideContent ? removeTaskFilterField(filter, 'content') : normalizeTaskListFilter(filter);
+
/**
* The part of a stored filter this page can show and edit. A condition on a
* field the page does not offer (a member field once the page has no member
diff --git a/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.test.ts b/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.test.ts
new file mode 100644
index 00000000000..1f5defa39af
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.test.ts
@@ -0,0 +1,137 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { act, renderHook } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { TASK_FILTER_CONTENT_COMMIT_DELAY_MS, useTaskListFind } from './useTaskListFind';
+
+const setup = (content?: string) => {
+ const onChange = vi.fn();
+ const hook = renderHook(
+ ({ value }: { value?: string }) => useTaskListFind({ content: value, onChange }),
+ { initialProps: { value: content } },
+ );
+ return { ...hook, onChange };
+};
+
+describe('useTaskListFind', () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('starts collapsed with no text condition, and Mod+F opens it with a focus request', () => {
+ const { result } = setup();
+ expect(result.current.expanded).toBe(false);
+
+ act(() => result.current.openFind());
+
+ expect(result.current.expanded).toBe(true);
+ expect(result.current.focusRequest).toBe(1);
+
+ // A repeat press asks to re-select the text.
+ act(() => result.current.openFind());
+ expect(result.current.focusRequest).toBe(2);
+ });
+
+ it('commits the typed text after the pause, not on every keystroke', () => {
+ const { result, onChange } = setup();
+ act(() => result.current.openFind());
+
+ act(() => result.current.setDraft('dep'));
+ act(() => result.current.setDraft('deploy'));
+ act(() => {
+ vi.advanceTimersByTime(TASK_FILTER_CONTENT_COMMIT_DELAY_MS - 1);
+ });
+ expect(onChange).not.toHaveBeenCalled();
+
+ act(() => {
+ vi.advanceTimersByTime(1);
+ });
+ expect(onChange).toHaveBeenCalledTimes(1);
+ expect(onChange).toHaveBeenCalledWith('deploy');
+ });
+
+ it('commits at once on Enter', () => {
+ const { result, onChange } = setup();
+ act(() => result.current.setDraft('T-12'));
+
+ act(() => result.current.commit());
+
+ expect(onChange).toHaveBeenCalledWith('T-12');
+ });
+
+ it('shows an active text condition in the box', () => {
+ const { result } = setup('billing');
+
+ expect(result.current.expanded).toBe(true);
+ expect(result.current.draft).toBe('billing');
+ });
+
+ it('clears the condition and closes on Escape without re-committing on the blur that follows', () => {
+ const { result, rerender, onChange } = setup('billing');
+
+ act(() => result.current.clearAndClose());
+ act(() => result.current.blur());
+
+ expect(onChange).toHaveBeenCalledTimes(1);
+ expect(onChange).toHaveBeenCalledWith('');
+
+ rerender({ value: undefined });
+ expect(result.current.expanded).toBe(false);
+ expect(result.current.draft).toBe('');
+ });
+
+ it('closes an empty box on blur and keeps one holding text', () => {
+ const { result } = setup();
+ act(() => result.current.openFind());
+ act(() => result.current.blur());
+ expect(result.current.expanded).toBe(false);
+
+ act(() => result.current.openFind());
+ act(() => result.current.setDraft('deploy'));
+ act(() => result.current.blur());
+ expect(result.current.expanded).toBe(true);
+ });
+
+ it('follows a condition changed elsewhere, but keeps a trailing space being typed', () => {
+ const { result, rerender } = setup('deploy');
+
+ act(() => result.current.setDraft('deploy '));
+ rerender({ value: 'deploy' });
+ expect(result.current.draft).toBe('deploy ');
+
+ // The filter menu replaced the condition.
+ rerender({ value: 'billing' });
+ expect(result.current.draft).toBe('billing');
+ });
+
+ it('keeps a box shown for an existing condition open while its text is erased and retyped', () => {
+ const { result, rerender } = setup('deploy');
+
+ act(() => result.current.focus());
+ act(() => result.current.setDraft(''));
+ // The empty text is committed after the pause; the focused box must stay.
+ rerender({ value: undefined });
+
+ expect(result.current.expanded).toBe(true);
+ });
+
+ it('closes an unfocused open box when its condition is cleared elsewhere', () => {
+ const { result, rerender } = setup();
+ act(() => result.current.openFind());
+ act(() => result.current.setDraft('deploy'));
+ rerender({ value: 'deploy' });
+ act(() => result.current.blur());
+ expect(result.current.expanded).toBe(true);
+
+ // "Clear all" in the empty state.
+ rerender({ value: undefined });
+
+ expect(result.current.expanded).toBe(false);
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.ts b/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.ts
new file mode 100644
index 00000000000..79c408f12fb
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/filter/useTaskListFind.ts
@@ -0,0 +1,91 @@
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+/**
+ * Typed text is committed to the `content` condition after this pause; each
+ * commit is a list request. Shared by the find box and the filter bar's chip.
+ */
+export const TASK_FILTER_CONTENT_COMMIT_DELAY_MS = 400;
+
+interface UseTaskListFindOptions {
+ /** The list's committed `content` condition (trimmed by the filter). */
+ content?: string;
+ onChange: (content: string) => void;
+}
+
+/**
+ * State of the Tasks page find box: a draft committed to the `content` filter
+ * after a pause, opened by Mod+F, cleared and closed by Escape.
+ */
+export const useTaskListFind = ({ content = '', onChange }: UseTaskListFindOptions) => {
+ const [open, setOpen] = useState(false);
+ const [focused, setFocused] = useState(false);
+ const [draft, setDraft] = useState(content);
+ const [focusRequest, setFocusRequest] = useState(0);
+ // Set once the box is cleared, so the blur that follows cannot commit the old text again.
+ const discardBlurRef = useRef(false);
+
+ // Follow the condition when it changes elsewhere (the filter menu, "Clear"). The
+ // committed value is trimmed, so a draft that only differs by spaces is kept as typed.
+ const [syncedContent, setSyncedContent] = useState(content);
+ if (syncedContent !== content) {
+ setSyncedContent(content);
+ if (draft.trim() !== content) setDraft(content);
+ // Cleared elsewhere while nobody is typing in it: an empty box has nothing to keep.
+ if (!content && !focused) setOpen(false);
+ }
+
+ useEffect(() => {
+ if (draft.trim() === content) return;
+ const timer = setTimeout(() => onChange(draft), TASK_FILTER_CONTENT_COMMIT_DELAY_MS);
+ return () => clearTimeout(timer);
+ }, [content, draft, onChange]);
+
+ const openFind = useCallback(() => {
+ discardBlurRef.current = false;
+ setOpen(true);
+ // Bumped on every press, so a repeat Mod+F re-selects the text.
+ setFocusRequest((nonce) => nonce + 1);
+ }, []);
+
+ const commit = useCallback(() => {
+ if (draft.trim() !== content) onChange(draft);
+ }, [content, draft, onChange]);
+
+ const clearAndClose = useCallback(() => {
+ discardBlurRef.current = true;
+ setOpen(false);
+ setDraft('');
+ if (content) onChange('');
+ }, [content, onChange]);
+
+ // A box shown for an existing condition becomes an open one once focused, so
+ // erasing the text to type another does not collapse it under the cursor.
+ const focus = useCallback(() => {
+ setFocused(true);
+ setOpen(true);
+ }, []);
+
+ const blur = useCallback(() => {
+ setFocused(false);
+ if (discardBlurRef.current) {
+ discardBlurRef.current = false;
+ return;
+ }
+ commit();
+ // An empty box has nothing to keep on screen.
+ if (!draft.trim()) setOpen(false);
+ }, [commit, draft]);
+
+ return {
+ blur,
+ clearAndClose,
+ commit,
+ draft,
+ // An active text condition always shows in the box, so it stays visible and editable.
+ expanded: open || !!content,
+ focus,
+ focusRequest,
+ openFind,
+ setDraft,
+ };
+};