feat(sidebar): add last activity task sorting (#2762)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import type { TaskSwitcherProps } from "../task-switcher";
|
||||
import type { MobileTaskListProps } from "./session-task-switcher-sheet";
|
||||
|
||||
/** Maps mobile view state and actions to the shared task switcher rows. */
|
||||
export function buildMobileTaskSwitcherProps(
|
||||
props: MobileTaskListProps,
|
||||
helpers: {
|
||||
grouped: TaskSwitcherProps["grouped"];
|
||||
collapsedGroupKeys: string[];
|
||||
onToggleGroup: (groupKey: string) => void;
|
||||
collapsedSubtaskParentIds: string[];
|
||||
onToggleSubtasks: (parentTaskId: string) => void;
|
||||
onTogglePin: (taskId: string) => void;
|
||||
onReorderGroup: (groupTaskIds: string[]) => void;
|
||||
onReorderSubtasks: (parentTaskId: string, orderedSubtaskIds: string[]) => void;
|
||||
pinnedTaskIds: string[];
|
||||
showActivityTime: boolean;
|
||||
},
|
||||
): TaskSwitcherProps {
|
||||
return {
|
||||
grouped: helpers.grouped,
|
||||
workflows: props.workflows,
|
||||
stepsByWorkflowId: props.stepsByWorkflowId,
|
||||
activeTaskId: props.activeTaskId,
|
||||
selectedTaskId: props.selectedTaskId,
|
||||
collapsedGroupKeys: helpers.collapsedGroupKeys,
|
||||
showActivityTime: helpers.showActivityTime,
|
||||
onToggleGroup: helpers.onToggleGroup,
|
||||
collapsedSubtaskParentIds: helpers.collapsedSubtaskParentIds,
|
||||
onToggleSubtasks: helpers.onToggleSubtasks,
|
||||
onSelectTask: props.onSelectTask,
|
||||
onEditTask: props.onEditTask,
|
||||
onRenameTask: props.onRenameTask,
|
||||
onCreateSubtask: props.onCreateSubtask,
|
||||
onArchiveTask: props.onArchiveTask,
|
||||
onDeleteTask: props.onDeleteTask,
|
||||
onDetachTask: props.onDetachTask,
|
||||
onNestTask: props.onNestTask,
|
||||
onLinkPullRequest: props.onLinkPullRequest,
|
||||
onLinkIssue: props.onLinkIssue,
|
||||
onLinkMergeRequest: props.onLinkMergeRequest,
|
||||
onLinkJiraTicket: props.onLinkJiraTicket,
|
||||
onLinkLinearIssue: props.onLinkLinearIssue,
|
||||
onLinkSentryIssue: props.onLinkSentryIssue,
|
||||
onTogglePin: helpers.onTogglePin,
|
||||
onReorderGroup: helpers.onReorderGroup,
|
||||
onReorderSubtasks: helpers.onReorderSubtasks,
|
||||
pinnedTaskIds: helpers.pinnedTaskIds,
|
||||
deletingTaskId: props.deletingTaskId,
|
||||
isLoading: props.isLoading,
|
||||
loadError: props.loadError,
|
||||
onRetryLoad: props.onRetryLoad,
|
||||
retryLabel: props.retryLabel,
|
||||
totalTaskCount: props.tasks.length,
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from "@kandev/ui/dra
|
||||
import { Button } from "@kandev/ui/button";
|
||||
import { QuickChatSheetButton } from "./quick-chat-sheet-button";
|
||||
import { TaskSwitcher } from "../task-switcher";
|
||||
import type { TaskSwitcherItem, TaskSwitcherProps } from "../task-switcher";
|
||||
import type { TaskSwitcherItem } from "../task-switcher";
|
||||
import { SidebarFilterBar } from "../sidebar-filter/sidebar-filter-bar";
|
||||
import type { StepDef } from "../task-switcher-context-menu";
|
||||
import type { TaskMoveWorkflow } from "../task-move-context-menu";
|
||||
@@ -39,7 +39,7 @@ import { useQuickChatLauncher } from "@/hooks/use-quick-chat-launcher";
|
||||
import { useMobileTaskRename } from "./use-mobile-task-rename";
|
||||
import { SidebarTaskEditDialog, useSidebarTaskEdit } from "../task-session-sidebar-edit";
|
||||
import { usePortForwardingVisibility } from "../port-forwarding-visibility-provider";
|
||||
|
||||
import { buildMobileTaskSwitcherProps } from "./session-task-switcher-sheet-props";
|
||||
type SessionTaskSwitcherSheetProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
@@ -47,7 +47,6 @@ type SessionTaskSwitcherSheetProps = {
|
||||
workflowId: string | null;
|
||||
presentation?: "sheet" | "drawer";
|
||||
};
|
||||
|
||||
export function useTaskSheetSelectionController() {
|
||||
const [selectionController] = useState(createTaskSheetSelectionController);
|
||||
useEffect(
|
||||
@@ -58,7 +57,6 @@ export function useTaskSheetSelectionController() {
|
||||
);
|
||||
return selectionController;
|
||||
}
|
||||
|
||||
function useMobileTaskLinking(workspaceId: string | null) {
|
||||
const store = useAppStoreApi();
|
||||
const actions = useSidebarLinkActions(store);
|
||||
@@ -80,7 +78,7 @@ function useSidebarGroupToggle(viewId: string) {
|
||||
);
|
||||
}
|
||||
|
||||
type MobileTaskListProps = {
|
||||
export type MobileTaskListProps = {
|
||||
tasks: TaskSwitcherItem[];
|
||||
workflows: TaskMoveWorkflow[];
|
||||
stepsByWorkflowId: Record<string, StepDef[]>;
|
||||
@@ -107,62 +105,6 @@ type MobileTaskListProps = {
|
||||
retryLabel?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Assembles the TaskSwitcher props for the mobile task list, mirroring the
|
||||
* desktop `buildTaskSwitcherProps` so the prop-forwarding surface stays a
|
||||
* thin mapping layer.
|
||||
*/
|
||||
function buildMobileTaskSwitcherProps(
|
||||
props: MobileTaskListProps,
|
||||
helpers: {
|
||||
grouped: TaskSwitcherProps["grouped"];
|
||||
collapsedGroupKeys: string[];
|
||||
onToggleGroup: (groupKey: string) => void;
|
||||
collapsedSubtaskParentIds: string[];
|
||||
onToggleSubtasks: (parentTaskId: string) => void;
|
||||
onTogglePin: (taskId: string) => void;
|
||||
onReorderGroup: (groupTaskIds: string[]) => void;
|
||||
onReorderSubtasks: (parentTaskId: string, orderedSubtaskIds: string[]) => void;
|
||||
pinnedTaskIds: string[];
|
||||
},
|
||||
): TaskSwitcherProps {
|
||||
return {
|
||||
grouped: helpers.grouped,
|
||||
workflows: props.workflows,
|
||||
stepsByWorkflowId: props.stepsByWorkflowId,
|
||||
activeTaskId: props.activeTaskId,
|
||||
selectedTaskId: props.selectedTaskId,
|
||||
collapsedGroupKeys: helpers.collapsedGroupKeys,
|
||||
onToggleGroup: helpers.onToggleGroup,
|
||||
collapsedSubtaskParentIds: helpers.collapsedSubtaskParentIds,
|
||||
onToggleSubtasks: helpers.onToggleSubtasks,
|
||||
onSelectTask: props.onSelectTask,
|
||||
onEditTask: props.onEditTask,
|
||||
onRenameTask: props.onRenameTask,
|
||||
onCreateSubtask: props.onCreateSubtask,
|
||||
onArchiveTask: props.onArchiveTask,
|
||||
onDeleteTask: props.onDeleteTask,
|
||||
onDetachTask: props.onDetachTask,
|
||||
onNestTask: props.onNestTask,
|
||||
onLinkPullRequest: props.onLinkPullRequest,
|
||||
onLinkIssue: props.onLinkIssue,
|
||||
onLinkMergeRequest: props.onLinkMergeRequest,
|
||||
onLinkJiraTicket: props.onLinkJiraTicket,
|
||||
onLinkLinearIssue: props.onLinkLinearIssue,
|
||||
onLinkSentryIssue: props.onLinkSentryIssue,
|
||||
onTogglePin: helpers.onTogglePin,
|
||||
onReorderGroup: helpers.onReorderGroup,
|
||||
onReorderSubtasks: helpers.onReorderSubtasks,
|
||||
pinnedTaskIds: helpers.pinnedTaskIds,
|
||||
deletingTaskId: props.deletingTaskId,
|
||||
isLoading: props.isLoading,
|
||||
loadError: props.loadError,
|
||||
onRetryLoad: props.onRetryLoad,
|
||||
retryLabel: props.retryLabel,
|
||||
totalTaskCount: props.tasks.length,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The mobile task tree surface: renders the shared TaskSwitcher with the
|
||||
* mobile drawer's view state (grouping, ordering, collapse, reorder, nest).
|
||||
@@ -201,6 +143,7 @@ export function MobileTaskList(props: MobileTaskListProps) {
|
||||
onReorderGroup: handleReorderGroup,
|
||||
onReorderSubtasks: handleReorderSubtasks,
|
||||
pinnedTaskIds,
|
||||
showActivityTime: view.sort.key === "lastActivityAt",
|
||||
});
|
||||
return <TaskSwitcher {...switcherProps} />;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { useTranslation } from "react-i18next";
|
||||
const SORT_OPTIONS: Array<{ key: SortKey; labelKey: string }> = [
|
||||
{ key: "state", labelKey: "task:sortStatus" },
|
||||
{ key: "updatedAt", labelKey: "task:sortUpdated" },
|
||||
{ key: "lastActivityAt", labelKey: "task:sortLastActivity" },
|
||||
{ key: "createdAt", labelKey: "task:sortCreated" },
|
||||
{ key: "title", labelKey: "task:sortTitle" },
|
||||
{ key: "custom", labelKey: "task:sortCustom" },
|
||||
|
||||
@@ -64,7 +64,13 @@ export function TaskItemStatsRow({
|
||||
return (
|
||||
<span className="flex items-center gap-1.5 text-[11px]">
|
||||
{updatedAt && (
|
||||
<span className="text-muted-foreground/50">{formatRelativeTime(updatedAt)}</span>
|
||||
<span
|
||||
data-testid="sidebar-task-time"
|
||||
data-time-value={updatedAt}
|
||||
className="text-muted-foreground/50"
|
||||
>
|
||||
{formatRelativeTime(updatedAt)}
|
||||
</span>
|
||||
)}
|
||||
{prInfo && <span className="text-muted-foreground/50">#{prInfo.number}</span>}
|
||||
{queuedCount ? (
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { TaskPR } from "@/lib/types/github";
|
||||
import type { TaskMR } from "@/lib/types/gitlab";
|
||||
import { TaskItem } from "./task-item";
|
||||
import { TooltipProvider } from "@kandev/ui/tooltip";
|
||||
import { formatRelativeTime } from "@/lib/utils";
|
||||
|
||||
const TURN_FINISHED_ICON_TEST_ID = "task-state-turn-finished";
|
||||
const WORKFLOW_COMPLETE_ICON_TEST_ID = "task-state-workflow-complete";
|
||||
@@ -577,6 +578,37 @@ describe("TaskItem queued prompt count badge", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskItem activity timestamp", () => {
|
||||
it("shows activity time only when the active view sorts by activity", () => {
|
||||
const activityAt = "2026-07-20T00:00:00Z";
|
||||
const updatedAt = "2026-07-24T00:00:00Z";
|
||||
const { rerender } = renderTaskItem({
|
||||
updatedAt,
|
||||
lastActivityAt: activityAt,
|
||||
showActivityTime: true,
|
||||
});
|
||||
|
||||
expect(screen.getByTestId("sidebar-task-time").textContent).toBe(
|
||||
formatRelativeTime(activityAt),
|
||||
);
|
||||
|
||||
rerender(
|
||||
<StateProvider>
|
||||
<TooltipProvider>
|
||||
<TaskItem
|
||||
title="Needs answer"
|
||||
state="REVIEW"
|
||||
updatedAt={updatedAt}
|
||||
lastActivityAt={activityAt}
|
||||
showActivityTime={false}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
</StateProvider>,
|
||||
);
|
||||
expect(screen.getByTestId("sidebar-task-time").textContent).toBe(formatRelativeTime(updatedAt));
|
||||
});
|
||||
});
|
||||
|
||||
describe("TaskItem contribution badges", () => {
|
||||
it("renders the PR badge before the MR badge when the task has both (AC2)", () => {
|
||||
renderTaskItem(
|
||||
|
||||
@@ -68,6 +68,8 @@ type TaskItemProps = {
|
||||
remoteExecutorType?: string;
|
||||
remoteExecutorName?: string;
|
||||
updatedAt?: string;
|
||||
lastActivityAt?: string;
|
||||
showActivityTime?: boolean;
|
||||
menuOpen?: boolean;
|
||||
isDeleting?: boolean;
|
||||
taskId?: string;
|
||||
@@ -324,6 +326,8 @@ function TaskItemContent({
|
||||
isPinned,
|
||||
repositories,
|
||||
updatedAt,
|
||||
lastActivityAt,
|
||||
showActivityTime,
|
||||
prInfo,
|
||||
queuedCount,
|
||||
wipQueue,
|
||||
@@ -341,6 +345,8 @@ function TaskItemContent({
|
||||
isPinned?: boolean;
|
||||
repositories?: string[];
|
||||
updatedAt?: string;
|
||||
lastActivityAt?: string;
|
||||
showActivityTime?: boolean;
|
||||
prInfo?: { number: number; state: string; aggregateState?: string };
|
||||
queuedCount?: number;
|
||||
wipQueue?: WipQueueStatus;
|
||||
@@ -384,7 +390,7 @@ function TaskItemContent({
|
||||
</span>
|
||||
)}
|
||||
<TaskItemStatsRow
|
||||
updatedAt={updatedAt}
|
||||
updatedAt={showActivityTime ? (lastActivityAt ?? updatedAt) : updatedAt}
|
||||
prInfo={prInfo}
|
||||
primarySessionId={primarySessionId}
|
||||
queuedCount={queuedCount}
|
||||
@@ -434,6 +440,8 @@ export const TaskItem = memo(function TaskItem({
|
||||
remoteExecutorType,
|
||||
remoteExecutorName,
|
||||
updatedAt,
|
||||
lastActivityAt,
|
||||
showActivityTime = false,
|
||||
menuOpen = false,
|
||||
isDeleting,
|
||||
taskId,
|
||||
@@ -496,6 +504,8 @@ export const TaskItem = memo(function TaskItem({
|
||||
isPinned={isPinned}
|
||||
repositories={repositories}
|
||||
updatedAt={updatedAt}
|
||||
lastActivityAt={lastActivityAt}
|
||||
showActivityTime={showActivityTime}
|
||||
prInfo={prInfo}
|
||||
queuedCount={queuedCount}
|
||||
wipQueue={wipQueue}
|
||||
|
||||
@@ -4,6 +4,9 @@ import { buildSidebarItem } from "./task-session-sidebar-item";
|
||||
type SidebarTask = Parameters<typeof buildSidebarItem>[0];
|
||||
type SidebarContext = Parameters<typeof buildSidebarItem>[1];
|
||||
const UPDATED_AT = "2026-07-22T00:00:00Z";
|
||||
const ACTIVITY_AT = "2026-07-24T00:00:00Z";
|
||||
const CREATED_AT = "2026-07-20T00:00:00Z";
|
||||
const SUMMARY_UPDATED_AT = "2026-07-25T00:00:00Z";
|
||||
|
||||
function emptyContext(): SidebarContext {
|
||||
return {
|
||||
@@ -122,3 +125,41 @@ describe("buildSidebarItem", () => {
|
||||
expect(item.queuedCount).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSidebarItem activity", () => {
|
||||
it("maps summary activity and falls back through task update to creation", () => {
|
||||
const projected = buildSidebarItem(
|
||||
task({
|
||||
updatedAt: UPDATED_AT,
|
||||
createdAt: CREATED_AT,
|
||||
statusSummary: {
|
||||
revision: 6,
|
||||
updated_at: SUMMARY_UPDATED_AT,
|
||||
last_activity_at: ACTIVITY_AT,
|
||||
},
|
||||
}),
|
||||
emptyContext(),
|
||||
);
|
||||
expect(projected.updatedAt).toBe(SUMMARY_UPDATED_AT);
|
||||
expect(projected.lastActivityAt).toBe(ACTIVITY_AT);
|
||||
|
||||
const updatedFallback = buildSidebarItem(
|
||||
task({
|
||||
updatedAt: UPDATED_AT,
|
||||
createdAt: CREATED_AT,
|
||||
statusSummary: { revision: 7, updated_at: SUMMARY_UPDATED_AT },
|
||||
}),
|
||||
emptyContext(),
|
||||
);
|
||||
expect(updatedFallback.lastActivityAt).toBe(UPDATED_AT);
|
||||
|
||||
const createdFallback = buildSidebarItem(
|
||||
task({
|
||||
createdAt: CREATED_AT,
|
||||
statusSummary: { revision: 8, updated_at: SUMMARY_UPDATED_AT },
|
||||
}),
|
||||
emptyContext(),
|
||||
);
|
||||
expect(createdFallback.lastActivityAt).toBe(CREATED_AT);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,6 +68,13 @@ function issueInfoForTask(task: KanbanState["tasks"][number]) {
|
||||
return { url: task.issueUrl, number: task.issueNumber };
|
||||
}
|
||||
|
||||
function sidebarLastActivityAt(
|
||||
summary: TaskStatusSummary | null | undefined,
|
||||
task: KanbanState["tasks"][number],
|
||||
) {
|
||||
return summary?.last_activity_at ?? task.updatedAt ?? task.createdAt;
|
||||
}
|
||||
|
||||
function sidebarSessionStatus(
|
||||
summary: TaskStatusSummary | null | undefined,
|
||||
task: KanbanState["tasks"][number],
|
||||
@@ -85,6 +92,7 @@ function sidebarSessionStatus(
|
||||
foregroundActivity: hasSummary ? summary?.foreground_activity : task.foregroundActivity,
|
||||
primarySessionId: hasSummary ? (primarySession?.id ?? null) : (task.primarySessionId ?? null),
|
||||
updatedAt: hasSummary ? summary?.updated_at : (task.updatedAt ?? task.createdAt),
|
||||
lastActivityAt: sidebarLastActivityAt(summary, task),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@ export function buildTaskSwitcherProps(args: {
|
||||
stepsByWorkflowId: TaskSwitcherComponentProps["stepsByWorkflowId"];
|
||||
highlightedTaskId: string | null;
|
||||
highlightedSelectedTaskId: string | null;
|
||||
effectiveView: { collapsedGroups: TaskSwitcherComponentProps["collapsedGroupKeys"] };
|
||||
effectiveView: {
|
||||
collapsedGroups: TaskSwitcherComponentProps["collapsedGroupKeys"];
|
||||
sort: { key: string };
|
||||
};
|
||||
handleToggleGroup: TaskSwitcherComponentProps["onToggleGroup"];
|
||||
collapsedSubtaskParents: TaskSwitcherComponentProps["collapsedSubtaskParentIds"];
|
||||
toggleSubtaskCollapsed: TaskSwitcherComponentProps["onToggleSubtasks"];
|
||||
@@ -43,6 +46,7 @@ export function buildTaskSwitcherProps(args: {
|
||||
activeTaskId: args.highlightedTaskId,
|
||||
selectedTaskId: args.highlightedSelectedTaskId,
|
||||
collapsedGroupKeys: args.effectiveView.collapsedGroups,
|
||||
showActivityTime: args.effectiveView.sort.key === "lastActivityAt",
|
||||
onToggleGroup: args.handleToggleGroup,
|
||||
collapsedSubtaskParentIds: args.collapsedSubtaskParents,
|
||||
onToggleSubtasks: args.toggleSubtaskCollapsed,
|
||||
|
||||
@@ -21,6 +21,7 @@ export type TaskRowProps = {
|
||||
stepsByWorkflowId?: Record<string, StepDef[]>;
|
||||
activeTaskId: string | null;
|
||||
selectedTaskId: string | null;
|
||||
showActivityTime?: boolean;
|
||||
onSelectTask: (taskId: string) => void;
|
||||
onEditTask?: (task: TaskSwitcherItem) => void;
|
||||
onRenameTask?: (taskId: string, currentTitle: string) => void;
|
||||
@@ -91,6 +92,7 @@ type TaskRowItemProps = Pick<
|
||||
| "subtaskToggle"
|
||||
| "activeTaskId"
|
||||
| "selectedTaskId"
|
||||
| "showActivityTime"
|
||||
| "onSelectTask"
|
||||
| "selectedTaskIds"
|
||||
| "onToggleSelectTask"
|
||||
@@ -107,6 +109,7 @@ function TaskRowItem({
|
||||
subtaskToggle,
|
||||
activeTaskId,
|
||||
selectedTaskId,
|
||||
showActivityTime,
|
||||
onSelectTask,
|
||||
selectedTaskIds,
|
||||
onToggleSelectTask,
|
||||
@@ -154,6 +157,8 @@ function TaskRowItem({
|
||||
hasPendingClarification={task.hasPendingClarification}
|
||||
hasPendingPermission={task.hasPendingPermission}
|
||||
updatedAt={task.updatedAt}
|
||||
lastActivityAt={task.lastActivityAt}
|
||||
showActivityTime={showActivityTime}
|
||||
repositories={task.repositories}
|
||||
prInfo={task.prInfo}
|
||||
queuedCount={task.queuedCount}
|
||||
|
||||
@@ -36,6 +36,7 @@ export type TaskSwitcherItem = {
|
||||
remoteExecutorType?: string;
|
||||
remoteExecutorName?: string;
|
||||
updatedAt?: string;
|
||||
lastActivityAt?: string;
|
||||
createdAt?: string;
|
||||
isArchived?: boolean;
|
||||
primarySessionId?: string | null;
|
||||
@@ -91,6 +92,7 @@ export type TaskSwitcherProps = {
|
||||
onRetryLoad?: () => void;
|
||||
retryLabel?: string;
|
||||
totalTaskCount?: number;
|
||||
showActivityTime?: boolean;
|
||||
// Multi-select (cmd/shift click). When the selection is non-empty, plain
|
||||
// clicks toggle instead of navigating; the context menu acts on the selection.
|
||||
selectedTaskIds?: Set<string>;
|
||||
|
||||
@@ -20,6 +20,7 @@ function buildTaskRowProps(props: TaskSwitcherProps): TaskRowBaseProps {
|
||||
stepsByWorkflowId: props.stepsByWorkflowId,
|
||||
activeTaskId: props.activeTaskId,
|
||||
selectedTaskId: props.selectedTaskId,
|
||||
showActivityTime: props.showActivityTime,
|
||||
onSelectTask: props.onSelectTask,
|
||||
onEditTask: props.onEditTask,
|
||||
onRenameTask: props.onRenameTask,
|
||||
|
||||
Reference in New Issue
Block a user