Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-6136 feat(issues): distinguish self-references to the current issue in inline mentions (#6939)

Bowser3d6dfffc1e41
diff --git a/packages/views/editor/content-editor-current-issue.test.tsx b/packages/views/editor/content-editor-current-issue.test.tsx
new file mode 100644
index 0000000000..3a85a68ae4
--- /dev/null
+++ b/packages/views/editor/content-editor-current-issue.test.tsx
@@ -0,0 +1,101 @@
+import { describe, expect, it, vi } from "vitest";
+import { screen, waitFor } from "@testing-library/react";
+import type { ReactNode } from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { renderWithI18n } from "../test/i18n";
+import { NavigationProvider } from "../navigation/context";
+import type { NavigationAdapter } from "../navigation/types";
+import { CurrentIssueRenderContextProvider } from "../issues/current-issue-render-context";
+
+vi.mock("../issues/components/issue-chip", () => ({
+ IssueChip: ({
+ issueId,
+ children,
+ }: {
+ issueId: string;
+ children?: ReactNode;
+ }) => (
+ <span
+ data-testid="issue-chip"
+ data-issue-id={issueId}
+ data-current={children !== undefined ? "true" : "false"}
+ >
+ {children}
+ </span>
+ ),
+}));
+
+vi.mock("../issues/components/issue-hover-card", () => ({
+ IssueHoverCard: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}));
+
+vi.mock("./link-hover-card", () => ({
+ useLinkHover: () => ({}),
+ LinkHoverCard: () => null,
+}));
+
+vi.mock("@multica/core/paths", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/paths")>()),
+ useWorkspacePaths: () => ({
+ issueDetail: (id: string) => `/acme/issues/${id}`,
+ projectDetail: (id: string) => `/acme/projects/${id}`,
+ }),
+ useWorkspaceSlug: () => "acme",
+}));
+
+import { ContentEditor } from "./content-editor";
+
+const CURRENT_ID = "11111111-1111-4111-8111-111111111111";
+const OTHER_ID = "22222222-2222-4222-8222-222222222222";
+const CONTENT = [
+ `[MUL-7](mention://issue/${CURRENT_ID})`,
+ `[MUL-8](mention://issue/${OTHER_ID})`,
+].join(" and ");
+
+function adapter(): NavigationAdapter {
+ return {
+ push: vi.fn(),
+ replace: vi.fn(),
+ back: vi.fn(),
+ pathname: "/",
+ searchParams: new URLSearchParams(),
+ getShareableUrl: (path) => `https://app.example${path}`,
+ };
+}
+
+function renderEditor() {
+ const queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false, gcTime: 0 } },
+ });
+ return renderWithI18n(
+ <NavigationProvider value={adapter()}>
+ <QueryClientProvider client={queryClient}>
+ <CurrentIssueRenderContextProvider
+ value={{ id: CURRENT_ID, identifier: "MUL-7" }}
+ >
+ <ContentEditor
+ defaultValue={CONTENT}
+ showBubbleMenu={false}
+ />
+ </CurrentIssueRenderContextProvider>
+ </QueryClientProvider>
+ </NavigationProvider>,
+ );
+}
+
+describe("ContentEditor current-issue context", () => {
+ it("passes the provider through the Tiptap NodeView portal to only the current mention", async () => {
+ renderEditor();
+
+ await waitFor(() => {
+ expect(screen.getAllByTestId("issue-chip")).toHaveLength(2);
+ });
+
+ const chips = screen.getAllByTestId("issue-chip");
+ expect(chips.map((chip) => chip.getAttribute("data-current"))).toEqual([
+ "true",
+ "false",
+ ]);
+ expect(chips[0]).toHaveTextContent("This issue · MUL-7");
+ });
+});
diff --git a/packages/views/issues/components/issue-chip.tsx b/packages/views/issues/components/issue-chip.tsx
index 5907581514..90c1c6af89 100644
--- a/packages/views/issues/components/issue-chip.tsx
+++ b/packages/views/issues/components/issue-chip.tsx
@@ -1,5 +1,6 @@
"use client";
+import type { ReactNode } from "react";
import { useQuery } from "@tanstack/react-query";
import { issueListOptions, issueDetailOptions } from "@multica/core/issues/queries";
import { useWorkspaceId } from "@multica/core/hooks";
@@ -38,6 +39,8 @@ export interface IssueChipProps {
issueId: string;
/** Shown when the issue can't be resolved (deleted, other workspace, …). */
fallbackLabel?: string;
+ /** Optional content override for callers that need the shared chip shell. */
+ children?: ReactNode;
/** Extra classes — callers layer interaction hints here
* (e.g. `hover:bg-accent cursor-pointer` for navigable variants). */
className?: string;
@@ -46,7 +49,12 @@ export interface IssueChipProps {
const BASE_CLASS =
"issue-mention inline-flex min-w-0 max-w-[min(18rem,100%)] items-center gap-1.5 rounded-md border mx-0.5 px-2 py-0.5 text-caption";
-export function IssueChip({ issueId, fallbackLabel, className }: IssueChipProps) {
+export function IssueChip({
+ issueId,
+ fallbackLabel,
+ children,
+ className,
+}: IssueChipProps) {
const wsId = useWorkspaceId();
const { data: issues = [] } = useQuery(issueListOptions(wsId));
const listIssue = issues.find((i) => i.id === issueId);
@@ -60,6 +68,10 @@ export function IssueChip({ issueId, fallbackLabel, className }: IssueChipProps)
const issue = listIssue ?? detailIssue;
const cls = className ? `${BASE_CLASS} ${className}` : BASE_CLASS;
+ if (children !== undefined) {
+ return <span className={cls}>{children}</span>;
+ }
+
if (!issue) {
return (
<span className={cls}>
diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsx
index f649a18ce8..2b90095c6d 100644
--- a/packages/views/issues/components/issue-detail.tsx
+++ b/packages/views/issues/components/issue-detail.tsx
@@ -70,6 +70,7 @@ import { ProjectPicker } from "../../projects/components/project-picker";
import { LocalDirectoryHint } from "../../projects/components/local-directory-hint";
import { CommentCard } from "./comment-card";
import { CommentInput } from "./comment-input";
+import { CurrentIssueRenderContextProvider } from "../current-issue-render-context";
import { ResolvedThreadBar } from "./resolved-thread-bar";
import { getShortcut, shortcutMatchesEvent } from "@multica/core/shortcuts";
import { isImeComposing } from "@multica/core/utils";
@@ -2058,6 +2059,18 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
overrideTop: restoredScrollTop,
});
+ // Keep the identity value stable across unrelated issue-detail updates so
+ // context consumers only re-render when the owning issue changes identity.
+ const resolvedIssueId = issue?.id;
+ const resolvedIssueIdentifier = issue?.identifier;
+ const currentIssueRenderContext = useMemo(
+ () =>
+ resolvedIssueId && resolvedIssueIdentifier
+ ? { id: resolvedIssueId, identifier: resolvedIssueIdentifier }
+ : null,
+ [resolvedIssueId, resolvedIssueIdentifier],
+ );
+
if (loading) {
return <IssueDetailSkeleton leading={leadingAction} />;
}
@@ -2483,6 +2496,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
// Hosts the one image viewer this issue's images page through — see
// ImageSequenceProvider. Wraps the whole column so the description
// editor's images and the timeline's images share one sequence.
+ <CurrentIssueRenderContextProvider value={currentIssueRenderContext}>
<ImageSequenceProvider items={imageSequence}>
<div className="relative flex h-full min-w-0 flex-1 flex-col">
{/* In-page find bar — floats over the top-right of the content column
@@ -3125,6 +3139,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tr
)}
</div>
</ImageSequenceProvider>
+ </CurrentIssueRenderContextProvider>
);
if (isMobile) {
diff --git a/packages/views/issues/components/issue-mention-card.test.tsx b/packages/views/issues/components/issue-mention-card.test.tsx
index efa06d740d..01a35dad24 100644
--- a/packages/views/issues/components/issue-mention-card.test.tsx
+++ b/packages/views/issues/components/issue-mention-card.test.tsx
@@ -1,8 +1,14 @@
import { describe, expect, it, vi } from "vitest";
-import { fireEvent, render, screen } from "@testing-library/react";
+import { fireEvent, screen } from "@testing-library/react";
+import type { ReactNode } from "react";
+import { renderWithI18n } from "../../test/i18n";
import { IssueMentionCard } from "./issue-mention-card";
import { NavigationProvider } from "../../navigation";
import type { NavigationAdapter } from "../../navigation";
+import {
+ CurrentIssueRenderContextProvider,
+ type CurrentIssueRenderContextValue,
+} from "../current-issue-render-context";
vi.mock("@multica/core/paths", () => ({
useWorkspacePaths: () => ({
@@ -11,8 +17,19 @@ vi.mock("@multica/core/paths", () => ({
}));
vi.mock("./issue-chip", () => ({
- IssueChip: ({ fallbackLabel }: { fallbackLabel?: string }) => (
- <span data-testid="issue-chip">{fallbackLabel ?? "chip"}</span>
+ IssueChip: ({
+ fallbackLabel,
+ children,
+ }: {
+ fallbackLabel?: string;
+ children?: ReactNode;
+ }) => (
+ <span
+ data-testid="issue-chip"
+ data-current={children !== undefined ? "true" : "false"}
+ >
+ {children ?? fallbackLabel ?? "chip"}
+ </span>
),
}));
@@ -30,10 +47,23 @@ function makeAdapter(
};
}
-function renderCard(adapter: NavigationAdapter) {
- return render(
+function renderCard(
+ adapter: NavigationAdapter,
+ context?: CurrentIssueRenderContextValue,
+ issueId = "issue-1",
+) {
+ const card = (
+ <IssueMentionCard issueId={issueId} fallbackLabel="MUL-7" />
+ );
+ return renderWithI18n(
<NavigationProvider value={adapter}>
- <IssueMentionCard issueId="issue-1" fallbackLabel="MUL-7" />
+ {context ? (
+ <CurrentIssueRenderContextProvider value={context}>
+ {card}
+ </CurrentIssueRenderContextProvider>
+ ) : (
+ card
+ )}
</NavigationProvider>,
);
}
@@ -108,4 +138,17 @@ describe("IssueMentionCard", () => {
expect(defaultNotPrevented).toBe(true);
expect(push).not.toHaveBeenCalled();
});
+
+ it("uses current-issue content when the resolved target matches the current issue id", () => {
+ renderCard(makeAdapter(), { id: "issue-1", identifier: "MUL-7" });
+
+ expect(screen.getByTestId("issue-chip")).toHaveAttribute("data-current", "true");
+ expect(screen.getByTestId("issue-chip")).toHaveTextContent("This issue · MUL-7");
+ });
+
+ it("does not infer current-issue context from the visible fallback label", () => {
+ renderCard(makeAdapter(), { id: "issue-2", identifier: "MUL-7" });
+
+ expect(screen.getByTestId("issue-chip")).toHaveAttribute("data-current", "false");
+ });
});
diff --git a/packages/views/issues/components/issue-mention-card.tsx b/packages/views/issues/components/issue-mention-card.tsx
index 36bf1fcbef..d6be8b6bbe 100644
--- a/packages/views/issues/components/issue-mention-card.tsx
+++ b/packages/views/issues/components/issue-mention-card.tsx
@@ -4,6 +4,8 @@ import { AppLink } from "../../navigation";
import { useWorkspacePaths } from "@multica/core/paths";
import { IssueChip } from "./issue-chip";
import { IssueHoverCard } from "./issue-hover-card";
+import { useT } from "../../i18n";
+import { useCurrentIssueRenderContext } from "../current-issue-render-context";
interface IssueMentionCardProps {
issueId: string;
@@ -11,6 +13,18 @@ interface IssueMentionCardProps {
fallbackLabel?: string;
}
+function CurrentIssueChipContent({ identifier }: { identifier: string }) {
+ const { t } = useT("issues");
+
+ return (
+ <span className="font-medium text-muted-foreground shrink-0">
+ <span>{t(($) => $.detail.current_issue)}</span>{" "}
+ <span className="text-muted-foreground">·</span>{" "}
+ <span translate="no">{identifier}</span>
+ </span>
+ );
+}
+
/**
* Navigable chip — wraps IssueChip in an AppLink pointing at the issue's
* detail page. Hover/cursor affordance is layered onto the chip itself so
@@ -27,6 +41,11 @@ interface IssueMentionCardProps {
*/
export function IssueMentionCard({ issueId, fallbackLabel }: IssueMentionCardProps) {
const p = useWorkspacePaths();
+ const currentIssue = useCurrentIssueRenderContext();
+ const currentIdentifier =
+ currentIssue && issueId === currentIssue.id
+ ? currentIssue.identifier
+ : null;
return (
<IssueHoverCard issueId={issueId} fallbackLabel={fallbackLabel}>
<AppLink
@@ -38,7 +57,11 @@ export function IssueMentionCard({ issueId, fallbackLabel }: IssueMentionCardPro
issueId={issueId}
fallbackLabel={fallbackLabel}
className="cursor-pointer hover:bg-accent transition-colors"
- />
+ >
+ {currentIdentifier ? (
+ <CurrentIssueChipContent identifier={currentIdentifier} />
+ ) : undefined}
+ </IssueChip>
</AppLink>
</IssueHoverCard>
);
diff --git a/packages/views/issues/current-issue-render-context.tsx b/packages/views/issues/current-issue-render-context.tsx
new file mode 100644
index 0000000000..b3ec6ce8fe
--- /dev/null
+++ b/packages/views/issues/current-issue-render-context.tsx
@@ -0,0 +1,40 @@
+"use client";
+
+import {
+ createContext,
+ useContext,
+ type ReactNode,
+} from "react";
+
+export type CurrentIssueRenderContextValue = Readonly<{
+ id: string;
+ identifier: string;
+}>;
+
+/**
+ * The issue identity that owns the content currently being rendered.
+ *
+ * It intentionally defaults to null: content renderers are shared by issue
+ * detail, inbox, chat, and other surfaces, and only an explicit issue-detail
+ * owner may opt into current-issue semantics.
+ */
+const CurrentIssueRenderContext =
+ createContext<CurrentIssueRenderContextValue | null>(null);
+
+export function CurrentIssueRenderContextProvider({
+ value,
+ children,
+}: {
+ value: CurrentIssueRenderContextValue | null;
+ children: ReactNode;
+}) {
+ return (
+ <CurrentIssueRenderContext.Provider value={value}>
+ {children}
+ </CurrentIssueRenderContext.Provider>
+ );
+}
+
+export function useCurrentIssueRenderContext(): CurrentIssueRenderContextValue | null {
+ return useContext(CurrentIssueRenderContext);
+}
diff --git a/packages/views/locales/en/issues.json b/packages/views/locales/en/issues.json
index 32c074e870..cffd66c38c 100644
--- a/packages/views/locales/en/issues.json
+++ b/packages/views/locales/en/issues.json
@@ -244,6 +244,7 @@
"back": "Back",
"title_placeholder": "Issue title",
"desc_placeholder": "Add description...",
+ "current_issue": "This issue",
"sub_issues_label": "Sub-issues",
"sub_issue_of": "Sub-issue of",
"add_sub_issues": "Add sub-issues",
diff --git a/packages/views/locales/ja/issues.json b/packages/views/locales/ja/issues.json
index b4ec42acad..4c178487c5 100644
--- a/packages/views/locales/ja/issues.json
+++ b/packages/views/locales/ja/issues.json
@@ -242,6 +242,7 @@
"back": "戻る",
"title_placeholder": "タスクのタイトル",
"desc_placeholder": "説明を追加...",
+ "current_issue": "現在のタスク",
"sub_issues_label": "サブタスク",
"sub_issue_of": "親タスク",
"add_sub_issues": "サブタスクを追加",
diff --git a/packages/views/locales/ko/issues.json b/packages/views/locales/ko/issues.json
index 35877bd9d9..6f6276fcbd 100644
--- a/packages/views/locales/ko/issues.json
+++ b/packages/views/locales/ko/issues.json
@@ -242,6 +242,7 @@
"back": "뒤로",
"title_placeholder": "태스크 제목",
"desc_placeholder": "설명 추가...",
+ "current_issue": "현재 작업",
"sub_issues_label": "하위 태스크",
"sub_issue_of": "상위 태스크",
"add_sub_issues": "하위 태스크 추가",
diff --git a/packages/views/locales/zh-Hans/issues.json b/packages/views/locales/zh-Hans/issues.json
index 284fa735e1..5b8210299b 100644
--- a/packages/views/locales/zh-Hans/issues.json
+++ b/packages/views/locales/zh-Hans/issues.json
@@ -242,6 +242,7 @@
"back": "返回",
"title_placeholder": "任务标题",
"desc_placeholder": "添加描述...",
+ "current_issue": "当前任务",
"sub_issues_label": "子任务",
"sub_issue_of": "属于父任务",
"add_sub_issues": "添加子任务",
diff --git a/packages/views/rich-content/current-issue-rendering.test.tsx b/packages/views/rich-content/current-issue-rendering.test.tsx
new file mode 100644
index 0000000000..c05d70290c
--- /dev/null
+++ b/packages/views/rich-content/current-issue-rendering.test.tsx
@@ -0,0 +1,193 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { screen } from "@testing-library/react";
+import type { ReactNode } from "react";
+import type { Issue } from "@multica/core/types";
+import { renderWithI18n } from "../test/i18n";
+import { NavigationProvider } from "../navigation/context";
+import type { NavigationAdapter } from "../navigation/types";
+import {
+ CurrentIssueRenderContextProvider,
+ type CurrentIssueRenderContextValue,
+} from "../issues/current-issue-render-context";
+
+const resolvedIssues = vi.hoisted(() => ({
+ current: null as Issue | null,
+ other: null as Issue | null,
+}));
+
+vi.mock("../issues/hooks", () => ({
+ useResolveIssueIdentifier: (identifier: string) => {
+ if (identifier === "MUL-7") return resolvedIssues.current;
+ if (identifier === "MUL-8") return resolvedIssues.other;
+ return null;
+ },
+}));
+
+vi.mock("../issues/components/issue-chip", () => ({
+ IssueChip: ({
+ issueId,
+ children,
+ }: {
+ issueId: string;
+ children?: ReactNode;
+ }) => (
+ <span
+ data-testid="issue-chip"
+ data-issue-id={issueId}
+ data-current={children !== undefined ? "true" : "false"}
+ >
+ {children ?? issueId}
+ </span>
+ ),
+}));
+
+vi.mock("../issues/components/issue-hover-card", () => ({
+ IssueHoverCard: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}));
+
+vi.mock("../editor/link-hover-card", () => ({
+ useLinkHover: () => ({}),
+ LinkHoverCard: () => null,
+}));
+
+vi.mock("@multica/core/api", () => ({
+ api: { getAttachmentTextContent: vi.fn() },
+ PreviewTooLargeError: class extends Error {},
+ PreviewUnsupportedError: class extends Error {},
+}));
+
+vi.mock("@multica/core/paths", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@multica/core/paths")>()),
+ useWorkspacePaths: () => ({
+ issueDetail: (id: string) => `/acme/issues/${id}`,
+ projectDetail: (id: string) => `/acme/projects/${id}`,
+ }),
+ useWorkspaceSlug: () => "acme",
+}));
+
+vi.mock("mermaid", () => ({
+ default: { initialize: vi.fn(), render: vi.fn() },
+}));
+
+import { RichContent } from "./rich-content";
+
+const APP_ORIGIN = "https://app.example";
+const CURRENT_ID = "11111111-1111-4111-8111-111111111111";
+const OTHER_ID = "22222222-2222-4222-8222-222222222222";
+const CURRENT_CONTEXT: CurrentIssueRenderContextValue = {
+ id: CURRENT_ID,
+ identifier: "MUL-7",
+};
+const CONTENT = [
+ `See [MUL-7](mention://issue/${CURRENT_ID})`,
+ "MUL-8",
+ `${APP_ORIGIN}/acme/issues/${OTHER_ID}.`,
+].join(" and ");
+
+/**
+ * The self-reference written every other way it can be written, since a
+ * reference reaches the mention card through a different resolution path per
+ * form: the autolink preprocessor for bare prose, and the entity-link unfurl
+ * for a pasted URL — which itself splits on whether "copy link" produced a
+ * UUID or an identifier.
+ *
+ * Each pairs the self-reference with an other-issue reference on the SAME
+ * path, so a failure here means the current-issue check stopped applying, not
+ * that the path stopped resolving at all.
+ */
+const SELF_REFERENCE_FORMS: ReadonlyArray<readonly [string, string]> = [
+ ["a bare identifier", "See MUL-7 and MUL-8."],
+ [
+ "a UUID URL",
+ `See ${APP_ORIGIN}/acme/issues/${CURRENT_ID} and ${APP_ORIGIN}/acme/issues/${OTHER_ID}.`,
+ ],
+ [
+ "an identifier URL",
+ `See ${APP_ORIGIN}/acme/issues/MUL-7 and ${APP_ORIGIN}/acme/issues/MUL-8.`,
+ ],
+];
+
+function makeIssue(id: string, identifier: string): Issue {
+ return { id, identifier } as unknown as Issue;
+}
+
+function adapter(): NavigationAdapter {
+ return {
+ push: vi.fn(),
+ replace: vi.fn(),
+ back: vi.fn(),
+ pathname: "/",
+ searchParams: new URLSearchParams(),
+ getShareableUrl: (path) => `${APP_ORIGIN}${path}`,
+ };
+}
+
+function renderContent(
+ context?: CurrentIssueRenderContextValue,
+ content = CONTENT,
+) {
+ return renderWithI18n(
+ <NavigationProvider value={adapter()}>
+ {context ? (
+ <CurrentIssueRenderContextProvider value={context}>
+ <RichContent content={content} />
+ </CurrentIssueRenderContextProvider>
+ ) : (
+ <RichContent content={content} />
+ )}
+ </NavigationProvider>,
+ );
+}
+
+beforeEach(() => {
+ resolvedIssues.current = makeIssue(CURRENT_ID, "MUL-7");
+ resolvedIssues.other = makeIssue(OTHER_ID, "MUL-8");
+});
+
+describe("RichContent current-issue rendering", () => {
+ it("marks only the current UUID mention in a paragraph with two other references as current", () => {
+ renderContent(CURRENT_CONTEXT);
+
+ const chips = screen.getAllByTestId("issue-chip");
+ expect(chips).toHaveLength(3);
+ expect(chips.map((chip) => chip.getAttribute("data-issue-id"))).toEqual([
+ CURRENT_ID,
+ OTHER_ID,
+ OTHER_ID,
+ ]);
+ expect(chips.map((chip) => chip.getAttribute("data-current"))).toEqual([
+ "true",
+ "false",
+ "false",
+ ]);
+ expect(chips[0]).toHaveTextContent("This issue · MUL-7");
+ });
+
+ it.each(SELF_REFERENCE_FORMS)(
+ "marks the current issue written as %s, and only it, as current",
+ (_form, content) => {
+ renderContent(CURRENT_CONTEXT, content);
+
+ const chips = screen.getAllByTestId("issue-chip");
+ expect(chips.map((chip) => chip.getAttribute("data-issue-id"))).toEqual([
+ CURRENT_ID,
+ OTHER_ID,
+ ]);
+ expect(chips.map((chip) => chip.getAttribute("data-current"))).toEqual([
+ "true",
+ "false",
+ ]);
+ expect(chips[0]).toHaveTextContent("This issue · MUL-7");
+ },
+ );
+
+ it("keeps every chip on regular content without a current-issue provider", () => {
+ renderContent();
+
+ const chips = screen.getAllByTestId("issue-chip");
+ expect(chips).toHaveLength(3);
+ for (const chip of chips) {
+ expect(chip).toHaveAttribute("data-current", "false");
+ }
+ });
+});