Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(web): a completed blocker no longer tints the card (#771)

Pasqual Troncone217a36d6c79b
diff --git a/apps/web/src/features/work-items/WorkItemsPage.tsx b/apps/web/src/features/work-items/WorkItemsPage.tsx
index 3a9ebb80..a5fc8bda 100644
--- a/apps/web/src/features/work-items/WorkItemsPage.tsx
+++ b/apps/web/src/features/work-items/WorkItemsPage.tsx
@@ -247,7 +247,11 @@ export default function WorkItemsPage() {
)}
<div className="relative flex-1 overflow-hidden">
- <IssueLinksProvider issues={project.issues} enabled={settings.showLinks}>
+ <IssueLinksProvider
+ issues={project.issues}
+ columns={project.columns}
+ enabled={settings.showLinks}
+ >
<SubtasksProvider
issues={project.issues}
enabled={settings.showSubtasks}
diff --git a/apps/web/src/features/work-items/components/BoardLayout.tsx b/apps/web/src/features/work-items/components/BoardLayout.tsx
index 44872e6b..66428516 100644
--- a/apps/web/src/features/work-items/components/BoardLayout.tsx
+++ b/apps/web/src/features/work-items/components/BoardLayout.tsx
@@ -53,7 +53,7 @@ export default function BoardLayout({
}
return (
- <IssueLinksProvider issues={allIssues} enabled={settings.showLinks}>
+ <IssueLinksProvider issues={allIssues} columns={project.columns} enabled={settings.showLinks}>
<SubtasksProvider
issues={allIssues}
enabled={subtasksEnabled && settings.showSubtasks}
diff --git a/apps/web/src/features/work-items/components/kanban/BoardCard.tsx b/apps/web/src/features/work-items/components/kanban/BoardCard.tsx
index b564b9b9..b2d135eb 100644
--- a/apps/web/src/features/work-items/components/kanban/BoardCard.tsx
+++ b/apps/web/src/features/work-items/components/kanban/BoardCard.tsx
@@ -6,10 +6,10 @@ import type { BoardIssue } from '@/lib/api/endpoints/issues';
import { type Maps } from '@/utils/project';
import { useIsPhone } from '@/hooks/useIsPhone';
import { usePermissions } from '@/hooks/usePermissions';
-import { isBlocked } from '@/utils/issueLinks';
import { cn } from '@/lib/utils';
import type { PropertyKey } from '@/utils/viewSettings';
import IssueContextMenu from '@/features/issue/components/actions/IssueContextMenu';
+import { useIsBlocked } from '../../context/useIssueLinks';
import { useSelection } from '../../context/useSelection';
import { draggedIds } from '../../utils/kanban';
import { IssueCardBody } from './IssueCardBody';
@@ -40,6 +40,7 @@ export function BoardCard({
const { can } = usePermissions();
const selection = useSelection();
const selected = selection.isSelected(issue.id);
+ const blocked = useIsBlocked(issue);
const { setNodeRef, attributes, listeners } = useDraggable({
id: issue.id,
data: { issueIds: selected ? [...selection.selected] : [issue.id] },
@@ -94,7 +95,7 @@ export function BoardCard({
// also starting a native text selection across cards.
'kanban-card cursor-grab rounded-md p-2 select-none',
isDragging && 'opacity-40',
- isBlocked(issue) && 'kanban-card-blocked',
+ blocked && 'kanban-card-blocked',
// Selected cards read as a primary-tinted fill, like Linear — no border,
// no checkbox (see .kanban-card-selected in globals.css).
selected && 'kanban-card-selected',
diff --git a/apps/web/src/features/work-items/components/table/TableRow.tsx b/apps/web/src/features/work-items/components/table/TableRow.tsx
index 88b3d2eb..fee320b0 100644
--- a/apps/web/src/features/work-items/components/table/TableRow.tsx
+++ b/apps/web/src/features/work-items/components/table/TableRow.tsx
@@ -6,7 +6,6 @@ import { type Maps } from '@/utils/project';
import { useSetFieldValue, useUpdateIssue } from '@/services/issues.service';
import { useIsPhone } from '@/hooks/useIsPhone';
import { usePermissions } from '@/hooks/usePermissions';
-import { isBlocked } from '@/utils/issueLinks';
import { cn } from '@/lib/utils';
import IssueContextMenu from '@/features/issue/components/actions/IssueContextMenu';
import { DropLine } from '../shared/DropLine';
@@ -14,6 +13,7 @@ import { EditableBuiltinCell } from '../shared/EditableBuiltinCell';
import { EditableCustomCell } from '../shared/EditableCustomCell';
import { IssueIdentifier } from '../shared/IssueIdentifier';
import { SubtaskProgress } from '../shared/SubtaskProgress';
+import { useIsBlocked } from '../../context/useIssueLinks';
import { useSubtaskFold } from '../../context/useSubtasks';
import { columnKey, type OrderedColumn } from '../../utils/table';
import { TableBuiltinCell } from './TableBuiltinCell';
@@ -63,6 +63,7 @@ export function TableRow({
// issue edit).
const { can } = usePermissions();
const subtasks = useSubtaskFold();
+ const blocked = useIsBlocked(issue);
const updateIssue = useUpdateIssue(project.project.ref);
const setFieldValue = useSetFieldValue(project.project.ref);
const patch = (fields: IssuePatch) => updateIssue.mutate({ id: issue.id, patch: fields });
@@ -100,7 +101,7 @@ export function TableRow({
}}
className={cn(
'relative grid cursor-grab gap-3 border-b py-2 pr-4 text-sm transition-colors',
- isBlocked(issue) ? 'row-blocked' : 'hover:bg-accent/40',
+ blocked ? 'row-blocked' : 'hover:bg-accent/40',
alignTop ? 'items-start' : 'items-center',
indented ? 'pl-9' : 'pl-4',
isDragging && 'opacity-40',
diff --git a/apps/web/src/features/work-items/components/timeline/TimelineBar.tsx b/apps/web/src/features/work-items/components/timeline/TimelineBar.tsx
index ef9cc68d..5096d725 100644
--- a/apps/web/src/features/work-items/components/timeline/TimelineBar.tsx
+++ b/apps/web/src/features/work-items/components/timeline/TimelineBar.tsx
@@ -1,8 +1,8 @@
import { useTranslations } from 'next-intl';
import type { BoardIssue, Issue } from '@/lib/api/endpoints/issues';
-import { isBlocked } from '@/utils/issueLinks';
import { cn } from '@/lib/utils';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
+import { useIsBlocked } from '../../context/useIssueLinks';
import { type TimelineDragMode } from '../../hooks/useTimelineDrag';
import { type Span } from '../../utils/timeline';
@@ -35,7 +35,7 @@ export function TimelineBar({
onOpen: (id: number) => void;
}) {
const t = useTranslations('workItems.timeline');
- const blocked = isBlocked(issue);
+ const blocked = useIsBlocked(issue);
let cursor = 'cursor-ew-resize';
if (readOnly) cursor = 'cursor-pointer';
else if (active) cursor = 'cursor-grabbing';
diff --git a/apps/web/src/features/work-items/context/useIssueLinks.test.tsx b/apps/web/src/features/work-items/context/useIssueLinks.test.tsx
new file mode 100644
index 00000000..233302f8
--- /dev/null
+++ b/apps/web/src/features/work-items/context/useIssueLinks.test.tsx
@@ -0,0 +1,30 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { renderToStaticMarkup } from 'react-dom/server';
+import type { Column } from '@/lib/api/endpoints/columns';
+import type { BoardIssue } from '@/lib/api/endpoints/issues';
+import { IssueLinksProvider, useIsBlocked, useIssueLinks } from './useIssueLinks';
+
+const started = { id: 1, stateType: 'started' } as Column;
+const blocker = { id: 2, columnId: started.id, links: [] } as unknown as BoardIssue;
+const card = {
+ id: 1,
+ columnId: started.id,
+ links: [{ id: 9, relation: 'blocked_by', issueId: blocker.id }],
+} as unknown as BoardIssue;
+
+function Probe() {
+ const links = useIssueLinks(card.links);
+ return `${useIsBlocked(card) ? 'blocked' : 'free'} ${links.length}`;
+}
+
+describe('IssueLinksProvider', () => {
+ it('keeps the blocked tint with the Links display property off, and hides the relations', () => {
+ const html = renderToStaticMarkup(
+ <IssueLinksProvider issues={[card, blocker]} columns={[started]} enabled={false}>
+ <Probe />
+ </IssueLinksProvider>,
+ );
+ assert.equal(html, 'blocked 0');
+ });
+});
diff --git a/apps/web/src/features/work-items/context/useIssueLinks.tsx b/apps/web/src/features/work-items/context/useIssueLinks.tsx
index 49149b6b..562374df 100644
--- a/apps/web/src/features/work-items/context/useIssueLinks.tsx
+++ b/apps/web/src/features/work-items/context/useIssueLinks.tsx
@@ -1,8 +1,14 @@
'use client';
import { createContext, useContext, useMemo, type ReactNode } from 'react';
-import type { Issue, IssueLinkInputKind, IssueLinkRef } from '@/lib/api/endpoints/issues';
-import { LINK_RELATIONS } from '@/utils/issueLinks';
+import type { Column } from '@/lib/api/endpoints/columns';
+import type {
+ BoardIssue,
+ Issue,
+ IssueLinkInputKind,
+ IssueLinkRef,
+} from '@/lib/api/endpoints/issues';
+import { isBlocked, LINK_RELATIONS } from '@/utils/issueLinks';
// One relation as a card or a table row shows it: how it reads from the issue it
// is shown on, and the issue on the other end.
@@ -12,29 +18,45 @@ export interface IssueLinkView {
issue: Issue;
}
-const IssueLookupContext = createContext<Map<number, Issue>>(new Map());
+interface IssueLookup {
+ byId: Map<number, Issue>;
+ columnById: Map<number, Column>;
+ showLinks: boolean;
+}
+
+const IssueLookupContext = createContext<IssueLookup>({
+ byId: new Map(),
+ columnById: new Map(),
+ showLinks: false,
+});
const RELATION_ORDER = new Map(LINK_RELATIONS.map((relation, index) => [relation, index]));
// Holds the project's issues for the cards and rows below to resolve the other
// end of a relation against. `issues` are the project's issues before the filter
-// bar narrows them, so a relation to a filtered-out issue still reads. Empty
-// while the Links display property is off, which is what turns the relations off
-// everywhere at once.
+// bar narrows them, so a relation to a filtered-out issue still reads. The Links
+// display property turns the relations off everywhere at once, but the blocked
+// tint still reads the blockers here.
export function IssueLinksProvider({
issues,
+ columns,
enabled,
children,
}: {
issues: Issue[];
+ columns: Column[];
enabled: boolean;
children: ReactNode;
}) {
- const byId = useMemo(
- () => (enabled ? new Map(issues.map((issue) => [issue.id, issue])) : new Map<number, Issue>()),
- [enabled, issues],
+ const lookup = useMemo(
+ () => ({
+ byId: new Map(issues.map((issue) => [issue.id, issue])),
+ columnById: new Map(columns.map((column) => [column.id, column])),
+ showLinks: enabled,
+ }),
+ [issues, columns, enabled],
);
- return <IssueLookupContext.Provider value={byId}>{children}</IssueLookupContext.Provider>;
+ return <IssueLookupContext.Provider value={lookup}>{children}</IssueLookupContext.Provider>;
}
const NONE: IssueLinkView[] = [];
@@ -42,9 +64,9 @@ const NONE: IssueLinkView[] = [];
// An issue's relations with the issue on the other end of each resolved, ordered
// by relation and then by that issue's number.
export function useIssueLinks(links: IssueLinkRef[] | undefined): IssueLinkView[] {
- const byId = useContext(IssueLookupContext);
+ const { byId, showLinks } = useContext(IssueLookupContext);
return useMemo(() => {
- if (!links?.length || byId.size === 0) return NONE;
+ if (!showLinks || !links?.length) return NONE;
const views = links.flatMap((link) => {
const issue = byId.get(link.issueId);
return issue ? [{ id: link.id, relation: link.relation, issue }] : [];
@@ -55,5 +77,11 @@ export function useIssueLinks(links: IssueLinkRef[] | undefined): IssueLinkView[
a.issue.sequenceNumber - b.issue.sequenceNumber,
);
return views;
- }, [links, byId]);
+ }, [links, byId, showLinks]);
+}
+
+// Whether an issue still open holds this one up (see isBlocked).
+export function useIsBlocked(issue: BoardIssue): boolean {
+ const { byId, columnById } = useContext(IssueLookupContext);
+ return isBlocked(issue, byId, columnById);
}
diff --git a/apps/web/src/utils/issueLinks.test.ts b/apps/web/src/utils/issueLinks.test.ts
new file mode 100644
index 00000000..57e79757
--- /dev/null
+++ b/apps/web/src/utils/issueLinks.test.ts
@@ -0,0 +1,45 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import type { Column, StateType } from '@/lib/api/endpoints/columns';
+import type { BoardIssue, Issue, IssueLinkRef } from '@/lib/api/endpoints/issues';
+import { isBlocked } from './issueLinks';
+
+const columns = (['started', 'completed', 'canceled'] as StateType[]).map(
+ (stateType, i) => ({ id: i + 1, stateType }) as Column,
+);
+const columnById = new Map(columns.map((column) => [column.id, column]));
+const [started, completed, canceled] = columns;
+
+const issue = (id: number, columnId: number, links: IssueLinkRef[] = []) =>
+ ({ id, columnId, links }) as unknown as BoardIssue;
+
+function blockedBy(blockerColumn: Column | null) {
+ const blocker = issue(2, blockerColumn?.id ?? 0);
+ const issueById = new Map<number, Issue>(blockerColumn ? [[2, blocker]] : []);
+ const card = issue(1, started.id, [{ id: 9, relation: 'blocked_by', issueId: 2 }]);
+ return isBlocked(card, issueById, columnById);
+}
+
+describe('isBlocked', () => {
+ it('holds while the blocker is open', () => {
+ assert.equal(blockedBy(started), true);
+ });
+
+ it('lets go once the blocker is completed or canceled', () => {
+ assert.equal(blockedBy(completed), false);
+ assert.equal(blockedBy(canceled), false);
+ });
+
+ it('holds for a blocker the board cannot find, since the relation stands', () => {
+ assert.equal(blockedBy(null), true);
+ });
+
+ it('ignores the relations that do not block the issue', () => {
+ const other = issue(2, started.id);
+ const card = issue(1, started.id, [
+ { id: 9, relation: 'blocks', issueId: 2 },
+ { id: 10, relation: 'relates', issueId: 2 },
+ ]);
+ assert.equal(isBlocked(card, new Map([[2, other]]), columnById), false);
+ });
+});
diff --git a/apps/web/src/utils/issueLinks.ts b/apps/web/src/utils/issueLinks.ts
index ce810b0a..ed4725d1 100644
--- a/apps/web/src/utils/issueLinks.ts
+++ b/apps/web/src/utils/issueLinks.ts
@@ -1,6 +1,8 @@
import { Ban, CircleSlash, Copy, Link2, type LucideIcon } from 'lucide-react';
+import type { Column } from '@/lib/api/endpoints/columns';
import type {
BoardIssue,
+ Issue,
IssueLink,
IssueLinkInputKind,
IssueLinkKind,
@@ -55,10 +57,19 @@ export function linkRelation(link: IssueLink): IssueLinkInputKind {
}
// Whether another issue holds this one up, which the board views tint the card
-// or row for. Read off the issue's own relations, so it holds whether or not the
-// Links display property is showing them.
-export function isBlocked(issue: BoardIssue): boolean {
- return issue.links.some((link) => link.relation === 'blocked_by');
+// or row for. A blocker in a completed or canceled column no longer does; one the
+// board cannot find still counts, since the relation stands.
+export function isBlocked(
+ issue: BoardIssue,
+ issueById: Map<number, Issue>,
+ columnById: Map<number, Column>,
+): boolean {
+ return issue.links.some((link) => {
+ if (link.relation !== 'blocked_by') return false;
+ const blocker = issueById.get(link.issueId);
+ const stateType = blocker && columnById.get(blocker.columnId)?.stateType;
+ return stateType !== 'completed' && stateType !== 'canceled';
+ });
}
// The same relation read from the other end, for naming it on the issue on that