TypeScript
feat(scheduled-tasks): tasks link to their thread (#31764)
Theo Browne4a087861d076
diff --git a/apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsxindex 34dd75e7500..6e90e449359 100644--- a/apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx+++ b/apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx@@ -18,7 +18,9 @@ import {MAX_WEBHOOK_DELIVERY_AGE_MINUTES,MAX_WEBHOOK_FILTERS,resolveEnvironmentMachineKind,+ scheduledTaskThreadMode,} from "@t3tools/contracts";+import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";import type { MenuAction } from "@react-native-menu/menu";import { DateTimePicker } from "@expo/ui/community/datetime-picker";import {@@ -1412,6 +1414,7 @@ function EnvironmentTasks({label: "scheduled task delete",reportFailure: false,});+ const selectDetail = useSelectWorkspaceDetail();const failure = (title: string, result: AtomCommandResult<unknown, unknown>) => {if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {Dialog.alert(title, String(squashAtomCommandFailure(result)));@@ -1493,6 +1496,9 @@ function EnvironmentTasks({<Menuactions={[{ id: "edit", title: "Edit" },+ ...(task.threadId !== null && scheduledTaskThreadMode(task) !== "new_thread"+ ? [{ id: "thread", title: "Open thread" }]+ : []),{id: "toggle",title: task.enabled ? "Pause" : "Resume",@@ -1511,6 +1517,14 @@ function EnvironmentTasks({const action = nativeEvent.event;if (action === "edit") {onEdit(task);+ } else if (action === "thread" && task.threadId !== null) {+ selectDetail({+ name: "Thread",+ params: {+ environmentId: String(environmentId),+ threadId: String(task.threadId),+ },+ });} else if (action === "delete") {Dialog.alert("Delete task?", task.title, [{ text: "Cancel", style: "cancel" },diff --git a/apps/web/src/components/settings/ScheduledTasksSettings.tsx b/apps/web/src/components/settings/ScheduledTasksSettings.tsxindex fbff362b78e..55efbec7508 100644--- a/apps/web/src/components/settings/ScheduledTasksSettings.tsx+++ b/apps/web/src/components/settings/ScheduledTasksSettings.tsx@@ -39,6 +39,7 @@ import {MIN_SCHEDULED_TASK_INTERVAL_MS,ProviderInstanceId,resolveEnvironmentMachineKind,+ scheduledTaskThreadMode,} from "@t3tools/contracts";import {isAtomCommandInterrupted,@@ -60,7 +61,8 @@ import {useEnvironmentHttpBaseUrl,type EnvironmentPresentation,} from "../../state/environments";-import { useProjects, useThreadShell } from "../../state/entities";+import { useProjects, useQuietThreadShell, useThreadShell } from "../../state/entities";+import { buildThreadRouteParams } from "../../threadRoutes";import { scopeThreadRef } from "@t3tools/client-runtime/environment";import { environmentAtomList, environmentIdsKey } from "../../state/environmentAtomList";import { formatEnvironmentQueryError, useEnvironmentQuery } from "../../state/query";@@ -787,6 +789,9 @@ function ScheduledTaskRow({{task.lastRunStatus !== "never" ? (<Badge variant={statusVariant(task.lastRunStatus)}>{task.lastRunStatus}</Badge>) : null}+ {task.threadId !== null && scheduledTaskThreadMode(task) !== "new_thread" ? (+ <ScheduledTaskThreadLink environmentId={environmentId} threadId={task.threadId} />+ ) : null}{task.lastRunError ? <span className="text-destructive">{task.lastRunError}</span> : null}</div>}@@ -847,6 +852,26 @@ function ScheduledTaskRow({);}+function ScheduledTaskThreadLink({+ environmentId,+ threadId,+}: {+ readonly environmentId: EnvironmentId;+ readonly threadId: ThreadId;+}) {+ const ref = scopeThreadRef(environmentId, threadId);+ const title = useQuietThreadShell(ref)?.title.trim();+ return (+ <Link+ to="/$environmentId/$threadId"+ params={buildThreadRouteParams(ref)}+ className="max-w-64 truncate underline underline-offset-2 hover:text-foreground"+ >+ {title || "Open thread"}+ </Link>+ );+}+function WebhookDeliveriesDialog({environmentId,task,