mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Its task lists help people find and manage work across personal and organization views. > - Several personal views stop after 100 tasks, and Blocked stops after 200 tasks. > - Other lists have page reads but lack a consistent way to load more or retry a failed page. > - This pull request makes pagination available across every task-list view. > - People can reach older tasks, keep filters active, and retry without losing readable rows. ## Linked Issues or Issue Description **What happened?** Task lists have inconsistent pagination. Mine, Recent, and Unread stop at the first task batch. Blocked stops at 200 tasks. Everything has the same missing-page behavior before this PR. Some organization layouts and searches replace paged rows with separate capped queries. **Expected behavior** Every task-list view can load its remaining tasks. A failed later page keeps loaded tasks visible and offers a retry. **Steps to reproduce** 1. Use a company and account with more tasks than a view's first batch. 2. Open Mine, Recent, Unread, Everything, or Blocked and scroll to the bottom. 3. Try to reach older tasks. The affected views stop without a next-page control. 4. Check organization status views, Archived, search, and board layouts for consistent loading controls. **Paperclip version or commit** The affected code is present at base commit `53bebb59f907571228dfb85a834a38536f934aa6`. **Deployment mode** Observed on hosted staging. Verified locally from source on macOS arm64. GitHub searches found no duplicate open PR or directly matching issue. ## What Changed - Apply one task pagination control to personal, organization, status, archive, classic, and sandbox task lists. - Make Recent, Unread, and Everything page through touched tasks. Remove the shared 100-task display cutoff. - Filter unread tasks on the server before paging. - Keep Mine's coherent initial snapshot. Fetch older task pages through the existing authorized list API. - Add older pages to Blocked. Load Needs attention task details in batches from its existing task index. - Let the Tasks route supply paged search and board data to the shared list components, so separate capped queries cannot replace loaded pages. - Keep loaded rows visible during later-page loading and errors. Keep the retry control available when the final attention page fails. - Pause the classic and streamlined lists' automatic server-page reads after a later-page error. Keep an explicit retry button available to restart that page. - Keep one paging and retry control inside each task-list component for list and board layouts. - Reuse the same request filters for the first and later Legacy Inbox pages. - Preserve the array cache contract for archive rollback, live updates, and sharing the first page across tabs. - Update product documentation and cover the additional views with regression tests. ## Verification - Revision: `9275d37c06dc14d00b6759ad71fb6402252db84b`, based on `origin/master` at `53bebb59f907571228dfb85a834a38536f934aa6`. - Environment: macOS arm64, Node v25.6.1, pnpm 9.15.4. - From `ui/`, ran `pnpm exec vitest run src/components/IssuesList.paging.test.tsx src/pages/TaskListPagination.test.tsx src/pages/Issues.test.tsx src/hooks/useInboxTouchedIssues.test.tsx src/lib/inbox.test.ts src/lib/blockedInbox.test.ts src/lib/inboxArchiveCache.test.ts src/lib/inboxOrderPin.test.ts src/hooks/useSharedPolling.test.ts src/hooks/useSharedPollingSnapshot.test.tsx src/hooks/useTaskListCollection.test.tsx`: all 133 tests passed across 11 files. - Real IssuesList tests cover both UI modes. They verify that provided board and search pages stay visible, capped column and search queries do not run, and each layout has one paging and retry control. Only leaf row and board rendering are stubbed. - Real Inbox page tests load later Mine and Recent pages in both UI modes. They also check Unread's server filter, first-page and later-page filter agreement, and removal of the control after the last page. - Page tests cover All tasks, Active, Backlog, Done, Archived, Needs attention, Blocked, and classic Tasks with server search. Supporting UI services and row rendering are isolated. - Red-green regressions proved the old 100-task display cutoff and automatic retries after a failed page. The fixed lists keep readable rows and require an explicit retry after failure. - The work-limit test uses 500 full task fixtures across five pages. A deterministic counter throws above a linear task-ID read budget. Ten unchanged rerenders per page perform no collection work. - Tests also cover page overlap, duplicate observer events, last-page detection, loading and retry, account and company changes, archive rollback, live invalidation, and the fallback without IntersectionObserver. - Ran `pnpm --dir ui typecheck`: passed. - Ran `node scripts/check-test-budget.mjs --base origin/master`: passed for all four changed test files. - Ran `git diff --check origin/master...HEAD`: passed. - A prior `pnpm verify` attempt selected 2,319 files and started a broad server run. It was stopped to avoid duplicating broad CI for this UI change. That interrupted attempt is not a pass. - Full local build and browser acceptance of the modified pages were not run. [Greptile passed with 5/5 on this revision](https://github.com/paperclipai/paperclip/pull/23564#issuecomment-7362362373). Both inline review threads are resolved. [CI typecheck](https://github.com/paperclipai/paperclip/actions/runs/47004999629/job/143907916923) and [build](https://github.com/paperclipai/paperclip/actions/runs/47004999629/job/143907916990) passed. [Both required CI checks passed on this revision](https://github.com/paperclipai/paperclip/actions/runs/47004999629): `ci / e2e` and `ci / verify`. No CI checks remain pending or failed. Confirmation that automated design review has cleared the prior hold is still pending. ## Risks - Task updates can move rows between offset pages. The merge removes duplicate task IDs, and live refreshes update loaded pages. - Search and task filters cover loaded rows in personal views. Use Load more tasks to include older rows while filters are active. - Mine keeps the existing snapshot and access behavior. The change adds no database migration or public API contract. ## Model Used OpenAI `gpt-6.1-sol` through the Codex harness, with xhigh reasoning effort and tool use. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
427 lines
19 KiB
TypeScript
427 lines
19 KiB
TypeScript
import { PERSONAL_ARCHIVE_QUERY_KEY } from "@/lib/inboxArchiveCache";
|
|
import { companyProjectsQuery } from "@/lib/company-projects-query";
|
|
import { QueryErrorState, useQueryView } from "@/components/QueryView";
|
|
import { useShowAgentCreatedTasks } from "../hooks/useShowAgentCreatedTasks";
|
|
import { useCoordinatorWorkspaceEnabled } from "../hooks/useCoordinatorWorkspaceEnabled";
|
|
import { CoordinatorTaskViews } from "./CoordinatorTaskViews";
|
|
import { useDesignSandbox } from "../context/DesignSandboxContext";
|
|
import { DesignSandboxTasks } from "./DesignSandboxTasks";
|
|
import { useEffect, useMemo, useCallback, useRef, useState } from "react";
|
|
import type { ReactNode } from "react";
|
|
import { useLocation, useNavigate, useSearchParams } from "@/lib/router";
|
|
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
|
|
import { issuesApi } from "../api/issues";
|
|
import { agentsApi } from "../api/agents";
|
|
import { heartbeatsApi } from "../api/heartbeats";
|
|
import { useCompany } from "../context/CompanyContext";
|
|
import { useBreadcrumbs } from "../context/BreadcrumbContext";
|
|
import { collectLiveIssueIds } from "../lib/liveIssueIds";
|
|
import { usePublishSharedQueryData, useSharedPollingQuery } from "@/hooks/useSharedPolling";
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import { createIssueDetailLocationState } from "../lib/issueDetailBreadcrumb";
|
|
import { EmptyState } from "../components/EmptyState";
|
|
import { IssuesList } from "../components/IssuesList";
|
|
import { readIssueSortParams, type IssueSort } from "../lib/issue-sort";
|
|
import { readIssueUpdatedParams, writeIssueUpdatedParams, type IssueUpdatedFilter } from "../lib/issue-filters";
|
|
import { TaskViewsMenu } from "../components/TaskViewsMenu";
|
|
import { Button } from "@/components/ui/button";
|
|
import { CircleDot, Plus } from "lucide-react";
|
|
import type { Issue } from "@paperclipai/shared";
|
|
import { useStreamlinedUiEnabled } from "../hooks/useStreamlinedUiEnabled";
|
|
import { useCombinedInboxTasksEnabled } from "../hooks/useCombinedInboxTasksEnabled";
|
|
import { useDialogActions } from "../context/DialogContext";
|
|
import { useInboxBadge } from "../hooks/useInboxBadge";
|
|
import { Inbox } from "./Inbox";
|
|
import {
|
|
ORGANIZATION_SCOPED_PARAMS,
|
|
TASK_VIEW_PARAM,
|
|
loadLastTaskView,
|
|
normalizeTaskViewKey,
|
|
resolveInitialTaskView,
|
|
saveLastTaskView,
|
|
taskView,
|
|
type TaskViewKey,
|
|
} from "../lib/task-views";
|
|
import { useTaskArchiveAction } from "../hooks/useTaskArchiveAction";
|
|
import { useUpdateIssueMutation } from "../hooks/useUpdateIssueMutation";
|
|
import { usePageContentReady } from "../hooks/usePageContentReady";
|
|
|
|
const WORKSPACE_FILTER_ISSUE_LIMIT = 1000;
|
|
const ISSUES_PAGE_SIZE = 100;
|
|
export const ISSUES_ROW_PRESENTATION = "task" as const;
|
|
export const ISSUES_TOOLBAR_PRESENTATION = "collection" as const;
|
|
|
|
export function resolveIssuesPresentation(streamlinedUiEnabled: boolean) {
|
|
return streamlinedUiEnabled
|
|
? { rowPresentation: ISSUES_ROW_PRESENTATION, toolbarPresentation: ISSUES_TOOLBAR_PRESENTATION }
|
|
: { rowPresentation: "legacy" as const, toolbarPresentation: "legacy" as const };
|
|
}
|
|
|
|
export function getNextIssuesPageOffset(
|
|
loadedPageSize: number,
|
|
currentOffset: number,
|
|
pageSize: number = ISSUES_PAGE_SIZE,
|
|
): number | undefined {
|
|
return loadedPageSize >= pageSize ? currentOffset + pageSize : undefined;
|
|
}
|
|
|
|
export function mergeIssuePagesStable<T extends { id: string }>(pages: T[][]): T[] {
|
|
const seenIssueIds = new Set<string>();
|
|
const merged: T[] = [];
|
|
|
|
for (const page of pages) {
|
|
for (const issue of page) {
|
|
if (seenIssueIds.has(issue.id)) continue;
|
|
seenIssueIds.add(issue.id);
|
|
merged.push(issue);
|
|
}
|
|
}
|
|
|
|
return merged;
|
|
}
|
|
|
|
export function buildIssuesSearchUrl(currentHref: string, search: string): string | null {
|
|
const url = new URL(currentHref);
|
|
const currentSearch = url.searchParams.get("q") ?? "";
|
|
if (currentSearch === search) return null;
|
|
|
|
if (search.length > 0) {
|
|
url.searchParams.set("q", search);
|
|
} else {
|
|
url.searchParams.delete("q");
|
|
}
|
|
|
|
return `${url.pathname}${url.search}${url.hash}`;
|
|
}
|
|
|
|
/**
|
|
* Tasks — the single task surface after PAP-670 merged Inbox into it.
|
|
*
|
|
* This component only resolves `?view=` to a view and hands off: My-work views
|
|
* render the inbox list, organization views render the task collection. Both
|
|
* get the same Views control in their toolbar, so the switch reads as one page.
|
|
*/
|
|
export function Issues() {
|
|
const designSandbox = useDesignSandbox();
|
|
const { enabled: streamlinedUiEnabled } = useStreamlinedUiEnabled();
|
|
const { enabled: combinedInboxTasksEnabled } = useCombinedInboxTasksEnabled();
|
|
const { enabled: coordinatorEnabled } = useCoordinatorWorkspaceEnabled();
|
|
// The merged surface is Combined Inbox + Task List only. With the flag off, and always in
|
|
// the legacy shell, Tasks is the plain task list and Inbox keeps its pages.
|
|
return designSandbox ? <DesignSandboxTasks /> : coordinatorEnabled ? <CoordinatorTaskViews /> : streamlinedUiEnabled && combinedInboxTasksEnabled ? <StreamlinedTasks /> : <OrganizationIssues />;
|
|
}
|
|
|
|
function StreamlinedTasks() {
|
|
const navigate = useNavigate();
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
const { selectedCompanyId } = useCompany();
|
|
const { openNewIssue } = useDialogActions();
|
|
const inboxBadge = useInboxBadge(selectedCompanyId);
|
|
|
|
const requestedView = searchParams.get(TASK_VIEW_PARAM);
|
|
const hasOrganizationScopedParam = ORGANIZATION_SCOPED_PARAMS.some(
|
|
(param) => (searchParams.get(param) ?? "").length > 0,
|
|
);
|
|
// Read the stored view once per mount so a later write can't yank the view
|
|
// out from under the user mid-session.
|
|
const [lastUsedView] = useState<TaskViewKey>(() => loadLastTaskView());
|
|
const view = resolveInitialTaskView(requestedView, hasOrganizationScopedParam, lastUsedView);
|
|
const definition = taskView(view);
|
|
|
|
// Make the resolved view addressable without dropping the params that
|
|
// brought the user here — and correct a requested view that was overridden
|
|
// (an inbox view carrying an organization filter opens All tasks).
|
|
useEffect(() => {
|
|
if (normalizeTaskViewKey(requestedView) === view) return;
|
|
setSearchParams((current) => {
|
|
const next = new URLSearchParams(current);
|
|
next.set(TASK_VIEW_PARAM, view);
|
|
return next;
|
|
}, { replace: true });
|
|
}, [requestedView, view, setSearchParams]);
|
|
|
|
const selectView = useCallback((next: TaskViewKey) => {
|
|
saveLastTaskView(next);
|
|
// A view switch starts clean: the previous view's search and filters are
|
|
// its own, not the new view's.
|
|
navigate(`/issues?${TASK_VIEW_PARAM}=${next}`);
|
|
}, [navigate]);
|
|
|
|
const viewsMenu = (
|
|
<TaskViewsMenu value={view} onChange={selectView} badgeCount={inboxBadge.inbox} />
|
|
);
|
|
|
|
if (definition.surface === "inbox") {
|
|
return (
|
|
<Inbox
|
|
tab={definition.inboxTab}
|
|
surfaceLabel="Tasks"
|
|
toolbarContext={(
|
|
<div className="flex min-w-0 items-center gap-2">
|
|
{viewsMenu}
|
|
<Button size="sm" variant="outline" aria-label="New Task" onClick={() => openNewIssue()}>
|
|
<Plus className="h-4 w-4 sm:mr-1" />
|
|
<span className="hidden sm:inline">New Task</span>
|
|
</Button>
|
|
</div>
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return <OrganizationIssues toolbarContext={viewsMenu} initialStatuses={definition.statuses} archiveView={view === "archived" ? "archived" : "include"} />;
|
|
}
|
|
|
|
function OrganizationIssues({
|
|
toolbarContext,
|
|
initialStatuses,
|
|
archiveView,
|
|
}: { toolbarContext?: ReactNode; initialStatuses?: string[]; archiveView?: "archived" | "include" } = {}) {
|
|
const { enabled: streamlinedUiEnabled } = useStreamlinedUiEnabled();
|
|
const issuesPresentation = resolveIssuesPresentation(streamlinedUiEnabled);
|
|
const { selectedCompanyId } = useCompany();
|
|
const { userId, loaded: identitySettled } = useCoordinatorWorkspaceEnabled();
|
|
const inboxArchive = userId ? archiveView : undefined;
|
|
const archiveQueryScope = JSON.stringify([selectedCompanyId, userId, inboxArchive]);
|
|
const getArchiveAction = useTaskArchiveAction(selectedCompanyId, userId);
|
|
const { setBreadcrumbs } = useBreadcrumbs();
|
|
const location = useLocation();
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
const fetchNextPageInFlightRef = useRef(false);
|
|
|
|
const urlSearch = searchParams.get("q") ?? "";
|
|
const [searchOverride, setSearchOverride] = useState<{ search: string; locationSearch: string } | null>(null);
|
|
const syncedSearch = useMemo(() => {
|
|
if (typeof window !== "undefined" && searchOverride?.locationSearch === window.location.search) {
|
|
return searchOverride.search;
|
|
}
|
|
return urlSearch;
|
|
}, [searchOverride, urlSearch, location.search]);
|
|
const showAgentCreatedTasks = useShowAgentCreatedTasks(selectedCompanyId, "paperclip:issues-view");
|
|
const sort = useMemo(() => readIssueSortParams(searchParams), [searchParams]);
|
|
const includeBlockedBy = sort?.sortField === "workflow";
|
|
const serverSortField = sort?.sortField === "created" ? "created" : "updated";
|
|
const serverSortDir = sort?.sortField === "created" || sort?.sortField === "updated" ? sort.sortDir : "desc";
|
|
// React Router does not queue functional search updates, so writes made in the
|
|
// same event (Clear resets several URL filters) build on each other here.
|
|
const pendingSearchParamsRef = useRef<URLSearchParams | null>(null);
|
|
const writeTaskParams = useCallback((mutate: (next: URLSearchParams) => void) => {
|
|
setSearchParams(current => {
|
|
const next = new URLSearchParams(pendingSearchParamsRef.current ?? current);
|
|
if (syncedSearch) next.set("q", syncedSearch);
|
|
else next.delete("q");
|
|
mutate(next);
|
|
if (!pendingSearchParamsRef.current) queueMicrotask(() => { pendingSearchParamsRef.current = null; });
|
|
pendingSearchParamsRef.current = next;
|
|
return next;
|
|
}, { replace: true });
|
|
}, [setSearchParams, syncedSearch]);
|
|
const handleSortChange = useCallback((nextSort: IssueSort) => {
|
|
writeTaskParams(next => {
|
|
next.set("sortField", nextSort.sortField);
|
|
next.set("sortDir", nextSort.sortDir);
|
|
});
|
|
}, [writeTaskParams]);
|
|
const [updatedBefore, setUpdatedBefore] = useState<string | undefined>(undefined);
|
|
// The Tasks URL owns the Updated filter, so a filtered link opens filtered.
|
|
const urlUpdated = searchParams.get("updated");
|
|
const urlUpdatedFrom = searchParams.get("updatedFrom");
|
|
const urlUpdatedTo = searchParams.get("updatedTo");
|
|
const updatedFilter = useMemo(() => readIssueUpdatedParams(new URLSearchParams({
|
|
...(urlUpdated ? { updated: urlUpdated } : {}),
|
|
...(urlUpdatedFrom ? { updatedFrom: urlUpdatedFrom } : {}),
|
|
...(urlUpdatedTo ? { updatedTo: urlUpdatedTo } : {}),
|
|
})), [urlUpdated, urlUpdatedFrom, urlUpdatedTo]);
|
|
const handleUpdatedFilterChange = useCallback((filter: IssueUpdatedFilter) => {
|
|
writeTaskParams(next => writeIssueUpdatedParams(next, filter));
|
|
}, [writeTaskParams]);
|
|
const routineTasksOnly = searchParams.get("originKind") === "routine_execution";
|
|
const includeAgentCreatedTasks = showAgentCreatedTasks || routineTasksOnly;
|
|
const originKind = routineTasksOnly ? "routine_execution" : undefined;
|
|
const handleRoutineTasksOnlyChange = useCallback((checked: boolean) => {
|
|
writeTaskParams(next => {
|
|
if (checked) next.set("originKind", "routine_execution");
|
|
else next.delete("originKind");
|
|
});
|
|
}, [writeTaskParams]);
|
|
const participantAgentId = searchParams.get("participantAgentId") ?? undefined;
|
|
const initialWorkspaces = searchParams.getAll("workspace").filter((workspaceId) => workspaceId.length > 0);
|
|
const workspaceIdFilter = initialWorkspaces.length === 1 ? initialWorkspaces[0] : undefined;
|
|
const handleSearchChange = useCallback((search: string) => {
|
|
const nextUrl = buildIssuesSearchUrl(window.location.href, search);
|
|
if (!nextUrl) {
|
|
setSearchOverride(null);
|
|
return;
|
|
}
|
|
window.history.replaceState(window.history.state, "", nextUrl);
|
|
setSearchOverride({ search, locationSearch: window.location.search });
|
|
}, []);
|
|
|
|
const { data: agents } = useQuery({
|
|
queryKey: queryKeys.agents.list(selectedCompanyId!),
|
|
queryFn: () => agentsApi.list(selectedCompanyId!),
|
|
enabled: !!selectedCompanyId,
|
|
});
|
|
|
|
const { data: projects } = useQuery({
|
|
...companyProjectsQuery(selectedCompanyId!, { includeArchived: true }),
|
|
enabled: !!selectedCompanyId,
|
|
});
|
|
|
|
const liveRunsQueryKey = queryKeys.liveRuns(selectedCompanyId!);
|
|
const sharedLiveRuns = useSharedPollingQuery({
|
|
companyId: selectedCompanyId,
|
|
resourceKey: "live-runs",
|
|
queryKey: liveRunsQueryKey,
|
|
enabled: !!selectedCompanyId,
|
|
// Event-sourced via LiveUpdatesProvider (GitHub issue 9627); no interval poll needed.
|
|
refetchInterval: false,
|
|
leaderOnly: true,
|
|
});
|
|
const { data: liveRuns, dataUpdatedAt: liveRunsUpdatedAt } = useQuery({
|
|
queryKey: liveRunsQueryKey,
|
|
queryFn: () => heartbeatsApi.liveRunsForCompany(selectedCompanyId!),
|
|
enabled: sharedLiveRuns.enabled,
|
|
refetchInterval: sharedLiveRuns.refetchInterval,
|
|
});
|
|
usePublishSharedQueryData(sharedLiveRuns, liveRuns, liveRunsUpdatedAt);
|
|
|
|
const issueLinkState = useMemo(
|
|
() =>
|
|
createIssueDetailLocationState(
|
|
"Tasks",
|
|
`${location.pathname}${location.search}${location.hash}`,
|
|
"issues",
|
|
),
|
|
[location.pathname, location.search, location.hash],
|
|
);
|
|
|
|
useEffect(() => {
|
|
setBreadcrumbs([{ label: "Tasks" }]);
|
|
}, [setBreadcrumbs]);
|
|
|
|
const issuePageSize = workspaceIdFilter ? WORKSPACE_FILTER_ISSUE_LIMIT : ISSUES_PAGE_SIZE;
|
|
|
|
const issuesQuery = useInfiniteQuery({
|
|
queryKey: [
|
|
...queryKeys.issues.list(selectedCompanyId!),
|
|
"participant-agent",
|
|
participantAgentId ?? "__all__",
|
|
"workspace",
|
|
workspaceIdFilter ?? "__all__",
|
|
streamlinedUiEnabled ? "index" : "compact",
|
|
"with-routine-executions",
|
|
includeAgentCreatedTasks,
|
|
originKind,
|
|
"infinite",
|
|
syncedSearch.trim(),
|
|
issuePageSize,
|
|
serverSortField,
|
|
serverSortDir,
|
|
includeBlockedBy,
|
|
updatedBefore ?? "__any__",
|
|
PERSONAL_ARCHIVE_QUERY_KEY,
|
|
archiveQueryScope,
|
|
],
|
|
queryFn: ({ pageParam, signal }) => issuesApi.listCompact(selectedCompanyId!, {
|
|
projection: streamlinedUiEnabled ? "index" : undefined,
|
|
q: syncedSearch.trim() || undefined,
|
|
participantAgentId,
|
|
inboxArchive,
|
|
workspaceId: workspaceIdFilter,
|
|
includeRoutineExecutions: true,
|
|
includeAgentCreatedTasks,
|
|
originKind,
|
|
limit: issuePageSize,
|
|
offset: pageParam,
|
|
sortField: serverSortField,
|
|
sortDir: serverSortDir,
|
|
includeBlockedBy: includeBlockedBy || undefined,
|
|
updatedBefore,
|
|
}, { signal }),
|
|
initialPageParam: 0,
|
|
getNextPageParam: (lastPage, _allPages, lastPageParam) =>
|
|
getNextIssuesPageOffset(lastPage.length, lastPageParam, issuePageSize),
|
|
enabled: !!selectedCompanyId && (archiveView !== "archived" || !!userId),
|
|
placeholderData: (previousData, previousQuery) =>
|
|
previousQuery?.queryKey.at(-1) === archiveQueryScope ? previousData : undefined,
|
|
});
|
|
|
|
const { data: issuePages, isFetchingNextPage, hasNextPage, fetchNextPage } = issuesQuery;
|
|
const issuesView = useQueryView({ ...issuesQuery, ...(issuesQuery.isFetchNextPageError ? { error: null, status: "success" as const } : {}) });
|
|
// The task list is loaded once its first page of rows has rendered.
|
|
usePageContentReady(!selectedCompanyId || (issuesView.kind !== "loading" && issuesView.kind !== "reconnecting"));
|
|
const issues = useMemo(() => mergeIssuePagesStable(issuePages?.pages ?? []) as Issue[], [issuePages]);
|
|
const liveIssueIds = useMemo(() => collectLiveIssueIds(liveRuns, issues), [issues, liveRuns]);
|
|
const hasMoreServerIssues = hasNextPage === true;
|
|
const loadMoreServerIssues = useCallback(() => {
|
|
if (!hasNextPage || isFetchingNextPage || fetchNextPageInFlightRef.current) return;
|
|
fetchNextPageInFlightRef.current = true;
|
|
void fetchNextPage({ cancelRefetch: false }).finally(() => {
|
|
fetchNextPageInFlightRef.current = false;
|
|
});
|
|
}, [fetchNextPage, hasNextPage, isFetchingNextPage]);
|
|
|
|
// Optimistic, rolls back with a readable toast, and resends after an outage.
|
|
const updateIssue = useUpdateIssueMutation({ companyId: selectedCompanyId });
|
|
|
|
if (!selectedCompanyId) {
|
|
return (
|
|
<EmptyState
|
|
icon={CircleDot}
|
|
message={streamlinedUiEnabled
|
|
? "Select an organization to view tasks."
|
|
: "Select a company to view tasks."}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (archiveView === "archived" && !userId) return identitySettled
|
|
? <EmptyState icon={CircleDot} message="Sign in to view archived tasks." />
|
|
: <p role="status">Loading archived tasks…</p>;
|
|
|
|
if (issuesView.kind === "error") return <QueryErrorState size="page" error={issuesView.error} action="load tasks" onRetry={issuesView.retry} retrying={issuesView.isFetching} />;
|
|
|
|
return (
|
|
<IssuesList
|
|
key={archiveView === "archived" ? "archived" : undefined}
|
|
issues={issues ?? []}
|
|
getArchiveAction={getArchiveAction}
|
|
preloadTaskChats
|
|
pagedIssuesProvided
|
|
isLoading={issuesView.kind === "loading" || issuesView.kind === "reconnecting"}
|
|
isLoadingMoreIssues={isFetchingNextPage}
|
|
agents={agents}
|
|
projects={projects}
|
|
liveIssueIds={liveIssueIds}
|
|
viewStateKey="paperclip:issues-view"
|
|
rowPresentation={issuesPresentation.rowPresentation}
|
|
toolbarPresentation={issuesPresentation.toolbarPresentation}
|
|
issueLinkState={issueLinkState}
|
|
initialAssignees={searchParams.get("assignee") ? [searchParams.get("assignee")!] : undefined}
|
|
initialWorkspaces={initialWorkspaces.length > 0 ? initialWorkspaces : undefined}
|
|
initialStatuses={initialStatuses}
|
|
toolbarContext={toolbarContext}
|
|
initialSearch={syncedSearch}
|
|
onSearchChange={handleSearchChange}
|
|
enableAgentCreatedVisibilityFilter
|
|
routineTasksOnly={routineTasksOnly}
|
|
onRoutineTasksOnlyChange={handleRoutineTasksOnlyChange}
|
|
sort={sort}
|
|
onSortChange={handleSortChange}
|
|
onUpdatedBeforeChange={setUpdatedBefore}
|
|
updatedFilter={updatedFilter}
|
|
onUpdatedFilterChange={handleUpdatedFilterChange}
|
|
hasMoreIssues={hasMoreServerIssues && !issuesQuery.isFetchNextPageError}
|
|
onLoadMoreIssues={issuesQuery.isFetchNextPageError ? undefined : loadMoreServerIssues}
|
|
loadMoreIssuesError={issuesQuery.isFetchNextPageError ? issuesQuery.error : null}
|
|
onRetryLoadMoreIssues={loadMoreServerIssues}
|
|
onUpdateIssue={(id, data) => updateIssue.mutate({ id, data })}
|
|
searchFilters={participantAgentId || workspaceIdFilter || originKind || includeBlockedBy || inboxArchive || updatedBefore ? {
|
|
participantAgentId, workspaceId: workspaceIdFilter, originKind, inboxArchive, updatedBefore,
|
|
...(includeBlockedBy ? { includeBlockedBy: true } : {}),
|
|
} : undefined}
|
|
/>
|
|
);
|
|
}
|