π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π style(goal): move archive beside the favorite star on the goal detail header (#22765)
Rdmclin27dde5fe4728a
diff --git a/src/features/AgentGoals/GoalDetailActions.tsx b/src/features/AgentGoals/GoalDetailActions.tsxindex 2f927bdc36a..5e87004280e 100644--- a/src/features/AgentGoals/GoalDetailActions.tsx+++ b/src/features/AgentGoals/GoalDetailActions.tsx@@ -1,10 +1,12 @@-import { ActionIcon, DropdownMenu } from '@lobehub/ui';-import { MoreHorizontalIcon } from 'lucide-react';+import { ActionIcon, cssVar, DropdownMenu } from '@lobehub/ui';+import { ArchiveIcon, ArchiveRestoreIcon, MoreHorizontalIcon } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';+import { DESKTOP_HEADER_ICON_SMALL_SIZE } from '@/const/layoutTokens';import { goalSelectors, useGoalStore } from '@/store/goal';+import { useGoalArchiveToggle } from './useGoalArchiveToggle';import { useGoalMenuItems } from './useGoalMenuItems';interface GoalDetailActionsProps {@@ -17,27 +19,54 @@ interface GoalDetailActionsProps {projectId?: string | null;}+/** The detail header's archive button and "more" menu, beside the favorite star like a task's. */const GoalDetailActions = memo<GoalDetailActionsProps>(({ agentId, archivedAt, goalId, onRename, 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);const title = useGoalStore((s) => goalSelectors.goalGraph(goalId)(s)?.goal.title);+ const archive = useGoalArchiveToggle({ archivedAt, creatorUserId, goalId, status });const items = useGoalMenuItems({agentId,+ // Still passed: an archived goal's status submenu stays locked until restored.archivedAt,creatorUserId,goalId,+ // The archive action has its own header button.+ omitArchive: true,onRename,projectId,status,title,});+ const canArchive = !archive.deniedReason;+return (- <DropdownMenu items={items} placement={'bottomRight'}>- <ActionIcon icon={MoreHorizontalIcon} size={'small'} title={t('goalDetail.moreActions')} />- </DropdownMenu>+ <>+ {/* A blocked archive stays enabled so hover and keyboard users can read why;+ a click only repeats the reason. Never mark it `aria-disabled`: ActionIcon+ styles that with `pointer-events: none`, which hides the reason. */}+ <ActionIcon+ aria-description={archive.deniedReason}+ aria-label={archive.label}+ color={canArchive ? undefined : cssVar.colorTextDisabled}+ icon={archive.isArchived ? ArchiveRestoreIcon : ArchiveIcon}+ size={DESKTOP_HEADER_ICON_SMALL_SIZE}+ style={canArchive ? undefined : { cursor: 'not-allowed' }}+ title={archive.deniedReason ?? archive.label}+ tooltipProps={{ placement: 'bottom' }}+ onClick={() => void archive.toggle()}+ />+ <DropdownMenu items={items} placement={'bottomRight'}>+ <ActionIcon+ icon={MoreHorizontalIcon}+ size={'small'}+ title={t('goalDetail.moreActions')}+ />+ </DropdownMenu>+ </>);},);diff --git a/src/features/AgentGoals/useGoalArchiveToggle.test.ts b/src/features/AgentGoals/useGoalArchiveToggle.test.tsnew file mode 100644index 00000000000..f0ed8adc7f9--- /dev/null+++ b/src/features/AgentGoals/useGoalArchiveToggle.test.ts@@ -0,0 +1,93 @@+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useGoalArchiveToggle } from './useGoalArchiveToggle';++const mocks = vi.hoisted(() => ({+ canManage: true,+ store: { archiveGoal: vi.fn() },+ toast: { error: vi.fn(), info: vi.fn(), success: vi.fn() },+}));++vi.mock('@lobehub/ui', () => ({ toast: mocks.toast }));+vi.mock('@/store/goal', () => ({+ useGoalStore: (selector: (s: typeof mocks.store) => unknown) => selector(mocks.store),+}));+vi.mock('@/hooks/useResourceManageable', () => ({+ useResourceManageable: () => mocks.canManage,+}));+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));++const base = { creatorUserId: 'user_1', goalId: 'goal_1' };++describe('useGoalArchiveToggle', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mocks.canManage = true;+ mocks.store.archiveGoal.mockResolvedValue(undefined);+ });++ it('archives a completed goal and reports it', async () => {+ const onArchived = vi.fn();+ const { result } = renderHook(() =>+ useGoalArchiveToggle({ ...base, archivedAt: null, onArchived, status: 'achieved' }),+ );++ expect(result.current).toMatchObject({+ deniedReason: undefined,+ isArchived: false,+ label: 'goalList.archive',+ });+ await act(() => result.current.toggle());++ expect(mocks.store.archiveGoal).toHaveBeenCalledWith('goal_1', true);+ expect(mocks.toast.success).toHaveBeenCalledWith('goalList.archiveSuccess');+ expect(onArchived).toHaveBeenCalled();+ });++ it('restores an archived goal whatever its status', async () => {+ const { result } = renderHook(() =>+ useGoalArchiveToggle({ ...base, archivedAt: '2026-11-03T00:00:00.000Z', status: 'running' }),+ );++ expect(result.current).toMatchObject({ deniedReason: undefined, label: 'goalList.unarchive' });+ await act(() => result.current.toggle());++ expect(mocks.store.archiveGoal).toHaveBeenCalledWith('goal_1', false);+ });++ it('only repeats why a goal still in flight cannot be archived', async () => {+ const { result } = renderHook(() =>+ useGoalArchiveToggle({ ...base, archivedAt: null, status: 'running' }),+ );++ expect(result.current.deniedReason).toBe('goalList.archiveBlocked');+ await act(() => result.current.toggle());++ expect(mocks.store.archiveGoal).not.toHaveBeenCalled();+ expect(mocks.toast.info).toHaveBeenCalledWith('goalList.archiveBlocked');+ });++ it('refuses a member who may not manage the goal', async () => {+ mocks.canManage = false;+ const { result } = renderHook(() =>+ useGoalArchiveToggle({ ...base, archivedAt: null, status: 'achieved' }),+ );++ await act(() => result.current.toggle());++ expect(mocks.store.archiveGoal).not.toHaveBeenCalled();+ expect(mocks.toast.info).toHaveBeenCalledWith('goalList.archiveDenied');+ });++ it('reports a failed archive', async () => {+ mocks.store.archiveGoal.mockRejectedValue(new Error('boom'));+ const { result } = renderHook(() =>+ useGoalArchiveToggle({ ...base, archivedAt: null, status: 'canceled' }),+ );++ await act(() => result.current.toggle());++ expect(mocks.toast.error).toHaveBeenCalledWith('goalList.archiveFailed');+ });+});diff --git a/src/features/AgentGoals/useGoalArchiveToggle.ts b/src/features/AgentGoals/useGoalArchiveToggle.tsnew file mode 100644index 00000000000..3add245e4c8--- /dev/null+++ b/src/features/AgentGoals/useGoalArchiveToggle.ts@@ -0,0 +1,72 @@+import { isGoalArchiveBlocked } from '@lobechat/types';+import { toast } from '@lobehub/ui';+import { useCallback, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++import { useResourceManageable } from '@/hooks/useResourceManageable';+import { useGoalStore } from '@/store/goal';++interface UseGoalArchiveToggleOptions {+ archivedAt?: Date | string | null;+ creatorUserId?: string | null;+ goalId: string;+ /** Runs after the archive lands, for hosts that render the goal from another read. */+ onArchived?: () => void;+ status?: string;+}++export interface GoalArchiveToggle {+ /** Why the archive is refused, or `undefined` when it may run. */+ deniedReason?: string;+ isArchived: boolean;+ label: string;+ /** Archives or restores; when refused, only repeats the reason. */+ toggle: () => Promise<void>;+}++/** Archive or restore a goal, shared by the detail header button and the list rows' menu. */+export const useGoalArchiveToggle = ({+ archivedAt,+ creatorUserId,+ goalId,+ onArchived,+ status,+}: UseGoalArchiveToggleOptions): GoalArchiveToggle => {+ const { t } = useTranslation('chat');+ // Archiving hides the goal from every list, so the server only lets the+ // creator or a workspace owner do it β the same rule as closing.+ const canManage = useResourceManageable(creatorUserId);+ const archiveGoal = useGoalStore((s) => s.archiveGoal);++ const isArchived = !!archivedAt;+ // Archived goals leave every list, so only a goal that is done with β+ // completed or canceled β may be put away. Restoring is always fine.+ const archiveBlocked = !isArchived && (!status || isGoalArchiveBlocked({ status }));+ const deniedReason = !canManage+ ? t('goalList.archiveDenied')+ : archiveBlocked+ ? t('goalList.archiveBlocked')+ : undefined;++ const toggle = useCallback(async () => {+ // A blocked button stays clickable so touch users, who get no tooltip, learn why.+ if (deniedReason) {+ toast.info(deniedReason);+ return;+ }+ try {+ await archiveGoal(goalId, !isArchived);+ toast.success(t(isArchived ? 'goalList.unarchiveSuccess' : 'goalList.archiveSuccess'));+ onArchived?.();+ } catch {+ toast.error(t(isArchived ? 'goalList.unarchiveFailed' : 'goalList.archiveFailed'));+ }+ }, [archiveGoal, deniedReason, goalId, isArchived, onArchived, t]);++ const label = t(isArchived ? 'goalList.unarchive' : 'goalList.archive');++ return useMemo(+ () => ({ deniedReason, isArchived, label, toggle }),+ [deniedReason, isArchived, label, toggle],+ );+};diff --git a/src/features/AgentGoals/useGoalMenuItems.test.ts b/src/features/AgentGoals/useGoalMenuItems.test.tsindex d8261e341e0..cbdbc2611c4 100644--- a/src/features/AgentGoals/useGoalMenuItems.test.ts+++ b/src/features/AgentGoals/useGoalMenuItems.test.ts@@ -137,6 +137,27 @@ describe('useGoalItemMenu', () => {expect(keys.slice(-5)).toEqual(['copyLink', 'copy-goal', 'divider', 'archive', 'delete']);});+ // The detail header shows archive as its own button beside the favorite star.+ it('leaves the archive action out for a host that shows it on its own', () => {+ const { result } = renderHook(() =>+ useGoalMenuItems({+ archivedAt: '2026-11-03T00:00:00.000Z',+ goalId: 'goal_1',+ omitArchive: true,+ status: 'achieved',+ title: 'Desk pet',+ }),+ );++ const items = result.current;+ const keys = items.map((item) => (item && 'key' in item ? item.key : item?.type));+ expect(keys).not.toContain('archive');+ expect(keys).toContain('delete');+ // The goal is still archived, so its lifecycle stays locked until restored.+ const status = items.find((item) => item && 'key' in item && item.key === 'status') as any;+ expect(status.disabled).toBe(true);+ });+describe('archive', () => {const archiveItem = (items: DropdownItem[]) =>items.find((item) => item && 'key' in item && item.key === 'archive') as any;diff --git a/src/features/AgentGoals/useGoalMenuItems.tsx b/src/features/AgentGoals/useGoalMenuItems.tsxindex 529ec973a81..fdfa9a200f1 100644--- a/src/features/AgentGoals/useGoalMenuItems.tsx+++ b/src/features/AgentGoals/useGoalMenuItems.tsx@@ -1,4 +1,3 @@-import { isGoalArchiveBlocked } from '@lobechat/types';import { confirmModal, copyToClipboard, type DropdownItem, Icon, toast } from '@lobehub/ui';import {ArchiveIcon,@@ -28,6 +27,7 @@ import {toManualStatus,} from './goalStatusMenu';import { useConfirmDeleteGoal, useGoalRename, useGoalShareUrl } from './useGoalActions';+import { useGoalArchiveToggle } from './useGoalArchiveToggle';interface UseGoalMenuItemsOptions {/** Absent for a goal with no responsible agent β e.g. one created from a project. */@@ -36,6 +36,8 @@ interface UseGoalMenuItemsOptions {archivedAt?: Date | string | null;creatorUserId?: string | null;goalId: string;+ /** Leaves the archive action out for a host that shows it on its own, like the detail header. */+ omitArchive?: boolean;/** Replaces the default redirect to the goal list after a delete. */onDeleted?: () => void;/** Replaces the rename dialog, for a host that already edits the title in place. */@@ -54,6 +56,7 @@ export const useGoalMenuItems = ({archivedAt,creatorUserId,goalId,+ omitArchive,onDeleted,onRename,onStatusChanged,@@ -72,27 +75,20 @@ export const useGoalMenuItems = ({const resumeGoal = useGoalStore((s) => s.resumeGoal);const startGoal = useGoalStore((s) => s.startGoal);const closeGoal = useGoalStore((s) => s.closeGoal);- const archiveGoal = useGoalStore((s) => s.archiveGoal);const transferItems = useGoalTransferMenuItem(goalId) as DropdownItem[] | null;const { autoRename, openRename } = useGoalRename(goalId);// The server lets a workspace goal be renamed only by its creator or an owner.const canRename = canEditTask && canClose;const current = toManualStatus(status);- const isArchived = !!archivedAt;- // Archived goals leave every list, so only a goal that is done with β- // completed or canceled β may be put away. Restoring is always fine.- const archiveBlocked = !isArchived && (!status || isGoalArchiveBlocked({ status }));-- const toggleArchive = useCallback(async () => {- try {- await archiveGoal(goalId, !isArchived);- toast.success(t(isArchived ? 'goalList.unarchiveSuccess' : 'goalList.archiveSuccess'));- onStatusChanged?.();- } catch {- toast.error(t(isArchived ? 'goalList.unarchiveFailed' : 'goalList.archiveFailed'));- }- }, [archiveGoal, goalId, isArchived, onStatusChanged, t]);+ const archive = useGoalArchiveToggle({+ archivedAt,+ creatorUserId,+ goalId,+ onArchived: onStatusChanged,+ status,+ });+ const { isArchived } = archive;const changeStatus = useCallback((next: ManualGoalStatus) => {@@ -188,20 +184,16 @@ export const useGoalMenuItems = ({},...(transferItems ?? []),{ type: 'divider' },- ...(archivedAt === undefined+ ...(omitArchive || archivedAt === undefined? []: [{- desc: !canClose- ? t('goalList.archiveDenied')- : archiveBlocked- ? t('goalList.archiveBlocked')- : undefined,- disabled: !canClose || archiveBlocked,+ desc: archive.deniedReason,+ disabled: !!archive.deniedReason,icon: <Icon icon={isArchived ? ArchiveRestoreIcon : ArchiveIcon} />,key: 'archive',- label: t(isArchived ? 'goalList.unarchive' : 'goalList.archive'),- onClick: toggleArchive,+ label: archive.label,+ onClick: archive.toggle,} satisfies DropdownItem,]),{@@ -214,7 +206,7 @@ export const useGoalMenuItems = ({},],[- archiveBlocked,+ archive,archivedAt,autoRename,canClose,@@ -225,13 +217,13 @@ export const useGoalMenuItems = ({current,goalId,isArchived,+ omitArchive,onRename,openRename,shareUrl,status,t,title,- toggleArchive,transferItems,],);