A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 组织图的「离任」确认框被拒时留着,原因也留在框里(7.42)
lmliheng21b9fe8ece17
diff --git a/changelog/unreleased/2026-10-25-org-chart-leave-refusal.md b/changelog/unreleased/2026-10-25-org-chart-leave-refusal.mdnew file mode 100644index 00000000..b1a46fea--- /dev/null+++ b/changelog/unreleased/2026-10-25-org-chart-leave-refusal.md@@ -0,0 +1,39 @@+# Org chart: a refused leave keeps its question — and the reason++- **Date:** 2026-10-25+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-10-25-org-chart-leave-refusal.zh.md)++The "Leave the organization" row of an employee card's menu asks in the shared confirmation card+before the employee is taken off the chart. That card used to stay open when the leave was+refused, but the reason only fell into a toast that dismissed itself after a few seconds and+floated above the card — the card itself said nothing, so all the reader saw was the buttons+coming alive again with the employee still on the chart, and the retry meant opening the menu+again.++The card now closes only on the path where its leave landed; a refusal draws the server's words+inside the card, right above the retry button (`ConfirmModal`'s `refusal` slot, the app's existing+"Refused:" lead-in). Opening the card again drops the previous reason, which belonged to the+attempt it named; a write in flight takes one press only, and cancelling decides nothing.++## Details++- `features/company/org-chart-page.tsx`: `runLeave()` keeps the server's words in `leaveRefusal`+ instead of only toasting them, and both `setLeaveFor(null)` and the success notice sit on the+ path after the `await` succeeded. The menu's "离任" row clears the previous reason before it+ opens the card; the card's `onClose` already stopped answering while a write was out (`busy`),+ and the card now renders `refusal`.+- New browser test `e2e/org-chart-leave-refusal.spec.mjs`: with+ `DELETE …/organizations/<org>/employees/<employee>` refused at `page.route` 500, the card, its+ sentence and the chart on the server all stay (nothing in the notification region carries the+ words); cancelling and reopening shows no stale reason; the retry on the same card really lets+ the employee go — the card closes, the employee's card leaves the canvas and the chart holds+ the CEO alone.++## Compatibility++- No interface, wire-format, stored-data or dependency change: only *when* this card closes and+ *where* the reason is drawn. No new copy beyond the existing `S.common.refused` lead-in.diff --git a/changelog/unreleased/2026-10-25-org-chart-leave-refusal.zh.md b/changelog/unreleased/2026-10-25-org-chart-leave-refusal.zh.mdnew file mode 100644index 00000000..ef2dce0e--- /dev/null+++ b/changelog/unreleased/2026-10-25-org-chart-leave-refusal.zh.md@@ -0,0 +1,31 @@+# 组织图:让员工离任被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-25+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-25-org-chart-leave-refusal.md)++组织图里员工卡右上角的菜单有一行「离任」,它会用共享的确认框先问一句。过去这张框被拒时框是留着的,可+原因只落进一条几秒后自己消失、还浮在框上方的通知里 —— 框本身一个字都没有,读者只看到按钮又亮了,员工+却还在组织图里,重试还得重新打开菜单。++现在关框只发生在离任落地那条路径上;被拒时服务端原话画进框里、重试按钮正上方(`ConfirmModal` 的+`refusal` 槽,用的是应用既有的「操作被拒绝:」前缀)。重开这张框会先清掉上一次的原因 —— 那句话属于上次+那次尝试;一个写入在途时只认一次点击,取消不决定任何事。++## 细节++- `features/company/org-chart-page.tsx`:`runLeave()` 把服务端原话留在 `leaveRefusal` 里,不再只弹通知;+ `setLeaveFor(null)` 与那段成功通知都在 `await` 成功之后。菜单里那行「离任」在开框前先清掉旧原因;+ 框的 `onClose` 本来就在写入在途时不再响应(`busy`),框现在把 `refusal` 画出来。+- 新增浏览器用例 `e2e/org-chart-leave-refusal.spec.mjs`:用 `page.route` 把+ `DELETE …/organizations/<组织>/employees/<员工>` 拒成 500 之后,框、框里那句话与服务端上的组织图都不变+ (通知区里没有那句原话),取消后重开不带旧原因;在同一张框上重试才真正离任 —— 框关掉、员工的卡片从+ 画布上消失、组织图里只剩 CEO。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了这张框「什么时候关」与「原因画在哪」。除既有的+ `S.common.refused` 前缀外没有新文案。diff --git a/packages/web/e2e/org-chart-leave-refusal.spec.mjs b/packages/web/e2e/org-chart-leave-refusal.spec.mjsnew file mode 100644index 00000000..2ef89816--- /dev/null+++ b/packages/web/e2e/org-chart-leave-refusal.spec.mjs@@ -0,0 +1,163 @@+/**+ * Regression: an employee leaving the organization is asked in a confirmation card, and a refused+ * leave keeps that question — with the server's words inside it — instead of leaving only a toast+ * behind.+ *+ * The card in `features/company/org-chart-page.tsx` (the card menu's own "离任" row) already+ * stayed open on a refusal, but its reason fell into a toast that dismissed itself after a few+ * seconds and sat over the card rather than in it. It now closes only once its leave landed; a+ * refusal leaves the card standing with the reason drawn under its sentence (`ConfirmModal`'s+ * `refusal` slot), so the retry is the button that was pressed and cancelling decides nothing.+ *+ * The organization, its CEO and the departing employee are made through the API rather than+ * through the dialogs: this spec is about the confirmation, not about hiring. Company mode is off+ * on a fresh server, so the test turns the admin master switch on first (idempotent), and the+ * Project gets the mock as its model so the onboarding overlay stays off the page.+ */+import { test, expect, request } from "@playwright/test";+import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const P = "password123";+const ORG = "orgleaverefuse";+const MISSION = "把插件市场上线,做到搜索前三。";+/** The employee the flow lets go; the CEO is the one the server never lets leave. */+const DEV = { agentId: `${ORG}_dev`, name: "Dana Dev" };++/** The refusal the page paints; a 500 with its own words proves those words came back. */+const REFUSAL = { code: "org_chart_locked", message: "the org chart is mid-rewrite" };++/** The admin master switch, off by default: turned on server-wide before the flow starts. */+async function enableCompanyMode() {+ const adminCtx = await request.newContext();+ try {+ await login(adminCtx, ADMIN_ID, ADMIN_PASSWORD);+ const res = await adminCtx.put(`${BASE}/api/admin/settings`, { data: { companyMode: true } });+ if (!res.ok()) {+ throw new Error(`enable company mode failed: ${res.status()} ${await res.text()}`);+ }+ } finally {+ await adminCtx.dispose();+ }+}++/**+ * A fresh user with mock-model credentials, an organization whose CEO the server makes on+ * creation, and one subordinate hired straight through the API.+ */+async function setUp(page, tag) {+ await enableCompanyMode();+ const user = `${tag}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`;+ await provisionAndLogin(page.request, user, P);+ const project = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0];+ const projectId = project.projectId;+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(put.ok(), `put models ${projectId}`).toBeTruthy();++ const orgBase = `${BASE}/api/projects/${projectId}/organizations`;+ const created = await page.request.post(orgBase, { data: { orgId: ORG, mission: MISSION } });+ expect(created.ok(), "create organization").toBeTruthy();+ const hired = await page.request.post(`${orgBase}/${ORG}/employees`, {+ data: {+ newAgent: { agentId: DEV.agentId, name: DEV.name },+ title: "站点工程师",+ reportsTo: `${ORG}_ceo`,+ },+ });+ expect(hired.ok(), "hire the employee").toBeTruthy();++ /**+ * The chart as the server holds it: read from the API rather than the page, so "nothing was+ * written" is a fact about the chart file.+ */+ const chart = async () => {+ const res = await page.request.get(`${orgBase}/${ORG}/chart`);+ expect(res.ok(), "read the chart").toBeTruthy();+ return await res.json();+ };+ return { projectId, chart };+}++/** Open the org chart, then the departing employee's own card menu → "离任". */+async function openLeaveCard(page, projectId) {+ await page.goto(`/org/${projectId}/${ORG}/chart`);+ await page.getByRole("button", { name: `${DEV.name} · 员工操作` }).click();+ await page.getByRole("menuitem", { name: "离任" }).click();+ const card = page.getByRole("dialog", { name: "离任", exact: true });+ await expect(card).toBeVisible();+ return card;+}++/**+ * The card's own text with the refusal line dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal may change.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}++test("a refused leave keeps the card, its sentence and the chart", async ({ page }) => {+ const { projectId, chart } = await setUp(page, "r127leave");+ const stillThere = async () => (await chart()).employees.some((e) => e.agentId === DEV.agentId);+ expect(await stillThere()).toBe(true);++ const card = await openLeaveCard(page, projectId);+ const sentence = await cardText(card);+ expect(sentence).toContain(`让 ${DEV.name} 离任`);++ const deletes = [];+ await page.route(+ `**/api/projects/${projectId}/organizations/${ORG}/employees/**`,+ async (route) => {+ if (route.request().method() !== "DELETE") return route.fallback();+ deletes.push(route.request().url());+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ },+ );++ await card.getByRole("button", { name: "确认", exact: true }).click();++ // The reason is in the card that asked, and it is not a toast: the notification region (which+ // may still hold the company beta's own notice) never carries the server's words, and the card+ // reads exactly as before plus the one line.+ await expect(card.getByText(REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);+ expect(deletes).toHaveLength(1);+ await expect(card).toBeVisible();+ expect(await cardText(card)).toBe(sentence);++ // Nothing was written: the employee is still on the chart.+ expect(await stillThere()).toBe(true);++ // Closing the card decides nothing, and reopening it does not carry the old reason.+ await card.getByRole("button", { name: "取消" }).click();+ await expect(card).toHaveCount(0);+ const again = await openLeaveCard(page, projectId);+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);+ expect(await again.innerText()).toBe(sentence);++ // The retry lands: the card goes and the employee is off the chart.+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}/employees/**`);+ await again.getByRole("button", { name: "确认", exact: true }).click();+ await expect(again).toHaveCount(0);+ await expect.poll(async () => (await chart()).employees.length).toBe(1);+ await expect(page.getByRole("button", { name: `${DEV.name} · 员工操作` })).toHaveCount(0);+});diff --git a/packages/web/src/features/company/org-chart-page.tsx b/packages/web/src/features/company/org-chart-page.tsxindex 7d7819f4..715f6680 100644--- a/packages/web/src/features/company/org-chart-page.tsx+++ b/packages/web/src/features/company/org-chart-page.tsx@@ -4,7 +4,9 @@* one menu and no other action: it opens the desk session, and holds the personnel actions* below that — hire a subordinate, set budget, change the reporting line, renew the desk (a* fresh desk session, and the workspace it runs in), leave. Every one of the personnel actions- * confirms before it writes the chart file. The card owns when that menu is open (three+ * confirms before it writes the chart file, and a confirmation that is refused keeps its card+ * standing with the server's words inside it (the leave card's own `refusal`), where the button+ * that retries them is. The card owns when that menu is open (three* gestures reach it — see chart-card.tsx); this page only supplies the rows, against the* panel's own close, and bumps `viewEpoch` whenever the canvas moves the cards out from under* an open one.@@ -129,6 +131,8 @@ export function OrgChartPage() {);const [renewFor, setRenewFor] = useState<OrgEmployeeItem | null>(null);const [leaveFor, setLeaveFor] = useState<OrgEmployeeItem | null>(null);+ /** The server's own words for a refused leave, drawn in the card that asked, next to its retry. */+ const [leaveRefusal, setLeaveRefusal] = useState<string | null>(null);const [busy, setBusy] = useState(false);/** The view the reader moved to; null follows the fit, which is what the chart opens at. */const [view, setView] = useState<CanvasView | null>(null);@@ -320,16 +324,19 @@ export function OrgChartPage() {};const runLeave = async () => {- if (leaveFor === null) return;+ if (leaveFor === null || busy) return;setBusy(true);try {await api.leaveOrganization(projectId, orgId, leaveFor.agentId);- toastSuccess(S.company.chart.left(leaveFor.name));+ // The card goes with its own leave landing, never before: a refusal has to stay readable+ // next to the button that retries it.setLeaveFor(null);+ setLeaveRefusal(null);+ toastSuccess(S.company.chart.left(leaveFor.name));void load();void company.reloadOrganizations();} catch (e) {- toastError(apiErrorText(e));+ setLeaveRefusal(apiErrorText(e));} finally {setBusy(false);}@@ -397,7 +404,17 @@ export function OrgChartPage() {{S.company.chart.ceoCannotLeave}</span>) : (- menuRow(close, MENU_ICONS.leave, S.company.chart.leave, () => setLeaveFor(employee), true)+ menuRow(+ close,+ MENU_ICONS.leave,+ S.company.chart.leave,+ () => {+ // A new question, not the last one: the previous refusal is not its answer.+ setLeaveRefusal(null);+ setLeaveFor(employee);+ },+ true,+ ))}</Menu>);@@ -596,6 +613,7 @@ export function OrgChartPage() {busy={busy}onClose={() => (busy ? undefined : setLeaveFor(null))}onConfirm={() => void runLeave()}+ refusal={leaveRefusal === null ? undefined : S.common.refused(leaveRefusal)}><p className="text-sm text-gray-600 dark:text-gray-300">{leaveFor === null ? "" : S.company.chart.leaveConfirm(leaveFor.name)}