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): collapse sub-tasks by default and nest them under their parent (#18454)

Arvin Xu1829a389a0b4
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index bc06d410236..874df2f449e 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -1470,9 +1470,11 @@
"taskList.emptyHero.greeting": "What should we tackle today?",
"taskList.emptyHero.templatesTitle": "Templates picked for you",
"taskList.form.grouping": "Grouping",
+ "taskList.form.nestedSubTasks": "Nested sub-tasks",
"taskList.form.orderCompletedByRecency": "Sort completed tasks by recency",
"taskList.form.ordering": "Ordering",
"taskList.form.showCompleted": "Show completed & canceled",
+ "taskList.form.showSubTasks": "Show sub-tasks",
"taskList.form.subGrouping": "Sub-grouping",
"taskList.groupBy.assignee": "Assignee",
"taskList.groupBy.none": "No grouping",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 2a0d58523c4..83e7b044fd5 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -1470,9 +1470,11 @@
"taskList.emptyHero.greeting": "今天想搞定点什么?",
"taskList.emptyHero.templatesTitle": "为你推荐的模板",
"taskList.form.grouping": "分组",
+ "taskList.form.nestedSubTasks": "缩进显示子任务",
"taskList.form.orderCompletedByRecency": "按最近完成排序",
"taskList.form.ordering": "排序",
"taskList.form.showCompleted": "显示已完成与已取消",
+ "taskList.form.showSubTasks": "显示子任务",
"taskList.form.subGrouping": "子分组",
"taskList.groupBy.assignee": "负责人",
"taskList.groupBy.none": "不分组",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index f365b5b4bad..b44229d4989 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -1744,9 +1744,11 @@ export default {
'taskList.emptyHero.greeting': 'What should we tackle today?',
'taskList.emptyHero.templatesTitle': 'Templates picked for you',
'taskList.form.grouping': 'Grouping',
+ 'taskList.form.nestedSubTasks': 'Nested sub-tasks',
'taskList.form.orderCompletedByRecency': 'Sort completed tasks by recency',
'taskList.form.ordering': 'Ordering',
'taskList.form.showCompleted': 'Show completed & canceled',
+ 'taskList.form.showSubTasks': 'Show sub-tasks',
'taskList.form.subGrouping': 'Sub-grouping',
'taskList.hiddenCompleted.count_one': '{{count}} task',
'taskList.hiddenCompleted.count_other': '{{count}} tasks',
diff --git a/src/features/AgentTasks/AgentTaskList/TaskList.tsx b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
index d7205e9c0c4..433ee876aec 100644
--- a/src/features/AgentTasks/AgentTaskList/TaskList.tsx
+++ b/src/features/AgentTasks/AgentTaskList/TaskList.tsx
@@ -19,14 +19,17 @@ import PriorityNoneIcon from '../features/icons/PriorityNoneIcon';
import PriorityUrgentIcon from '../features/icons/PriorityUrgentIcon';
import TaskStatusIcon from '../features/TaskStatusIcon';
import { useAgentDisplayMeta } from '../shared/useAgentDisplayMeta';
-import type { TaskGroupBy, TaskGroupMeta, TaskListViewOptions } from './listViewOptions';
+import type { TaskGroupBy, TaskGroupMeta, TaskListViewOptions, TaskRow } from './listViewOptions';
import {
+ buildTaskRows,
+ collapseSubTasks,
compareTaskItems,
getTaskGroupMeta,
HIDDEN_WHEN_COMPLETED_STATUSES,
sortGroupEntries,
} from './listViewOptions';
import TaskItemSkeleton from './TaskItemSkeleton';
+import TaskRowIndent from './TaskRowIndent';
interface TaskListProps {
/**
@@ -48,25 +51,25 @@ interface TaskListProps {
const HIDDEN_COMPLETED_STATUS_SET = new Set<string>(HIDDEN_WHEN_COMPLETED_STATUSES);
-const renderTaskRows = (
- items: ReturnType<typeof taskListSelectors.taskList>,
- sub?: boolean,
- routeScope?: TaskItemRouteScope,
-) =>
- items.map((task, index) => (
- <Fragment key={task.identifier}>
- <AgentTaskItem routeScope={routeScope} task={task} />
- {!sub && index !== items.length - 1 && <Divider dashed style={{ margin: 0 }} />}
- </Fragment>
- ));
+const renderTaskRows = (rows: TaskRow[], sub?: boolean, routeScope?: TaskItemRouteScope) =>
+ rows.map((row, index) => {
+ // A nested child belongs to the row above it, so no rule is drawn between
+ // them — the divider only separates one top-level task from the next.
+ const showDivider = !sub && rows[index + 1] && rows[index + 1].depth === 0;
-const renderTaskListBlock = (
- items: ReturnType<typeof taskListSelectors.taskList>,
- sub?: boolean,
- routeScope?: TaskItemRouteScope,
-) => (
+ return (
+ <Fragment key={`${row.isParentContext ? 'context:' : ''}${row.task.identifier}`}>
+ <TaskRowIndent depth={row.depth} muted={row.isParentContext}>
+ <AgentTaskItem routeScope={routeScope} task={row.task} />
+ </TaskRowIndent>
+ {showDivider && <Divider dashed style={{ margin: 0 }} />}
+ </Fragment>
+ );
+ });
+
+const renderTaskListBlock = (rows: TaskRow[], sub?: boolean, routeScope?: TaskItemRouteScope) => (
<Block gap={sub ? 0 : 2} padding={2} variant={'borderless'}>
- {renderTaskRows(items, sub, routeScope)}
+ {renderTaskRows(rows, sub, routeScope)}
</Block>
);
@@ -145,16 +148,32 @@ const TaskList = memo<TaskListProps>((props) => {
const groupBy = normalizeGroupBy(options.groupBy, 'status');
const subGroupBy = normalizeGroupBy(options.subGroupBy, 'none');
const effectiveSubGroupBy = groupBy === 'none' ? 'none' : subGroupBy;
- const visibleTasks = useMemo(
+ const unfinishedTasks = useMemo(
() =>
options.hideCompleted
? tasks.filter((task) => !HIDDEN_COMPLETED_STATUS_SET.has(task.status))
: tasks,
[tasks, options.hideCompleted],
);
- const hiddenCount = tasks.length - visibleTasks.length;
+ // Only the completed/canceled cut feeds the "hidden by display options"
+ // footer — its "Show" action clears `hideCompleted`, so folding the sub-task
+ // count in would promise a reveal that toggle doesn't deliver.
+ const hiddenCount = tasks.length - unfinishedTasks.length;
+ const visibleTasks = useMemo(
+ () => (options.showSubTasks ? unfinishedTasks : collapseSubTasks(unfinishedTasks)),
+ [options.showSubTasks, unfinishedTasks],
+ );
+ // Keyed off the full list, not the visible one: a nested child's parent may
+ // sit in another group, or be hidden by the display options, and still has to
+ // resolve into a context row.
+ const taskById = useMemo(() => new Map(tasks.map((task) => [task.id, task])), [tasks]);
+ const nested = options.showSubTasks && options.nestedSubTasks;
const groupedTaskEntries = useMemo(() => {
- const sortedTasks = [...visibleTasks].sort((a, b) => compareTaskItems(a, b, options));
+ const compare = (a: (typeof visibleTasks)[number], b: (typeof visibleTasks)[number]) =>
+ compareTaskItems(a, b, options);
+ const toRows = (items: typeof visibleTasks) =>
+ buildTaskRows(items, { compare, nested, taskById });
+ const sortedTasks = [...visibleTasks].sort(compare);
const primaryGroupOrderDirection =
options.orderBy === groupBy ? options.orderDirection : undefined;
const subGroupOrderDirection =
@@ -182,9 +201,10 @@ const TaskList = memo<TaskListProps>((props) => {
return primaryGroups.map(([meta, groupedTasks]) => {
if (effectiveSubGroupBy === 'none') {
return {
- items: groupedTasks,
+ count: groupedTasks.length,
meta,
- subGroups: [] as Array<[TaskGroupMeta, typeof visibleTasks]>,
+ rows: toRows(groupedTasks),
+ subGroups: [] as Array<{ count: number; meta: TaskGroupMeta; rows: TaskRow[] }>,
};
}
@@ -202,16 +222,21 @@ const TaskList = memo<TaskListProps>((props) => {
}
return {
- items: groupedTasks,
+ count: groupedTasks.length,
meta,
+ rows: toRows(groupedTasks),
subGroups: sortGroupEntries(
[...subGroupMap.values()].map((group) => [group.meta, group.items]),
effectiveSubGroupBy,
subGroupOrderDirection,
- ),
+ ).map(([subMeta, subItems]) => ({
+ count: subItems.length,
+ meta: subMeta,
+ rows: toRows(subItems),
+ })),
};
});
- }, [effectiveSubGroupBy, groupBy, options, visibleTasks]);
+ }, [effectiveSubGroupBy, groupBy, nested, options, taskById, visibleTasks]);
const skeleton = (
<Block gap={2} padding={2} variant={'borderless'}>
@@ -254,7 +279,7 @@ const TaskList = memo<TaskListProps>((props) => {
const content =
groupBy === 'none' ? (
<>
- {renderTaskListBlock(groupedTaskEntries[0]?.items ?? [], false, routeScope)}
+ {renderTaskListBlock(groupedTaskEntries[0]?.rows ?? [], false, routeScope)}
{hiddenFooter}
</>
) : (
@@ -269,7 +294,7 @@ const TaskList = memo<TaskListProps>((props) => {
key={group.meta.key}
paddingBlock={8}
paddingInline={14}
- title={renderGroupTitle(group.meta, group.items.length)}
+ title={renderGroupTitle(group.meta, group.count)}
variant={'filled'}
styles={{
header: { marginBottom: 8 },
@@ -277,22 +302,22 @@ const TaskList = memo<TaskListProps>((props) => {
>
{group.subGroups.length > 0 ? (
<Accordion gap={6}>
- {group.subGroups.map(([subGroup, subGroupTasks]) => (
+ {group.subGroups.map((subGroup) => (
<AccordionItem
defaultExpand
indicatorPlacement={'end'}
- itemKey={`sub-${group.meta.key}-${subGroup.key}`}
- key={`${group.meta.key}-${subGroup.key}`}
+ itemKey={`sub-${group.meta.key}-${subGroup.meta.key}`}
+ key={`${group.meta.key}-${subGroup.meta.key}`}
paddingBlock={6}
paddingInline={14}
- title={renderGroupTitle(subGroup, subGroupTasks.length, true)}
+ title={renderGroupTitle(subGroup.meta, subGroup.count, true)}
>
- {renderTaskListBlock(subGroupTasks, true, routeScope)}
+ {renderTaskListBlock(subGroup.rows, true, routeScope)}
</AccordionItem>
))}
</Accordion>
) : (
- renderTaskListBlock(group.items, false, routeScope)
+ renderTaskListBlock(group.rows, false, routeScope)
)}
</AccordionItem>
);
diff --git a/src/features/AgentTasks/AgentTaskList/TaskRowIndent.tsx b/src/features/AgentTasks/AgentTaskList/TaskRowIndent.tsx
new file mode 100644
index 00000000000..4db46d96291
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/TaskRowIndent.tsx
@@ -0,0 +1,69 @@
+import { Flexbox } from '@lobehub/ui';
+import { createStaticStyles } from 'antd-style';
+import type { ReactNode } from 'react';
+
+/** Indent added per nesting level, in px. */
+const INDENT_STEP = 20;
+
+const styles = createStaticStyles(({ css, cssVar }) => {
+ return {
+ // Elbow drawn from the row's top edge down to its vertical centre, so a
+ // child reads as hanging off the row above it rather than off the group.
+ connector: css`
+ position: relative;
+
+ flex: none;
+ align-self: stretch;
+
+ inline-size: 12px;
+ margin-inline-end: 4px;
+
+ &::before {
+ content: '';
+
+ position: absolute;
+ inset-block: 0 50%;
+ inset-inline-start: 0;
+
+ inline-size: 8px;
+ border-block-end: 1px solid ${cssVar.colorBorder};
+ border-inline-start: 1px solid ${cssVar.colorBorder};
+ border-end-start-radius: 4px;
+ }
+ `,
+ muted: css`
+ opacity: 0.5;
+ `,
+ };
+});
+
+interface TaskRowIndentProps {
+ children: ReactNode;
+ /** Nesting level of the row; 0 renders the task untouched. */
+ depth: number;
+ /**
+ * Dims the row to mark it as context only — the task is shown to place a
+ * nested child, not because it belongs to this group.
+ */
+ muted?: boolean;
+}
+
+const TaskRowIndent = ({ children, depth, muted }: TaskRowIndentProps) => {
+ if (depth <= 0 && !muted) return <>{children}</>;
+
+ return (
+ <Flexbox
+ horizontal
+ align={'stretch'}
+ className={muted ? styles.muted : undefined}
+ style={depth > 0 ? { paddingInlineStart: depth * INDENT_STEP } : undefined}
+ >
+ {depth > 0 && <div className={styles.connector} />}
+ <Flexbox flex={1} style={{ minWidth: 0 }}>
+ {children}
+ </Flexbox>
+ </Flexbox>
+ );
+};
+
+export default TaskRowIndent;
diff --git a/src/features/AgentTasks/AgentTaskList/TasksGroupConfig.tsx b/src/features/AgentTasks/AgentTaskList/TasksGroupConfig.tsx
index a18cd46217f..36e77b93273 100644
--- a/src/features/AgentTasks/AgentTaskList/TasksGroupConfig.tsx
+++ b/src/features/AgentTasks/AgentTaskList/TasksGroupConfig.tsx
@@ -156,6 +156,38 @@ const TasksGroupConfig = memo<TasksHeaderProps>(({ options, setOptions }) => {
minWidth: undefined,
label: t('taskList.form.showCompleted'),
},
+ {
+ children: (
+ <Switch
+ checked={options.showSubTasks}
+ size={'small'}
+ onChange={(checked) => {
+ setOptions((prev) => ({ ...prev, showSubTasks: checked }));
+ }}
+ />
+ ),
+ minWidth: undefined,
+ label: t('taskList.form.showSubTasks'),
+ },
+ // Only meaningful once sub-tasks are on the list — otherwise the toggle
+ // would sit there controlling nothing.
+ ...(options.showSubTasks
+ ? [
+ {
+ children: (
+ <Switch
+ checked={options.nestedSubTasks}
+ size={'small'}
+ onChange={(checked) => {
+ setOptions((prev) => ({ ...prev, nestedSubTasks: checked }));
+ }}
+ />
+ ),
+ minWidth: undefined,
+ label: t('taskList.form.nestedSubTasks'),
+ } satisfies FormItemProps,
+ ]
+ : []),
];
const panelContent = (
diff --git a/src/features/AgentTasks/AgentTaskList/listViewOptions.test.ts b/src/features/AgentTasks/AgentTaskList/listViewOptions.test.ts
new file mode 100644
index 00000000000..535f10bbcf9
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskList/listViewOptions.test.ts
@@ -0,0 +1,181 @@
+import { describe, expect, it } from 'vitest';
+
+import type { TaskListItem } from '@/store/task/slices/list/initialState';
+
+import {
+ buildTaskRows,
+ collapseSubTasks,
+ compareTaskItems,
+ DEFAULT_TASK_LIST_VIEW_OPTIONS,
+ normalizeTaskListViewOptions,
+} from './listViewOptions';
+
+const task = (id: string, overrides: Partial<TaskListItem> = {}): TaskListItem =>
+ ({
+ createdAt: new Date('2026-01-01'),
+ id,
+ identifier: `T-${id}`,
+ name: id,
+ parentTaskId: null,
+ priority: 0,
+ status: 'backlog',
+ updatedAt: new Date('2026-01-01'),
+ ...overrides,
+ }) as unknown as TaskListItem;
+
+const byIdentifier = (a: TaskListItem, b: TaskListItem) => a.identifier.localeCompare(b.identifier);
+
+const indexById = (items: TaskListItem[]) => new Map(items.map((item) => [item.id, item]));
+
+describe('normalizeTaskListViewOptions', () => {
+ it('keeps sub-tasks out of the list but nested by default', () => {
+ const options = normalizeTaskListViewOptions();
+
+ expect(options.showSubTasks).toBe(false);
+ expect(options.nestedSubTasks).toBe(true);
+ });
+
+ it('restores the sub-task defaults for options persisted before the toggles existed', () => {
+ const options = normalizeTaskListViewOptions({ groupBy: 'priority' });
+
+ expect(options.showSubTasks).toBe(DEFAULT_TASK_LIST_VIEW_OPTIONS.showSubTasks);
+ expect(options.nestedSubTasks).toBe(DEFAULT_TASK_LIST_VIEW_OPTIONS.nestedSubTasks);
+ });
+
+ it('preserves an explicit sub-task choice', () => {
+ const options = normalizeTaskListViewOptions({ nestedSubTasks: false, showSubTasks: true });
+
+ expect(options.showSubTasks).toBe(true);
+ expect(options.nestedSubTasks).toBe(false);
+ });
+});
+
+describe('collapseSubTasks', () => {
+ it('drops a sub-task whose parent is already listed', () => {
+ const items = [task('parent'), task('child', { parentTaskId: 'parent' })];
+
+ expect(collapseSubTasks(items).map((item) => item.id)).toEqual(['parent']);
+ });
+
+ it('drops every level of a nested chain the root stands for', () => {
+ const items = [
+ task('root'),
+ task('child', { parentTaskId: 'root' }),
+ task('grandchild', { parentTaskId: 'child' }),
+ ];
+
+ expect(collapseSubTasks(items).map((item) => item.id)).toEqual(['root']);
+ });
+
+ it('keeps a sub-task whose parent is absent from the list', () => {
+ // A goal's child: the parent is filtered out server-side, so no listed row
+ // stands for it and hiding it would drop it from the page entirely.
+ const items = [task('orphan', { parentTaskId: 'goal-task' }), task('solo')];
+
+ expect(collapseSubTasks(items).map((item) => item.id)).toEqual(['orphan', 'solo']);
+ });
+});
+
+describe('buildTaskRows', () => {
+ it('leaves every task at the top level when nesting is off', () => {
+ const items = [task('parent'), task('child', { parentTaskId: 'parent' })];
+ const rows = buildTaskRows(items, {
+ compare: byIdentifier,
+ nested: false,
+ taskById: indexById(items),
+ });
+
+ expect(rows.map((row) => [row.task.id, row.depth])).toEqual([
+ ['parent', 0],
+ ['child', 0],
+ ]);
+ });
+
+ it('indents a sub-task under the parent it shares a group with', () => {
+ const items = [
+ task('child', { parentTaskId: 'parent' }),
+ task('parent'),
+ task('grandchild', { parentTaskId: 'child' }),
+ ];
+ const rows = buildTaskRows(items, {
+ compare: byIdentifier,
+ nested: true,
+ taskById: indexById(items),
+ });
+
+ expect(rows.map((row) => [row.task.id, row.depth, row.isParentContext])).toEqual([
+ ['parent', 0, false],
+ ['child', 1, false],
+ ['grandchild', 2, false],
+ ]);
+ });
+
+ it('anchors a sub-task under a muted context row when its parent sits elsewhere', () => {
+ const parent = task('parent', { status: 'backlog' });
+ const child = task('child', { parentTaskId: 'parent', status: 'running' });
+ const rows = buildTaskRows([child], {
+ compare: byIdentifier,
+ nested: true,
+ taskById: indexById([parent, child]),
+ });
+
+ expect(rows.map((row) => [row.task.id, row.depth, row.isParentContext])).toEqual([
+ ['parent', 0, true],
+ ['child', 1, false],
+ ]);
+ });
+
+ it('gathers siblings from other groups under a single context row', () => {
+ const parent = task('parent');
+ const first = task('first', { parentTaskId: 'parent' });
+ const second = task('second', { parentTaskId: 'parent' });
+ const rows = buildTaskRows([second, first], {
+ compare: byIdentifier,
+ nested: true,
+ taskById: indexById([parent, first, second]),
+ });
+
+ expect(rows.map((row) => [row.task.id, row.depth])).toEqual([
+ ['parent', 0],
+ ['first', 1],
+ ['second', 1],
+ ]);
+ });
+
+ it('keeps a sub-task at the top level when its parent is off the list entirely', () => {
+ const orphan = task('orphan', { parentTaskId: 'missing' });
+ const rows = buildTaskRows([orphan], {
+ compare: byIdentifier,
+ nested: true,
+ taskById: indexById([orphan]),
+ });
+
+ expect(rows).toEqual([{ depth: 0, isParentContext: false, task: orphan }]);
+ });
+
+ it('renders every task once when the parent chain loops back on itself', () => {
+ const a = task('a', { parentTaskId: 'b' });
+ const b = task('b', { parentTaskId: 'a' });
+ const rows = buildTaskRows([a, b], {
+ compare: byIdentifier,
+ nested: true,
+ taskById: indexById([a, b]),
+ });
+
+ expect(rows.map((row) => row.task.id).sort()).toEqual(['a', 'b']);
+ });
+
+ it('orders siblings with the list comparator', () => {
+ const options = { ...DEFAULT_TASK_LIST_VIEW_OPTIONS, orderBy: 'title' as const };
+ const parent = task('parent', { name: 'A parent' });
+ const beta = task('beta', { name: 'Beta', parentTaskId: 'parent' });
+ const alpha = task('alpha', { name: 'Alpha', parentTaskId: 'parent' });
+ const rows = buildTaskRows([parent, beta, alpha], {
+ compare: (a, b) => compareTaskItems(a, b, options),
+ nested: true,
+ taskById: indexById([parent, beta, alpha]),
+ });
+
+ expect(rows.map((row) => row.task.id)).toEqual(['parent', 'alpha', 'beta']);
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskList/listViewOptions.ts b/src/features/AgentTasks/AgentTaskList/listViewOptions.ts
index b1d6cabcf27..9ef332681b6 100644
--- a/src/features/AgentTasks/AgentTaskList/listViewOptions.ts
+++ b/src/features/AgentTasks/AgentTaskList/listViewOptions.ts
@@ -9,9 +9,13 @@ export type TaskOrderDirection = 'asc' | 'desc';
export interface TaskListViewOptions {
groupBy: TaskGroupBy;
hideCompleted: boolean;
+ /** Indent a shown sub-task under its parent instead of listing it as a peer. */
+ nestedSubTasks: boolean;
orderBy: TaskOrderBy;
orderCompletedByRecency: boolean;
orderDirection: TaskOrderDirection;
+ /** List sub-tasks whose parent is already on the list as rows of their own. */
+ showSubTasks: boolean;
subGroupBy: TaskGroupBy;
}
@@ -32,9 +36,14 @@ export interface TaskGroupMeta {
export const DEFAULT_TASK_LIST_VIEW_OPTIONS: TaskListViewOptions = {
groupBy: 'status',
hideCompleted: true,
+ // Nesting is the default *shape* for sub-tasks, but sub-tasks stay hidden
+ // until asked for: a parent already carries its progress (`3/8`), so listing
+ // its children as peers only pads the list with rows the parent stands for.
+ nestedSubTasks: true,
orderBy: 'updatedAt',
orderCompletedByRecency: true,
orderDirection: 'asc',
+ showSubTasks: false,
subGroupBy: 'none',
};
@@ -66,6 +75,10 @@ export const normalizeTaskListViewOptions = (
typeof next.hideCompleted === 'boolean'
? next.hideCompleted
: DEFAULT_TASK_LIST_VIEW_OPTIONS.hideCompleted,
+ nestedSubTasks:
+ typeof next.nestedSubTasks === 'boolean'
+ ? next.nestedSubTasks
+ : DEFAULT_TASK_LIST_VIEW_OPTIONS.nestedSubTasks,
orderBy: TASK_ORDER_BY_SET.has(next.orderBy as TaskOrderBy)
? (next.orderBy as TaskOrderBy)
: DEFAULT_TASK_LIST_VIEW_OPTIONS.orderBy,
@@ -76,6 +89,10 @@ export const normalizeTaskListViewOptions = (
orderDirection: TASK_ORDER_DIRECTION_SET.has(next.orderDirection as TaskOrderDirection)
? (next.orderDirection as TaskOrderDirection)
: DEFAULT_TASK_LIST_VIEW_OPTIONS.orderDirection,
+ showSubTasks:
+ typeof next.showSubTasks === 'boolean'
+ ? next.showSubTasks
+ : DEFAULT_TASK_LIST_VIEW_OPTIONS.showSubTasks,
subGroupBy: groupBy === 'none' || subGroupBy !== groupBy ? subGroupBy : 'none',
};
};
@@ -286,3 +303,120 @@ export const sortGroupEntries = (
: groupB.label.localeCompare(groupA.label);
});
};
+
+/** Depth cap — guards a malformed parent chain from recursing without end. */
+const MAX_NEST_DEPTH = 8;
+
+export interface TaskRow {
+ /** Indent level inside its group; 0 for a row that isn't nested. */
+ depth: number;
+ /**
+ * True when the row exists only to anchor a nested child whose parent sits in
+ * another group (or is hidden by the display options). It is rendered muted
+ * and is not counted as one of the group's tasks.
+ */
+ isParentContext: boolean;
+ task: TaskListItem;
+}
+
+/**
+ * Drop the sub-tasks a listed parent already stands for.
+ *
+ * Membership — not `parentTaskId` alone — is what decides: a task whose parent
+ * is absent from this list (a goal's child, a parent on another page) has no
+ * row representing it, so hiding it would drop it from the page entirely.
+ */
+export const collapseSubTasks = (items: TaskListItem[]): TaskListItem[] => {
+ const ids = new Set(items.map((item) => item.id));
+ return items.filter((item) => !item.parentTaskId || !ids.has(item.parentTaskId));
+};
+
+/**
+ * Lay a group's tasks out as indented rows, parents before their children.
+ *
+ * Grouping still keys off each task's own status/priority/assignee, so a
+ * sub-task regularly lands in a group its parent isn't in. Such a child gets a
+ * muted context row for its parent rather than sitting at the top level, where
+ * an indent-free row would read as an unrelated task.
+ */
+export const buildTaskRows = (
+ groupItems: TaskListItem[],
+ options: {
+ compare: (a: TaskListItem, b: TaskListItem) => number;
+ nested: boolean;
+ /** Every task on the list, keyed by id — resolves parents outside the group. */
+ taskById: Map<string, TaskListItem>;
+ },
+): TaskRow[] => {
+ const { compare, nested, taskById } = options;
+ if (!nested) return groupItems.map((task) => ({ depth: 0, isParentContext: false, task }));
+
+ interface TaskNode {
+ children: string[];
+ isParentContext: boolean;
+ task: TaskListItem;
+ }
+
+ const nodes = new Map<string, TaskNode>();
+ for (const task of groupItems) {
+ nodes.set(task.id, { children: [], isParentContext: false, task });
+ }
+
+ const parentOf = new Map<string, string>();
+ const roots: string[] = [];
+
+ // Every node holds at most one parent link, so a cycle can only close on the
+ // edge being added — walking up from the parent is enough to rule it out.
+ const isDescendantOf = (ancestorId: string, id: string) => {
+ let current: string | undefined = id;
+ for (let depth = 0; current && depth <= MAX_NEST_DEPTH; depth += 1) {
+ if (current === ancestorId) return true;
+ current = parentOf.get(current);
+ }
+ return false;
+ };
+
+ for (const task of groupItems) {
+ const parentId = task.parentTaskId;
+ if (!parentId || parentId === task.id) {
+ roots.push(task.id);
+ continue;
+ }
+
+ let parentNode = nodes.get(parentId);
+ if (!parentNode) {
+ const parentTask = taskById.get(parentId);
+ if (!parentTask) {
+ roots.push(task.id);
+ continue;
+ }
+ parentNode = { children: [], isParentContext: true, task: parentTask };
+ nodes.set(parentId, parentNode);
+ roots.push(parentId);
+ }
+
+ if (isDescendantOf(task.id, parentId)) {
+ roots.push(task.id);
+ continue;
+ }
+
+ parentNode.children.push(task.id);
+ parentOf.set(task.id, parentId);
+ }
+
+ const sortIds = (ids: string[]) =>
+ [...ids].sort((a, b) => compare(nodes.get(a)!.task, nodes.get(b)!.task));
+
+ const rows: TaskRow[] = [];
+ const visit = (id: string, depth: number) => {
+ const node = nodes.get(id);
+ if (!node) return;
+ rows.push({ depth, isParentContext: node.isParentContext, task: node.task });
+ if (depth >= MAX_NEST_DEPTH) return;
+ for (const childId of sortIds(node.children)) visit(childId, depth + 1);
+ };
+
+ for (const id of sortIds(roots)) visit(id, 0);
+
+ return rows;
+};
diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.ts
index b6d40dc6f6c..45cc10e643f 100644
--- a/src/store/global/initialState.ts
+++ b/src/store/global/initialState.ts
@@ -375,9 +375,11 @@ export interface SystemStatus {
taskListViewOptions?: {
groupBy: 'assignee' | 'none' | 'priority' | 'status';
hideCompleted: boolean;
+ nestedSubTasks: boolean;
orderBy: 'assignee' | 'createdAt' | 'priority' | 'status' | 'title' | 'updatedAt';
orderCompletedByRecency: boolean;
orderDirection: 'asc' | 'desc';
+ showSubTasks: boolean;
subGroupBy: 'assignee' | 'none' | 'priority' | 'status';
};
/**
@@ -515,9 +517,11 @@ export const INITIAL_STATUS = {
taskListViewOptions: {
groupBy: 'status',
hideCompleted: true,
+ nestedSubTasks: true,
orderBy: 'updatedAt',
orderCompletedByRecency: true,
orderDirection: 'asc',
+ showSubTasks: false,
subGroupBy: 'none',
},
taskListViewMode: 'list' as const,
diff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.ts
index f8b91e75df7..7362c6c343e 100644
--- a/src/store/global/selectors/systemStatus.ts
+++ b/src/store/global/selectors/systemStatus.ts
@@ -108,9 +108,11 @@ const taskListViewOptions = (s: GlobalState) =>
s.status.taskListViewOptions || {
groupBy: 'status',
hideCompleted: true,
+ nestedSubTasks: true,
orderBy: 'updatedAt',
orderCompletedByRecency: true,
orderDirection: 'asc',
+ showSubTasks: false,
subGroupBy: 'none',
};