Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(goal): add a context menu and a more button to goal list rows (#21211)

Arvin Xuc5ed0bc1dbe9
diff --git a/src/features/AgentGoals/GoalCardItem.tsx b/src/features/AgentGoals/GoalCardItem.tsx
index d13552e1f36..6ea528030bb 100644
--- a/src/features/AgentGoals/GoalCardItem.tsx
+++ b/src/features/AgentGoals/GoalCardItem.tsx
@@ -1,16 +1,17 @@
'use client';
-import { Block, createStaticStyles, cssVar, Flexbox, Icon, Text } from '@lobehub/ui';
-import { ArrowRightIcon } from 'lucide-react';
+import { Block, ContextMenuTrigger, createStaticStyles, cssVar, Flexbox, Text } from '@lobehub/ui';
import type { KeyboardEvent } from 'react';
import { memo } from 'react';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';
+import GoalItemMoreButton from './GoalItemMoreButton';
import { GoalProgress } from './GoalProgress';
import GoalStatusGlyph from './GoalStatusGlyph';
import type { GoalItemProps } from './types';
+import { useGoalItemMenu } from './useGoalMenuItems';
const styles = createStaticStyles(({ css }) => ({
card: css`
@@ -20,7 +21,8 @@ const styles = createStaticStyles(({ css }) => ({
background 0.2s ${cssVar.motionEaseOut},
transform 0.2s ${cssVar.motionEaseOut};
- &:hover {
+ &:hover,
+ &[data-popup-open] {
transform: translateY(-1px);
border-color: ${cssVar.colorPrimaryBorder};
background: ${cssVar.colorFillQuaternary};
@@ -28,7 +30,7 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-export const GoalCardItem = memo<GoalItemProps>(({ goal: item }) => {
+export const GoalCardItem = memo<GoalItemProps>(({ goal: item, projectId }) => {
const navigate = useWorkspaceAwareNavigate();
const { aid } = useActiveRouteParams<{ aid?: string }>();
const { goal } = item;
@@ -39,6 +41,7 @@ export const GoalCardItem = memo<GoalItemProps>(({ goal: item }) => {
const handleClick = () => {
navigate(agentId ? `/agent/${agentId}/goal/${goal.id}` : `/goal/${goal.id}`);
};
+ const menuItems = useGoalItemMenu({ agentId, goal, projectId, routeAgentId: aid });
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
@@ -46,42 +49,44 @@ export const GoalCardItem = memo<GoalItemProps>(({ goal: item }) => {
};
return (
- <Block
- clickable
- className={styles.card}
- gap={12}
- padding={16}
- role={'link'}
- tabIndex={0}
- variant={'outlined'}
- onClick={handleClick}
- onKeyDown={handleKeyDown}
- >
- <Flexbox horizontal align={'flex-start'} gap={12} justify={'space-between'}>
- <Flexbox gap={4} style={{ minWidth: 0 }}>
- <Flexbox horizontal align={'center'} gap={7}>
- <GoalStatusGlyph size={13} status={goal.status} />
- <Text ellipsis fontSize={15} weight={600}>
- {goal.title}
- </Text>
+ <ContextMenuTrigger items={menuItems}>
+ <Block
+ clickable
+ className={styles.card}
+ gap={12}
+ padding={16}
+ role={'link'}
+ tabIndex={0}
+ variant={'outlined'}
+ onClick={handleClick}
+ onKeyDown={handleKeyDown}
+ >
+ <Flexbox horizontal align={'flex-start'} gap={12} justify={'space-between'}>
+ <Flexbox gap={4} style={{ minWidth: 0 }}>
+ <Flexbox horizontal align={'center'} gap={7}>
+ <GoalStatusGlyph size={13} status={goal.status} />
+ <Text ellipsis fontSize={15} weight={600}>
+ {goal.title}
+ </Text>
+ </Flexbox>
+ {goal.requirement && goal.requirement !== goal.title && (
+ <Text ellipsis fontSize={12} type={'secondary'}>
+ {goal.requirement}
+ </Text>
+ )}
</Flexbox>
- {goal.requirement && goal.requirement !== goal.title && (
- <Text ellipsis fontSize={12} type={'secondary'}>
- {goal.requirement}
- </Text>
- )}
+ <GoalItemMoreButton items={menuItems} />
</Flexbox>
- <Icon color={cssVar.colorTextQuaternary} icon={ArrowRightIcon} size={16} />
- </Flexbox>
- <GoalProgress
- findingCount={item.findingCount}
- pendingDecisions={item.pendingDecisions}
- taskDone={item.taskDone}
- taskTotal={item.taskTotal}
- totalRunCost={item.totalRunCost}
- totalRunDuration={item.totalRunDuration}
- />
- </Block>
+ <GoalProgress
+ findingCount={item.findingCount}
+ pendingDecisions={item.pendingDecisions}
+ taskDone={item.taskDone}
+ taskTotal={item.taskTotal}
+ totalRunCost={item.totalRunCost}
+ totalRunDuration={item.totalRunDuration}
+ />
+ </Block>
+ </ContextMenuTrigger>
);
});
diff --git a/src/features/AgentGoals/GoalDetailActions.tsx b/src/features/AgentGoals/GoalDetailActions.tsx
index d5dbf52d862..0b92f8911e3 100644
--- a/src/features/AgentGoals/GoalDetailActions.tsx
+++ b/src/features/AgentGoals/GoalDetailActions.tsx
@@ -1,30 +1,11 @@
-import {
- ActionIcon,
- confirmModal,
- copyToClipboard,
- type DropdownItem,
- DropdownMenu,
- Icon,
- toast,
-} from '@lobehub/ui';
-import { CircleDashedIcon, CopyIcon, LinkIcon, MoreHorizontalIcon, TrashIcon } from 'lucide-react';
-import { memo, useCallback, useMemo } from 'react';
+import { ActionIcon, DropdownMenu } from '@lobehub/ui';
+import { MoreHorizontalIcon } from 'lucide-react';
+import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { TASK_STATUS_VISUALS } from '@/components/ExecutionStatus';
-import { renderMenuCheck } from '@/features/AgentTasks/features/menuExtra';
-import { usePermission } from '@/hooks/usePermission';
-import { useResourceManageable } from '@/hooks/useResourceManageable';
import { goalSelectors, useGoalStore } from '@/store/goal';
-import { goalStatusToTaskStatus } from './goalPresentation';
-import {
- isStatusChoiceDisabled,
- MANUAL_STATUSES,
- type ManualGoalStatus,
- toManualStatus,
-} from './goalStatusMenu';
-import { useConfirmDeleteGoal, useGoalShareUrl } from './useGoalActions';
+import { useGoalMenuItems } from './useGoalMenuItems';
interface GoalDetailActionsProps {
/** Absent for a goal with no responsible agent β€” e.g. one created from a project. */
@@ -34,93 +15,10 @@ interface GoalDetailActionsProps {
}
const GoalDetailActions = memo<GoalDetailActionsProps>(({ agentId, goalId, projectId }) => {
- const { t } = useTranslation(['chat', 'common']);
- const { allowed: canEditTask } = usePermission('create_content');
- const shareUrl = useGoalShareUrl({ agentId, goalId });
- const confirmDelete = useConfirmDeleteGoal({ agentId, goalId, projectId });
+ const { t } = useTranslation('chat');
const status = useGoalStore((s) => goalSelectors.goalGraph(goalId)(s)?.goal.status);
const creatorUserId = useGoalStore((s) => goalSelectors.goalGraph(goalId)(s)?.goal.userId);
- // Closing interrupts runs, so the server only lets the creator or a
- // workspace owner do it β€” the same rule as restart.
- const canClose = useResourceManageable(creatorUserId);
- const pauseGoal = useGoalStore((s) => s.pauseGoal);
- const resumeGoal = useGoalStore((s) => s.resumeGoal);
- const startGoal = useGoalStore((s) => s.startGoal);
- const closeGoal = useGoalStore((s) => s.closeGoal);
-
- const current = toManualStatus(status);
-
- const changeStatus = useCallback(
- (next: ManualGoalStatus) => {
- if (next === current) return;
- if (next === 'running') return void (status === 'draft' ? startGoal : resumeGoal)(goalId);
- if (next === 'paused') return void pauseGoal(goalId);
- // Closing interrupts live runs, so it asks first.
- confirmModal({
- cancelText: t('cancel', { ns: 'common' }),
- content: t(`goalDetail.closeConfirm.${next}.content`),
- okButtonProps: { danger: next === 'canceled' },
- okText: t(`goalDetail.closeConfirm.${next}.ok`),
- onOk: () => closeGoal(goalId, next),
- title: t(`goalDetail.closeConfirm.${next}.title`),
- });
- },
- [closeGoal, current, goalId, pauseGoal, resumeGoal, startGoal, status, t],
- );
-
- const items = useMemo<DropdownItem[]>(
- () => [
- // Same shape as a task's status submenu: status-colored glyphs, a check on the current one.
- {
- children: MANUAL_STATUSES.map((next) => {
- const visual = TASK_STATUS_VISUALS[goalStatusToTaskStatus(next)];
- return {
- disabled: isStatusChoiceDisabled(next, status, canClose),
- extra: renderMenuCheck(next === current),
- icon: <Icon color={visual.color} icon={visual.icon} />,
- key: `status-${next}`,
- label: t(`goalList.status.${next}`),
- onClick: () => changeStatus(next),
- };
- }),
- disabled: !canEditTask || !status,
- icon: <Icon icon={CircleDashedIcon} />,
- key: 'status',
- label: t('taskList.contextMenu.status'),
- },
- { type: 'divider' },
- {
- icon: <Icon icon={CopyIcon} />,
- key: 'copyId',
- label: t('taskList.contextMenu.copyId'),
- onClick: async () => {
- await copyToClipboard(goalId);
- toast.success(t('taskList.contextMenu.copyIdSuccess'));
- },
- },
- {
- disabled: !shareUrl,
- icon: <Icon icon={LinkIcon} />,
- key: 'copyLink',
- label: t('taskList.contextMenu.copyLink'),
- onClick: async () => {
- if (!shareUrl) return;
- await copyToClipboard(shareUrl);
- toast.success(t('taskList.contextMenu.copyLinkSuccess'));
- },
- },
- { type: 'divider' },
- {
- danger: true,
- disabled: !canEditTask,
- icon: <Icon icon={TrashIcon} />,
- key: 'delete',
- label: t('delete', { ns: 'common' }),
- onClick: confirmDelete,
- },
- ],
- [canClose, canEditTask, changeStatus, confirmDelete, current, goalId, shareUrl, status, t],
- );
+ const items = useGoalMenuItems({ agentId, creatorUserId, goalId, projectId, status });
return (
<DropdownMenu items={items} placement={'bottomRight'}>
diff --git a/src/features/AgentGoals/GoalItemMoreButton.tsx b/src/features/AgentGoals/GoalItemMoreButton.tsx
new file mode 100644
index 00000000000..22130f84319
--- /dev/null
+++ b/src/features/AgentGoals/GoalItemMoreButton.tsx
@@ -0,0 +1,27 @@
+'use client';
+
+import { ActionIcon, type DropdownItem, DropdownMenu } from '@lobehub/ui';
+import { MoreHorizontalIcon } from 'lucide-react';
+import type { SyntheticEvent } from 'react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+// The menu renders in a portal, whose React events still bubble to the row it sits in.
+const stopPropagation = (event: SyntheticEvent) => event.stopPropagation();
+
+/** The "more" button of a clickable goal row: opening it or picking an item must not open the goal. */
+const GoalItemMoreButton = memo<{ items: DropdownItem[] }>(({ items }) => {
+ const { t } = useTranslation('chat');
+
+ return (
+ <div onClick={stopPropagation} onKeyDown={stopPropagation}>
+ <DropdownMenu items={items} placement={'bottomRight'}>
+ <ActionIcon icon={MoreHorizontalIcon} size={'small'} title={t('goalDetail.moreActions')} />
+ </DropdownMenu>
+ </div>
+ );
+});
+
+GoalItemMoreButton.displayName = 'GoalItemMoreButton';
+
+export default GoalItemMoreButton;
diff --git a/src/features/AgentGoals/GoalListItem.tsx b/src/features/AgentGoals/GoalListItem.tsx
index 33936c31abb..fad8474e230 100644
--- a/src/features/AgentGoals/GoalListItem.tsx
+++ b/src/features/AgentGoals/GoalListItem.tsx
@@ -1,16 +1,17 @@
'use client';
-import { Block, createStaticStyles, cssVar, Flexbox, Icon, Text } from '@lobehub/ui';
-import { ArrowRightIcon } from 'lucide-react';
+import { Block, ContextMenuTrigger, createStaticStyles, cssVar, Flexbox, Text } from '@lobehub/ui';
import type { KeyboardEvent } from 'react';
import { memo } from 'react';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';
+import GoalItemMoreButton from './GoalItemMoreButton';
import { GoalProgress } from './GoalProgress';
import GoalStatusGlyph from './GoalStatusGlyph';
import type { GoalItemProps } from './types';
+import { useGoalItemMenu } from './useGoalMenuItems';
const styles = createStaticStyles(({ css }) => ({
row: css`
@@ -21,13 +22,14 @@ const styles = createStaticStyles(({ css }) => ({
border-block-start: 1px solid ${cssVar.colorBorderSecondary};
}
- &:hover {
+ &:hover,
+ &[data-popup-open] {
background: ${cssVar.colorFillQuaternary};
}
`,
}));
-export const GoalListItem = memo<GoalItemProps>(({ goal: item }) => {
+export const GoalListItem = memo<GoalItemProps>(({ goal: item, projectId }) => {
const navigate = useWorkspaceAwareNavigate();
const { aid } = useActiveRouteParams<{ aid?: string }>();
const { goal } = item;
@@ -38,6 +40,7 @@ export const GoalListItem = memo<GoalItemProps>(({ goal: item }) => {
const handleClick = () => {
navigate(agentId ? `/agent/${agentId}/goal/${goal.id}` : `/goal/${goal.id}`);
};
+ const menuItems = useGoalItemMenu({ agentId, goal, projectId, routeAgentId: aid });
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
@@ -45,44 +48,46 @@ export const GoalListItem = memo<GoalItemProps>(({ goal: item }) => {
};
return (
- <Block
- clickable
- horizontal
- align={'center'}
- className={styles.row}
- gap={12}
- justify={'space-between'}
- paddingBlock={10}
- paddingInline={0}
- role={'link'}
- tabIndex={0}
- variant={'borderless'}
- onClick={handleClick}
- onKeyDown={handleKeyDown}
- >
- <Flexbox gap={4} style={{ flex: 1, minWidth: 0 }}>
- <Flexbox horizontal align={'center'} gap={7}>
- <GoalStatusGlyph size={13} status={goal.status} />
- <Text ellipsis fontSize={15} weight={600}>
- {goal.title}
- </Text>
+ <ContextMenuTrigger items={menuItems}>
+ <Block
+ clickable
+ horizontal
+ align={'center'}
+ className={styles.row}
+ gap={12}
+ justify={'space-between'}
+ paddingBlock={10}
+ paddingInline={12}
+ role={'link'}
+ tabIndex={0}
+ variant={'borderless'}
+ onClick={handleClick}
+ onKeyDown={handleKeyDown}
+ >
+ <Flexbox gap={4} style={{ flex: 1, minWidth: 0 }}>
+ <Flexbox horizontal align={'center'} gap={7}>
+ <GoalStatusGlyph size={13} status={goal.status} />
+ <Text ellipsis fontSize={15} weight={600}>
+ {goal.title}
+ </Text>
+ </Flexbox>
+ {goal.requirement && goal.requirement !== goal.title && (
+ <Text ellipsis fontSize={12} type={'secondary'}>
+ {goal.requirement}
+ </Text>
+ )}
</Flexbox>
- {goal.requirement && goal.requirement !== goal.title && (
- <Text ellipsis fontSize={12} type={'secondary'}>
- {goal.requirement}
- </Text>
- )}
- </Flexbox>
- <GoalProgress
- findingCount={item.findingCount}
- pendingDecisions={item.pendingDecisions}
- taskDone={item.taskDone}
- taskTotal={item.taskTotal}
- totalRunCost={item.totalRunCost}
- totalRunDuration={item.totalRunDuration}
- />
- <Icon color={cssVar.colorTextQuaternary} icon={ArrowRightIcon} size={16} />
- </Block>
+ <GoalProgress
+ findingCount={item.findingCount}
+ pendingDecisions={item.pendingDecisions}
+ taskDone={item.taskDone}
+ taskTotal={item.taskTotal}
+ totalRunCost={item.totalRunCost}
+ totalRunDuration={item.totalRunDuration}
+ />
+ <GoalItemMoreButton items={menuItems} />
+ </Block>
+ </ContextMenuTrigger>
);
});
diff --git a/src/features/AgentGoals/useGoalMenuItems.test.ts b/src/features/AgentGoals/useGoalMenuItems.test.ts
new file mode 100644
index 00000000000..a9c7ef73f51
--- /dev/null
+++ b/src/features/AgentGoals/useGoalMenuItems.test.ts
@@ -0,0 +1,82 @@
+import type { DropdownItem } from '@lobehub/ui';
+import { act, renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useGoalItemMenu } from './useGoalMenuItems';
+
+const mocks = vi.hoisted(() => ({
+ confirmDelete: vi.fn(),
+ deleteOptions: undefined as { onDeleted?: () => void } | undefined,
+ navigate: vi.fn(),
+ store: {
+ closeGoal: vi.fn(),
+ pauseGoal: vi.fn(),
+ refreshGoals: vi.fn(),
+ resumeGoal: vi.fn(),
+ startGoal: vi.fn(),
+ },
+}));
+
+vi.mock('@/store/goal', () => ({
+ useGoalStore: (selector: (s: typeof mocks.store) => unknown) => selector(mocks.store),
+}));
+vi.mock('@/hooks/useResourceManageable', () => ({ useResourceManageable: () => true }));
+vi.mock('./useGoalActions', () => ({
+ useConfirmDeleteGoal: (options: { onDeleted?: () => void }) => {
+ mocks.deleteOptions = options;
+ return mocks.confirmDelete;
+ },
+ useGoalShareUrl: () => 'https://app.lobehub.com/goal/goal_1',
+}));
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+const goal = { agentId: 'agt_1', id: 'goal_1', status: 'running', userId: 'user_1' };
+
+const pickStatus = (items: DropdownItem[], next: string) => {
+ const status = items.find((item) => item && 'key' in item && item.key === 'status') as any;
+ const choice = status.children.find((child: any) => child.key === `status-${next}`);
+ return choice.onClick();
+};
+
+describe('useGoalItemMenu', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.store.pauseGoal.mockResolvedValue(undefined);
+ mocks.store.resumeGoal.mockResolvedValue(undefined);
+ });
+
+ // The row renders its status from the list, which the store's status
+ // actions do not refresh: without the refetch the row keeps the old status.
+ it('refetches the project list a status change was made from', async () => {
+ const { result } = renderHook(() =>
+ useGoalItemMenu({ agentId: 'agt_1', goal, projectId: 'proj_1' }),
+ );
+
+ await act(async () => pickStatus(result.current, 'paused'));
+
+ expect(mocks.store.pauseGoal).toHaveBeenCalledWith('goal_1');
+ expect(mocks.store.refreshGoals).toHaveBeenCalledWith('project:proj_1');
+ });
+
+ it("refetches the agent's list on an agent page", async () => {
+ const { result } = renderHook(() =>
+ useGoalItemMenu({
+ agentId: 'agt_1',
+ goal: { ...goal, status: 'paused' },
+ routeAgentId: 'agt_1',
+ }),
+ );
+
+ await act(async () => pickStatus(result.current, 'running'));
+
+ expect(mocks.store.resumeGoal).toHaveBeenCalledWith('goal_1');
+ expect(mocks.store.refreshGoals).toHaveBeenCalledWith('agt_1');
+ });
+
+ it('keeps the reader on the list after a delete', () => {
+ renderHook(() => useGoalItemMenu({ agentId: 'agt_1', goal, routeAgentId: 'agt_1' }));
+
+ // A host-supplied onDeleted replaces the redirect to the goal list.
+ expect(mocks.deleteOptions?.onDeleted).toBeTypeOf('function');
+ });
+});
diff --git a/src/features/AgentGoals/useGoalMenuItems.tsx b/src/features/AgentGoals/useGoalMenuItems.tsx
new file mode 100644
index 00000000000..0d9ad8426e8
--- /dev/null
+++ b/src/features/AgentGoals/useGoalMenuItems.tsx
@@ -0,0 +1,172 @@
+import { confirmModal, copyToClipboard, type DropdownItem, Icon, toast } from '@lobehub/ui';
+import { CircleDashedIcon, CopyIcon, LinkIcon, TrashIcon } from 'lucide-react';
+import { useCallback, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { TASK_STATUS_VISUALS } from '@/components/ExecutionStatus';
+import { renderMenuCheck } from '@/features/AgentTasks/features/menuExtra';
+import { usePermission } from '@/hooks/usePermission';
+import { useResourceManageable } from '@/hooks/useResourceManageable';
+import { useGoalStore } from '@/store/goal';
+
+import { goalStatusToTaskStatus } from './goalPresentation';
+import {
+ isStatusChoiceDisabled,
+ MANUAL_STATUSES,
+ type ManualGoalStatus,
+ toManualStatus,
+} from './goalStatusMenu';
+import { useConfirmDeleteGoal, useGoalShareUrl } from './useGoalActions';
+
+interface UseGoalMenuItemsOptions {
+ /** Absent for a goal with no responsible agent β€” e.g. one created from a project. */
+ agentId?: string;
+ creatorUserId?: string | null;
+ goalId: string;
+ /** Replaces the default redirect to the goal list after a delete. */
+ onDeleted?: () => void;
+ /** Runs after a status change lands, for hosts that render the status from another read. */
+ onStatusChanged?: () => void;
+ projectId?: string | null;
+ status?: string;
+}
+
+/** The goal's action menu, shared by the detail header's "more" button and the list rows. */
+export const useGoalMenuItems = ({
+ agentId,
+ creatorUserId,
+ goalId,
+ onDeleted,
+ onStatusChanged,
+ projectId,
+ status,
+}: UseGoalMenuItemsOptions): DropdownItem[] => {
+ const { t } = useTranslation(['chat', 'common']);
+ const { allowed: canEditTask } = usePermission('create_content');
+ const shareUrl = useGoalShareUrl({ agentId, goalId });
+ const confirmDelete = useConfirmDeleteGoal({ agentId, goalId, onDeleted, projectId });
+ // Closing interrupts runs, so the server only lets the creator or a
+ // workspace owner do it β€” the same rule as restart.
+ const canClose = useResourceManageable(creatorUserId);
+ const pauseGoal = useGoalStore((s) => s.pauseGoal);
+ const resumeGoal = useGoalStore((s) => s.resumeGoal);
+ const startGoal = useGoalStore((s) => s.startGoal);
+ const closeGoal = useGoalStore((s) => s.closeGoal);
+
+ const current = toManualStatus(status);
+
+ const changeStatus = useCallback(
+ (next: ManualGoalStatus) => {
+ if (next === current) return;
+ const settle = (change: Promise<void>) => void change.then(onStatusChanged);
+ if (next === 'running') return settle((status === 'draft' ? startGoal : resumeGoal)(goalId));
+ if (next === 'paused') return settle(pauseGoal(goalId));
+ // Closing interrupts live runs, so it asks first.
+ confirmModal({
+ cancelText: t('cancel', { ns: 'common' }),
+ content: t(`goalDetail.closeConfirm.${next}.content`),
+ okButtonProps: { danger: next === 'canceled' },
+ okText: t(`goalDetail.closeConfirm.${next}.ok`),
+ onOk: async () => {
+ await closeGoal(goalId, next);
+ onStatusChanged?.();
+ },
+ title: t(`goalDetail.closeConfirm.${next}.title`),
+ });
+ },
+ [closeGoal, current, goalId, onStatusChanged, pauseGoal, resumeGoal, startGoal, status, t],
+ );
+
+ return useMemo<DropdownItem[]>(
+ () => [
+ // Same shape as a task's status submenu: status-colored glyphs, a check on the current one.
+ {
+ children: MANUAL_STATUSES.map((next) => {
+ const visual = TASK_STATUS_VISUALS[goalStatusToTaskStatus(next)];
+ return {
+ disabled: isStatusChoiceDisabled(next, status, canClose),
+ extra: renderMenuCheck(next === current),
+ icon: <Icon color={visual.color} icon={visual.icon} />,
+ key: `status-${next}`,
+ label: t(`goalList.status.${next}`),
+ onClick: () => changeStatus(next),
+ };
+ }),
+ disabled: !canEditTask || !status,
+ icon: <Icon icon={CircleDashedIcon} />,
+ key: 'status',
+ label: t('taskList.contextMenu.status'),
+ },
+ { type: 'divider' },
+ {
+ icon: <Icon icon={CopyIcon} />,
+ key: 'copyId',
+ label: t('taskList.contextMenu.copyId'),
+ onClick: async () => {
+ await copyToClipboard(goalId);
+ toast.success(t('taskList.contextMenu.copyIdSuccess'));
+ },
+ },
+ {
+ disabled: !shareUrl,
+ icon: <Icon icon={LinkIcon} />,
+ key: 'copyLink',
+ label: t('taskList.contextMenu.copyLink'),
+ onClick: async () => {
+ if (!shareUrl) return;
+ await copyToClipboard(shareUrl);
+ toast.success(t('taskList.contextMenu.copyLinkSuccess'));
+ },
+ },
+ { type: 'divider' },
+ {
+ danger: true,
+ disabled: !canEditTask,
+ icon: <Icon icon={TrashIcon} />,
+ key: 'delete',
+ label: t('delete', { ns: 'common' }),
+ onClick: confirmDelete,
+ },
+ ],
+ [canClose, canEditTask, changeStatus, confirmDelete, current, goalId, shareUrl, status, t],
+ );
+};
+
+interface UseGoalItemMenuOptions {
+ /** The goal's agent, resolved by the host: the route's agent first, then the goal's own. */
+ agentId?: string | null;
+ goal: { agentId?: string | null; id: string; status: string; userId?: string | null };
+ /** The project whose goal page renders the row; absent on an agent's page. */
+ projectId?: string;
+ /** The route's agent, which keys the list scope on an agent's page. */
+ routeAgentId?: string;
+}
+
+/** The action menu of a goal-list row (list or card view). */
+export const useGoalItemMenu = ({
+ agentId,
+ goal,
+ projectId,
+ routeAgentId,
+}: UseGoalItemMenuOptions): DropdownItem[] => {
+ // The row reads its status from the list, not the goal graph the store
+ // actions refresh, so a status change refetches the list it was rendered in.
+ const refreshGoals = useGoalStore((s) => s.refreshGoals);
+ const scopeId = projectId ? `project:${projectId}` : routeAgentId;
+ const handleStatusChanged = useCallback(() => {
+ if (scopeId) void refreshGoals(scopeId);
+ }, [refreshGoals, scopeId]);
+
+ return useGoalMenuItems({
+ agentId: agentId ?? undefined,
+ creatorUserId: goal.userId,
+ goalId: goal.id,
+ // Deleting from the list keeps the reader on the list it just pruned.
+ onDeleted: noop,
+ onStatusChanged: handleStatusChanged,
+ projectId,
+ status: goal.status,
+ });
+};
+
+const noop = () => {};