mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-13 03:15:34 +02:00
* MUL-3903 refactor project issue surface state Co-authored-by: multica-agent <github@multica.ai> * Refactor project issue surface ownership Co-authored-by: multica-agent <github@multica.ai> * Extract shared issue surface entrypoints Co-authored-by: multica-agent <github@multica.ai> * Fix issue surface create defaults and selection reset Co-authored-by: multica-agent <github@multica.ai> * test(editor): add missing AbortSignal to suggestion items() calls The suggestion items() contract gained a required signal param; the mention/slash test call sites were never updated, breaking pnpm typecheck for @multica/views. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(issues): server-side assignee_types filter on ListIssues ListGroupedIssues has taken assignee_types since squads shipped, but ListIssues never did — so the workspace Members/Agents tabs had to fetch the unfiltered workspace list and post-filter loaded pages client-side, which made column totals and load-more pagination reflect the unfiltered counts. Add the same parse + WHERE clause to ListIssues (count query shares the WHERE, so totals agree), thread the param through the TS client, and widen MyIssuesFilter so scoped list caches can carry it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(issues): route issue cache writes through a membership-aware coordinator useUpdateIssue, useBatchUpdateIssues, and the WS issue:updated handler each maintained their own similar-but-diverging patch/invalidate rules. Consolidate them into cache-coordinator.ts (applyIssueChange / rollbackIssueChange / invalidateIssueDerivatives) so local writes and remote echoes follow one rules table by construction. The coordinator is membership-aware via surface/membership.ts (true | false | unknown against each list cache's own filter contract): - a change that moves an issue off a filtered surface removes the card surgically (bucket total decremented) — fixes assignee changes leaving stale cards on My Assigned with no local safety net (previously only the WS echo recovered it), and replaces the blanket invalidate-myAll net for project moves (MUL-3669) with per-key precision - possible entry into a loaded list marks that key stale — never hard-insert; page/slot is server knowledge - stale keys flush on settle for mutations (a mid-flight refetch would stomp the optimistic state) and immediately for WS - batch updates now patch detail + inbox like single updates; the off-screen bucket-count recovery previously exclusive to the WS path now covers local mutations too Preserved invariants: synchronous optimistic patches (dnd-kit), MUL-3375 control-field stripping, and no refetch of surgically reconciled lists (the drag-flicker fix). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(issues): resolve surfaces via core query plan/repository with window-keyed remount Read-path convergence and the loading/empty semantics that fall out of it: - scope -> API params moves from scope.ts helpers into surface/query-plan.ts; workspace members/agents become server-filtered scoped plans (assignee_types) and the client postFilter machinery is deleted — tab counts and load-more are now exact - query selection moves behind surface/repository.ts; the views data hook no longer branches on workspace-vs-scoped plumbing - IssueSurfaceContent remounts on data-window change (wsId + scope): keepPreviousData placeholders keep sort/filter changes flicker-free within one window but must never let project A's (or workspace A's) cards impersonate B's with no loading state — cold window shows the skeleton, warm window hits cache instantly - isEmpty is only asserted from full-window data; the gantt scheduled-only projection can't prove the window is empty, so GanttView's own "no scheduled issues" empty state renders instead of the generic create-issue one - per-card project lookups hoist into a surface-level projectMap (drops a per-card useQuery), create-defaults typing tightens to IssueCreateDefaults Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * perf(issues): count-only arithmetic for off-window status/membership changes An issue beyond a list's loaded page window used to force a full first-page refetch just to fix two column counts. When the change is CERTAIN (base entity known, membership definitive) the coordinator now does the arithmetic locally: - stayed a member + status changed: move one unit of total between the two buckets (loaded arrays untouched; hasMore stays consistent) - left the list (reassigned / re-projected): old status bucket total -1 - member-to-member reassignment: counts unaffected, not even a stale key Entering a list and any uncertainty (no base, unknown membership) still refetch — the right page/slot is server knowledge. Branches on membership OUTCOMES, not on which field changed, so future dimensions (team) join automatically. Biggest win is the WS path: agents flipping off-screen statuses no longer trigger refetch storms. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(issues): deferred view-refresh indicator during placeholder revalidation Sort/date changes (and any grouped-board filter change) revalidate behind the previous snapshot — correct, but on a slow network the click felt dead: content stays put and isLoading never fires. Surface the state as isRefreshing (isPlaceholderData of the active query) and render a shared ViewRefreshIndicator in every issues header: a fixed-width slot (zero layout shift) whose spinner fades in after 300ms, so sub-second responses show nothing (NN/g) while slow ones get a working signal. Bound to the revalidation STATE, not to any particular control — any current or future server-side view change lights it automatically. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: multica-agent <github@multica.ai> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
217 lines
7.1 KiB
TypeScript
217 lines
7.1 KiB
TypeScript
"use client";
|
|
|
|
import { memo, useMemo, type ReactNode } from "react";
|
|
import { EyeOff, MoreHorizontal, Plus, UserMinus } from "lucide-react";
|
|
import { Tooltip, TooltipTrigger, TooltipContent } from "@multica/ui/components/ui/tooltip";
|
|
import { useDroppable } from "@dnd-kit/core";
|
|
import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
import type {
|
|
Issue,
|
|
IssueAssigneeType,
|
|
IssueStatus,
|
|
Project,
|
|
} from "@multica/core/types";
|
|
import { Button } from "@multica/ui/components/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuTrigger,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
} from "@multica/ui/components/ui/dropdown-menu";
|
|
import { STATUS_CONFIG } from "@multica/core/issues/config";
|
|
import { useViewStoreApi } from "@multica/core/issues/stores/view-store-context";
|
|
import { StatusHeading } from "./status-heading";
|
|
import { DraggableBoardCard } from "./board-card";
|
|
import type { ChildProgress } from "./list-row";
|
|
import { useT } from "../../i18n";
|
|
import { ActorAvatar } from "../../common/actor-avatar";
|
|
import type { IssueCreateDefaults } from "../surface/types";
|
|
|
|
// Insertion-position prediction intentionally omitted. The server's
|
|
// ORDER BY uses PostgreSQL's en_US.utf8 collation (glibc), which
|
|
// cannot be faithfully replicated in JavaScript (ICU/V8). Showing an
|
|
// inaccurate indicator is worse than showing none.
|
|
|
|
export const BOARD_COL_WIDTH = 280;
|
|
export const BOARD_CARD_WIDTH = BOARD_COL_WIDTH - 16 - 8; // col(280) - col p-2(16) - droppable p-1(8)
|
|
|
|
export interface BoardColumnGroup {
|
|
id: string;
|
|
title: string;
|
|
status?: IssueStatus;
|
|
assigneeType?: IssueAssigneeType | null;
|
|
assigneeId?: string | null;
|
|
totalCount?: number;
|
|
createData?: IssueCreateDefaults;
|
|
}
|
|
|
|
export const BoardColumn = memo(function BoardColumn({
|
|
group,
|
|
issueIds,
|
|
issueMap,
|
|
childProgressMap,
|
|
projectMap,
|
|
totalCount,
|
|
footer,
|
|
projectId,
|
|
onCreateIssue,
|
|
sortLabel,
|
|
}: {
|
|
group: BoardColumnGroup;
|
|
issueIds: string[];
|
|
issueMap: Map<string, Issue>;
|
|
childProgressMap?: Map<string, ChildProgress>;
|
|
projectMap?: Map<string, Project>;
|
|
totalCount?: number;
|
|
footer?: ReactNode;
|
|
/** When set, the per-column "+" pre-fills the project on the create form. */
|
|
projectId?: string;
|
|
onCreateIssue?: (defaults: IssueCreateDefaults) => void;
|
|
sortLabel?: string | null;
|
|
}) {
|
|
const status = group.status;
|
|
const cfg = status ? STATUS_CONFIG[status] : null;
|
|
const { setNodeRef, isOver } = useDroppable({ id: group.id });
|
|
const viewStoreApi = useViewStoreApi();
|
|
const { t } = useT("issues");
|
|
|
|
// Resolve IDs to Issue objects, preserving parent-provided order
|
|
const resolvedIssues = useMemo(
|
|
() =>
|
|
issueIds.flatMap((id) => {
|
|
const issue = issueMap.get(id);
|
|
return issue ? [issue] : [];
|
|
}),
|
|
[issueIds, issueMap],
|
|
);
|
|
|
|
return (
|
|
<div style={{ width: BOARD_COL_WIDTH }} className={`flex shrink-0 flex-col rounded-xl ${cfg?.columnBg ?? "bg-muted/40"} p-2`}>
|
|
<div className="mb-2 flex items-center justify-between px-1.5">
|
|
<BoardGroupHeading group={group} count={totalCount ?? issueIds.length} />
|
|
|
|
{/* Right: add + menu */}
|
|
<div className="flex items-center gap-1">
|
|
{status && (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger
|
|
render={
|
|
<Button variant="ghost" size="icon-sm" className="rounded-full text-muted-foreground">
|
|
<MoreHorizontal className="size-3.5" />
|
|
</Button>
|
|
}
|
|
/>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onClick={() => viewStoreApi.getState().hideStatus(status)}>
|
|
<EyeOff className="size-3.5" />
|
|
{t(($) => $.board.hide_column)}
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)}
|
|
{onCreateIssue && (
|
|
<Tooltip>
|
|
<TooltipTrigger
|
|
render={
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="rounded-full text-muted-foreground"
|
|
onClick={() => {
|
|
const data = {
|
|
...(group.createData ?? {}),
|
|
...(projectId ? { project_id: projectId } : {}),
|
|
};
|
|
onCreateIssue(data);
|
|
}}
|
|
>
|
|
<Plus className="size-3.5" />
|
|
</Button>
|
|
}
|
|
/>
|
|
<TooltipContent>{t(($) => $.board.add_issue_tooltip)}</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="relative min-h-[200px] flex-1 rounded-lg">
|
|
{isOver && sortLabel && (
|
|
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-lg bg-background/40">
|
|
<span className="rounded-md bg-popover px-2.5 py-1 text-xs font-medium text-popover-foreground shadow-sm border border-border">
|
|
{sortLabel}
|
|
</span>
|
|
</div>
|
|
)}
|
|
<div
|
|
ref={setNodeRef}
|
|
className={`absolute inset-0 space-y-2 overflow-y-auto rounded-lg p-1 transition-colors ${
|
|
isOver && sortLabel
|
|
? "ring-2 ring-brand/25 bg-accent/15"
|
|
: isOver
|
|
? "bg-accent/60"
|
|
: ""
|
|
}`}
|
|
>
|
|
<SortableContext items={issueIds} strategy={verticalListSortingStrategy}>
|
|
{resolvedIssues.map((issue) => (
|
|
<DraggableBoardCard
|
|
key={issue.id}
|
|
issue={issue}
|
|
childProgress={childProgressMap?.get(issue.id)}
|
|
project={
|
|
issue.project_id ? projectMap?.get(issue.project_id) : undefined
|
|
}
|
|
disableSorting={!!sortLabel}
|
|
/>
|
|
))}
|
|
</SortableContext>
|
|
{issueIds.length === 0 && (
|
|
<p className="py-8 text-center text-xs text-muted-foreground">
|
|
{t(($) => $.board.empty_column)}
|
|
</p>
|
|
)}
|
|
{footer}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
});
|
|
|
|
function BoardGroupHeading({
|
|
group,
|
|
count,
|
|
}: {
|
|
group: BoardColumnGroup;
|
|
count: number;
|
|
}) {
|
|
if (group.status) {
|
|
return <StatusHeading status={group.status} count={count} />;
|
|
}
|
|
|
|
const actorIcon =
|
|
group.assigneeType && group.assigneeId ? (
|
|
<ActorAvatar
|
|
actorType={group.assigneeType}
|
|
actorId={group.assigneeId}
|
|
size={18}
|
|
showStatusDot={group.assigneeType === "agent"}
|
|
/>
|
|
) : (
|
|
<span className="flex size-[18px] shrink-0 items-center justify-center rounded-full bg-background text-muted-foreground">
|
|
<UserMinus className="size-3.5" />
|
|
</span>
|
|
);
|
|
|
|
return (
|
|
<div className="flex min-w-0 items-center gap-2">
|
|
{actorIcon}
|
|
<span className="truncate text-sm font-medium" title={group.title}>
|
|
{group.title}
|
|
</span>
|
|
<span className="shrink-0 rounded-full bg-background px-1.5 py-0.5 text-[11px] font-medium tabular-nums text-muted-foreground">
|
|
{count}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|