refactor(selection): split selectedAgentId into focus vs edit-modal states; improve Edit modal title

Before this commit one piece of state (`selectedAgentId`) did three
jobs: roster highlight, navigation destination, and Edit-modal open
flag. The three jobs had incompatible lifecycles — highlight should
persist across modal close, navigation should land on a screen
without opening a modal, and the modal itself only wants to open on
explicit intent. The conflation was the root cause of the "Edit: CEO
auto-opens on first Team view" bug (commit 41132e2 patched the most
visible symptom by not pre-selecting the lead agent, but the coupling
remained).

Split into two slice fields:

- `selectedAgentId` — which agent is currently highlighted in the
  roster / OrgChart. Survives modal close. Set by: row click, card
  click, navigation from Inbox / Hiring (all of which pass through
  `openAgentEditor` which sets both so the highlight follows the last
  interaction).
- `editingAgentId` — which agent's Edit modal is open, or
  NEW_ENTITY_ID for the "Request new hire" modal. Only set by
  explicit user action; cleared on modal close. Never set by
  navigation or onboarding — the pre-select pathway cannot
  accidentally open a modal again.

Plumbing:

- `selection.ts`: new `editingAgentId` + `setEditingAgentId`, plus
  clear on `clearCompanyScopedSelections`.
- `useCompanyData.ts`: derive `editingAgent` record from the id.
- `useCompanyController.ts`: forward `editingAgent` on the section
  context.
- `OrganizationSections.tsx`: `agents` section modals read
  `editingAgentId` / `editingAgent`. "Request new hire" button uses
  `setEditingAgentId(NEW_ENTITY_ID)`. Single-click handlers go
  through `openAgentEditor(id)` which updates both states.

Also improved Edit modal title (was "Edit: CEO", a machined English
prefix on a Chinese UI with zero context about the role):

- zh: "编辑 {name}({role})"
- en: "Edit {name} ({role})"

Renders as "编辑 CEO(首席执行官)" in the screenshot example.

Covers J9 / S2.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 19:54:16 -04:00
1 parent 9981ee342b
commit dc33131553
6 files changed
+50 -12

No files matched your search

+7
View File
@@ -19,6 +19,7 @@ export function useCompanyData(
const selectedTaskId = useAppStore((s) => s.selectedTaskId);
const selectedApprovalId = useAppStore((s) => s.selectedApprovalId);
const selectedAgentId = useAppStore((s) => s.selectedAgentId);
const editingAgentId = useAppStore((s) => s.editingAgentId);
const selectedGoalId = useAppStore((s) => s.selectedGoalId);
const selectedProjectId = useAppStore((s) => s.selectedProjectId);
const selectedWorkspaceId = useAppStore((s) => s.selectedWorkspaceId);
@@ -58,6 +59,10 @@ export function useCompanyData(
() => companyAgents.find((a) => a.id === selectedAgentId) ?? null,
[companyAgents, selectedAgentId],
);
const editingAgent = useMemo(
() => companyAgents.find((a) => a.id === editingAgentId) ?? null,
[companyAgents, editingAgentId],
);
const selectedGoal = useMemo(
() => companyGoals.find((g) => g.id === selectedGoalId) ?? null,
[companyGoals, selectedGoalId],
@@ -104,6 +109,7 @@ export function useCompanyData(
selectedApproval,
selectedRun,
selectedAgent,
editingAgent,
selectedGoal,
selectedProject,
selectedWorkspace,
@@ -128,6 +134,7 @@ export function useCompanyData(
selectedApproval,
selectedRun,
selectedAgent,
editingAgent,
selectedGoal,
selectedProject,
selectedWorkspace,