feat(web): archive the current task from the command palette (#2346)
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,9 @@
|
||||
|
||||
import { useCallback, useState, type ReactNode } from "react";
|
||||
import { IconGitMerge, IconGitPullRequestClosed, IconX } from "@tabler/icons-react";
|
||||
import { TaskArchiveConfirmDialog } from "@/components/task/task-archive-confirm-dialog";
|
||||
import { useAppStore, useAppStoreApi } from "@/components/state-provider";
|
||||
import { useArchiveAndSwitchTask } from "@/hooks/use-task-actions";
|
||||
import { useToast } from "@/components/toast-provider";
|
||||
import { findTaskInSnapshots } from "@/lib/kanban/find-task";
|
||||
import { TaskArchiveConfirmFlow } from "@/components/task/task-archive-confirm-flow";
|
||||
import { useAppStore } from "@/components/state-provider";
|
||||
import { useTaskArchiveConfirm } from "@/hooks/use-task-archive-confirm";
|
||||
import {
|
||||
markPRClosedBannerDismissed,
|
||||
markPRMergedBannerDismissed,
|
||||
@@ -15,47 +13,6 @@ import {
|
||||
} from "@/lib/local-storage";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type ArchiveTarget = { title: string; executorType?: string | null };
|
||||
|
||||
// Archiving from the terminal-state banners goes through the same confirmation
|
||||
// dialog as every other archive surface. Only failures toast; on success the
|
||||
// archive-and-switch flow moves the user to the next task.
|
||||
function useBannerArchiveConfirm(taskId: string) {
|
||||
const { t } = useTranslation();
|
||||
const store = useAppStoreApi();
|
||||
const archiveAndSwitch = useArchiveAndSwitchTask();
|
||||
const { toast } = useToast();
|
||||
const [target, setTarget] = useState<ArchiveTarget | null>(null);
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
|
||||
const requestArchive = useCallback(() => {
|
||||
const state = store.getState();
|
||||
const task = findTaskInSnapshots(taskId, state.kanbanMulti.snapshots, state.kanban.tasks);
|
||||
setTarget({
|
||||
title: task?.title ?? t("task:thisTask"),
|
||||
executorType: task?.primaryExecutorType,
|
||||
});
|
||||
}, [store, taskId]);
|
||||
|
||||
const closeConfirm = useCallback(() => setTarget(null), []);
|
||||
|
||||
const confirmArchive = useCallback(
|
||||
async ({ cascade }: { cascade: boolean }) => {
|
||||
setIsPending(true);
|
||||
try {
|
||||
await archiveAndSwitch(taskId, { cascade });
|
||||
} catch {
|
||||
toast({ description: t("task:failedToArchiveTask"), variant: "error" });
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
},
|
||||
[archiveAndSwitch, taskId, toast],
|
||||
);
|
||||
|
||||
return { target, requestArchive, closeConfirm, confirmArchive, isPending };
|
||||
}
|
||||
|
||||
// Presentational banner shared by PRMergedBanner / PRClosedBanner — an icon, a
|
||||
// message, and Archive + Dismiss controls. Colors/icon/testIds are supplied by
|
||||
// the caller so the two variants stay visually distinct. The Archive control
|
||||
@@ -80,8 +37,7 @@ function ArchiveDismissBanner({
|
||||
onDismiss: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { target, requestArchive, closeConfirm, confirmArchive, isPending } =
|
||||
useBannerArchiveConfirm(taskId);
|
||||
const archive = useTaskArchiveConfirm(taskId);
|
||||
return (
|
||||
<>
|
||||
<div data-testid={`${testIdPrefix}-banner`} className={containerClass}>
|
||||
@@ -90,7 +46,7 @@ function ArchiveDismissBanner({
|
||||
<button
|
||||
type="button"
|
||||
data-testid={`${testIdPrefix}-archive-button`}
|
||||
onClick={requestArchive}
|
||||
onClick={archive.requestArchive}
|
||||
className={archiveClass}
|
||||
>
|
||||
{t("task:archive")}
|
||||
@@ -105,16 +61,9 @@ function ArchiveDismissBanner({
|
||||
<IconX className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
<TaskArchiveConfirmDialog
|
||||
open={target !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) closeConfirm();
|
||||
}}
|
||||
taskTitle={target?.title ?? ""}
|
||||
<TaskArchiveConfirmFlow
|
||||
taskId={taskId}
|
||||
executorType={target?.executorType}
|
||||
isArchiving={isPending}
|
||||
onConfirm={confirmArchive}
|
||||
archive={archive}
|
||||
confirmTestId={`${testIdPrefix}-archive-confirm`}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { TaskArchiveConfirmDialog } from "@/components/task/task-archive-confirm-dialog";
|
||||
import type { useTaskArchiveConfirm } from "@/hooks/use-task-archive-confirm";
|
||||
|
||||
type TaskArchiveConfirmFlowProps = {
|
||||
taskId: string;
|
||||
archive: ReturnType<typeof useTaskArchiveConfirm>;
|
||||
/** Test id for the dialog's Archive button — the only per-surface difference. */
|
||||
confirmTestId: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Binds a `useTaskArchiveConfirm` result to the shared confirmation dialog, so
|
||||
* every archive entry point maps the hook onto the dialog the same way and a
|
||||
* dialog prop change lands in one place.
|
||||
*/
|
||||
export function TaskArchiveConfirmFlow({
|
||||
taskId,
|
||||
archive,
|
||||
confirmTestId,
|
||||
}: TaskArchiveConfirmFlowProps) {
|
||||
return (
|
||||
<TaskArchiveConfirmDialog
|
||||
open={archive.target !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) archive.closeConfirm();
|
||||
}}
|
||||
taskTitle={archive.target?.title ?? ""}
|
||||
taskId={taskId}
|
||||
executorType={archive.target?.executorType}
|
||||
isArchiving={archive.isPending}
|
||||
onConfirm={archive.confirmArchive}
|
||||
confirmTestId={confirmTestId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -208,7 +208,12 @@ function TaskDebugOverlay({ entries }: { entries: ReturnType<typeof maybeBuildDe
|
||||
return <DebugOverlay title={t("task:taskDebug")} entries={entries} />;
|
||||
}
|
||||
|
||||
export function TaskPageInner({
|
||||
/**
|
||||
* Derives everything the task page renders from its inputs: the resolved task
|
||||
* props plus the three prop bundles handed to the debug overlay, top bar, and
|
||||
* layout. Kept out of `TaskPageInner` so that component stays a wiring shell.
|
||||
*/
|
||||
function useTaskPageDerivedProps({
|
||||
task,
|
||||
effectiveSessionId,
|
||||
repository,
|
||||
@@ -219,8 +224,6 @@ export function TaskPageInner({
|
||||
agentctlStatus,
|
||||
connectionStatus,
|
||||
workflowSteps,
|
||||
archivedValue,
|
||||
isMobile,
|
||||
showDebugOverlay,
|
||||
onToggleDebugOverlay,
|
||||
initialScripts,
|
||||
@@ -228,7 +231,6 @@ export function TaskPageInner({
|
||||
defaultLayouts,
|
||||
initialLayout,
|
||||
officeTaskHref,
|
||||
ensureSession,
|
||||
onTaskUnarchived,
|
||||
}: TaskPageInnerProps) {
|
||||
const taskProps = resolveTaskProps(task, repository);
|
||||
@@ -275,6 +277,14 @@ export function TaskPageInner({
|
||||
initialLayout,
|
||||
});
|
||||
|
||||
return { taskProps, debugEntries, topBarProps, layoutProps };
|
||||
}
|
||||
|
||||
export function TaskPageInner(props: TaskPageInnerProps) {
|
||||
const { effectiveSessionId, task, merged, sessionPanel, archivedValue, isMobile, ensureSession } =
|
||||
props;
|
||||
const { taskProps, debugEntries, topBarProps, layoutProps } = useTaskPageDerivedProps(props);
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<VcsDialogsProvider
|
||||
@@ -290,6 +300,7 @@ export function TaskPageInner({
|
||||
isAgentRunning={merged.isAgentWorking}
|
||||
hasWorktree={Boolean(merged.worktreeBranch)}
|
||||
isPassthrough={sessionPanel.isSessionPassthrough}
|
||||
isTaskArchived={archivedValue.isArchived}
|
||||
/>
|
||||
<TaskPRShortcut taskId={taskProps.taskId} />
|
||||
<TaskDebugOverlay entries={debugEntries} />
|
||||
|
||||
Reference in New Issue
Block a user