A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 换工位被拒时,原因留在弹窗里,不再只活六秒
lmliheng43d6b5e0f346
diff --git a/changelog/unreleased/2026-11-04-desk-renew-refusal.md b/changelog/unreleased/2026-11-04-desk-renew-refusal.mdnew file mode 100644index 00000000..4c30e314--- /dev/null+++ b/changelog/unreleased/2026-11-04-desk-renew-refusal.md@@ -0,0 +1,46 @@+# A refused desk renewal says why in its dialog, not in a six-second toast++- **Date:** 2026-11-04+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-04-desk-renew-refusal.zh.md)++"New desk session" on the org chart is a dialog that is its own confirmation: a changed workspace is+written to the employee tree first and a fresh desk session opened afterwards, and an untouched one is+just the session. The first write has always answered where it was asked — an invalid workspace lands+under the field, because the box is what has to change. When the **second** write was the one refused,+the dialog stayed open with the field as it was, and the reason went to a notification: six seconds+later it was gone, leaving a dialog that read exactly as it did before the press, with the same button+to retry it.++That sentence is now drawn in the dialog, above the workspace field (`role="alert"`, danger colour,+`NoticeStrip`'s danger tone — the same shape as the "mark blocked" form in the ticket dialog). Above+the field rather than under it because the renewal, not the path in the box, is what was refused: the+reader still sees which path they tried, and the sentence does not take the field's own error slot,+where "invalid workspace: …" belongs. It belongs to the attempt that produced it — the next press+clears it before it sends, and reopening the dialog carries no old answer.++## Details++- `packages/web/src/features/company/employee-dialogs.tsx`: `DeskRenewDialog` gains a `refusal` state —+ `confirm()` clears it before the request and sets it when the desk-session write fails (it used to+ raise `toastError`); the open effect clears it too. It draws one `S.common.refused(reason)`, the+ app-wide refusal slot's wording (7.19: a request that never reached the route reads its error code's+ localized sentence).+- The header comment now records why the sentence lives in the dialog and why it stays out of the+ field's `error` slot.++## Tests++- One more case in `packages/web/e2e/employee-refusal.spec.mjs` (real server, real browser): the+ renewal's `POST` is stubbed to 500 at `page.route`. The refusal keeps the dialog, draws the reason+ inside it and puts nothing in the notification region; **seven seconds later** (past the six an error+ notification lives) it is still there; cancelling and reopening carries no old answer; once allowed+ the dialog closes and the page follows the new desk session to its chat.++## Compatibility++No interface change, no new dependency, no Project config change, no new strings —+`S.common.refused` already existed and keeps its exact wording.diff --git a/changelog/unreleased/2026-11-04-desk-renew-refusal.zh.md b/changelog/unreleased/2026-11-04-desk-renew-refusal.zh.mdnew file mode 100644index 00000000..5c6ac9e5--- /dev/null+++ b/changelog/unreleased/2026-11-04-desk-renew-refusal.zh.md@@ -0,0 +1,37 @@+# 换工位被拒时,原因留在弹窗里,不再只活六秒++- **日期:** 2026-11-04+- **类型:** fix+- **范围:** `web`+- **破坏性:** 否++[English](2026-11-04-desk-renew-refusal.md)++组织图里的「换工位」是一个自己就是确认的弹窗:改过工作区就先写员工树,再开一个新的工位会话;不改就只是+换一个工位会话。第一笔写入被拒时,理由早就落在工作区字段下面 —— 要改的正是那个框。被拒的是**第二笔**时+弹窗照旧开着、字段照旧留着,但理由只落进一条通知:六秒后它自己消失,屏上留下一张与按键前一模一样的弹窗,+而重试就是同一颗按钮。++那句话现在画在弹窗里、工作区字段的上面(`role="alert"`、危险色、`NoticeStrip` 的危险色调,与工单弹窗里+「标记阻塞」那张表单同一写法)。放在字段上面而不是下面,是因为被拒的是**换工位**这件事、不是框里的那条+路径:读者仍看得见自己拿哪条路径试的,那句原因也不去抢字段自己的错误位 —— 工作区不合法时那里念的是+「工作区无效:…」,两件事各有各的位置。它属于产生它的那一次尝试:下一次按键在发请求之前先清掉它,重新+打开弹窗也不带旧答案。++## 明细++- `packages/web/src/features/company/employee-dialogs.tsx`:`DeskRenewDialog` 多一个 `refusal` 状态 ——+ `confirm()` 在发请求之前清掉它,开新工位会话那一笔失败时写上(原来走 `toastError`);打开弹窗的那条+ 效果也清一次。画的是一句 `S.common.refused(reason)`,与全应用拒绝位的措辞一致(7.19:请求没到服务端时+ 念错误码自己的本地化句子)。+- 头注释补上这一段:为什么这句留在弹窗里、为什么它不去占字段的 `error` 槽。++## 测试++- `packages/web/e2e/employee-refusal.spec.mjs` 新增一条用例(真服务端 + 真浏览器):换工位那一笔 `POST`+ 在 `page.route` 上桩成 500。被拒之后弹窗留着、原因画在弹窗里、通知区里没有这句话;**7 秒后**(超过错误+ 通知活着的 6 秒)它仍在;取消并重新打开不带旧答案;放行后弹窗关闭、页面按新的工位会话跳到对话页。++## 兼容性++不碰接口、不引入新依赖、不改 Project 配置、无新文案 —— `S.common.refused` 原本就在,措辞一字未改。diff --git a/packages/web/e2e/employee-refusal.spec.mjs b/packages/web/e2e/employee-refusal.spec.mjsindex 803574b0..b87fe91e 100644--- a/packages/web/e2e/employee-refusal.spec.mjs+++ b/packages/web/e2e/employee-refusal.spec.mjs@@ -1,19 +1,25 @@/**- * Regression: hiring a subordinate and editing one of an employee's single fields (here its- * budget) are asked in a confirmation card, and a refused write keeps that question — with the- * server's words inside it — instead of leaving only a toast behind.+ * Regression: hiring a subordinate, editing one of an employee's single fields (here its budget),+ * and renewing an employee's desk all answer a refused write where it was asked — with the+ * server's words inside the card or the dialog — instead of leaving only a toast behind.*- * Both cards in `features/company/employee-dialogs.tsx` used to close themselves in the `catch`- * of their own write, so a refusal left the chart file untouched (nothing was written) while the- * reason fell into a toast that dismissed itself after a few seconds and sat over a card that was- * already gone. They now close only once their write 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 two confirmation cards in `features/company/employee-dialogs.tsx` used to close themselves+ * in the `catch` of their own write, so a refusal left the chart file untouched (nothing was+ * written) while the reason fell into a toast that dismissed itself after a few seconds and sat+ * over a card that was already gone. They now close only once their write 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 employee edited in the second test are made through the API- * rather than through the dialogs: this spec is about the two confirmations, not about creation.- * Company mode is off on a fresh server, so each 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 desk renewal is its own dialog rather than a confirmation, and its second write (the desk+ * session, after the workspace patch has already landed) had the same shape: the dialog stayed+ * open, so the reason in a toast had a question on screen to answer and nothing to answer it+ * with. That reason now sits above the field, because the renewal — not the box — is what was+ * refused.+ *+ * The organization, its CEO and the employees are made through the API rather than through the+ * dialogs: this spec is about the writes' refusals, not about creation. Company mode is off on a+ * fresh server, so each test turns the admin master switch on first (idempotent), and the Project+ * gets the mock as its model so the onboarding overlay stays off.*/import { test, expect, request } from "@playwright/test";import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";@@ -244,3 +250,71 @@ test("a refused budget edit keeps the card, its sentence and the stored budget",await expect(page.getByRole("dialog", { name: "设置 Dana Dev 的预算" })).toHaveCount(0);await expect.poll(async () => Math.round((await budgetOf()) * 7)).toBe(60);});++test("a refused desk renewal keeps the dialog and the reason, past the toast's six seconds", async ({+ page,+}) => {+ const { projectId, orgBase } = await setUp(page, "r194renew");+ const hired = await page.request.post(`${orgBase}/${ORG}/employees`, {+ data: {+ newAgent: { agentId: `${ORG}_dev`, name: "Dana Dev" },+ title: "站点工程师",+ reportsTo: `${ORG}_ceo`,+ },+ });+ expect(hired.ok(), "hire the employee").toBeTruthy();++ await openChart(page, projectId);+ await page.getByRole("button", { name: "Dana Dev · 员工操作" }).click();+ await page.getByRole("menuitem", { name: "换工位" }).click();+ const dialog = page.getByRole("dialog", { name: "为 Dana Dev 换工位" });+ await expect(dialog).toBeVisible();+ // What it will do stays on screen; the spec is prefilled with the current one, so confirming+ // without touching it renews the desk and writes no chart.+ await expect(dialog.getByText("换工位会开一个新的工位会话", { exact: false })).toBeVisible();++ const renewals = [];+ await page.route(+ `**/api/projects/${projectId}/organizations/${ORG}/employees/**`,+ async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ renewals.push(route.request().url());+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ },+ );++ await dialog.getByRole("button", { name: "换工位", exact: true }).click();++ // The reason is in the dialog that asked, not in the notification region, and the dialog is+ // still the question it was asking — the retry is the button that was just pressed.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" })).not.toContainText(REFUSAL.message);+ expect(renewals).toHaveLength(1);+ await expect(dialog).toBeVisible();+ expect(await dialog.innerText()).toContain("换工位会开一个新的工位会话");++ // Past the six seconds an error notification lives: the sentence is still there. This is the+ // whole point — a toast would have left the open dialog with a dead button and no reason.+ await page.waitForTimeout(7000);+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();++ // Closing decides nothing, and reopening the dialog does not carry the previous answer.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ await page.getByRole("button", { name: "Dana Dev · 员工操作" }).click();+ await page.getByRole("menuitem", { name: "换工位" }).click();+ const again = page.getByRole("dialog", { name: "为 Dana Dev 换工位" });+ await expect(again).toBeVisible();+ await expect(again.getByText(REFUSAL.message)).toHaveCount(0);++ // The retry lands: the dialog goes and the new desk session is where the page takes the reader.+ await page.unroute(`**/api/projects/${projectId}/organizations/${ORG}/employees/**`);+ await again.getByRole("button", { name: "换工位", exact: true }).click();+ await expect(page.getByRole("dialog", { name: "为 Dana Dev 换工位" })).toHaveCount(0);+ await expect(page).toHaveURL(/\/chat\/[^/]+$/);+ await expect(page.getByText("已换到新的工位会话")).toBeVisible();+});diff --git a/packages/web/src/features/company/employee-dialogs.tsx b/packages/web/src/features/company/employee-dialogs.tsxindex 72f70634..c34c464b 100644--- a/packages/web/src/features/company/employee-dialogs.tsx+++ b/packages/web/src/features/company/employee-dialogs.tsx@@ -26,11 +26,11 @@ import {ICONS,Input,Modal,+ NoticeStrip,RuledSection,Segmented,Select,Textarea,- toastError,toastSuccess,} from "@adelie/ui";import * as api from "../../api/endpoints";@@ -620,6 +620,11 @@ export function EmployeeEditDialog({* spec is written first and its 400 lands under the field, leaving the desk alone. A renewal* that fails after the chart was already rewritten keeps the dialog open and asks the page to* reload, so what is on screen never disagrees with the file.+ *+ * That second write's refusal is drawn in the dialog too, above the field: it is about the+ * renewal rather than about what is in the box, so it does not take the field's own error slot —+ * and the retry is the button that was just pressed, which a toast dismissing itself after a few+ * seconds would leave without its reason over a dialog that is still open.*/export function DeskRenewDialog({open,@@ -642,12 +647,19 @@ export function DeskRenewDialog({}) {const [workspace, setWorkspace] = useState("");const [error, setError] = useState<string | undefined>(undefined);+ /**+ * The server's words for a renewal it refused: drawn in the dialog above the field, since the+ * box is not what has to change. It belongs to the attempt that produced it — a new attempt+ * clears it first, and so does a fresh opening of the dialog.+ */+ const [refusal, setRefusal] = useState<string | null>(null);const [busy, setBusy] = useState(false);useEffect(() => {if (!open) return;setWorkspace(employee.workspace);setError(undefined);+ setRefusal(null);}, [open, employee]);const confirm = async () => {@@ -656,6 +668,8 @@ export function DeskRenewDialog({setError(S.common.requiredField);return;}+ // A new attempt, not the last one: whatever the server said about it is not this one's answer.+ setRefusal(null);setBusy(true);let patched = false;try {@@ -681,7 +695,7 @@ export function DeskRenewDialog({toastSuccess(S.company.chart.renewed);onRenewed(desk.sessionId);} catch (e) {- toastError(apiErrorText(e));+ setRefusal(apiErrorText(e));if (patched) onChartChanged();} finally {setBusy(false);@@ -705,6 +719,13 @@ export function DeskRenewDialog({}><div className="space-y-3">+ {refusal !== null && (+ // Above the field rather than under it: the renewal, not the box, is what was refused,+ // and the reader can still see the spec they tried it with.+ <NoticeStrip tone="danger" role="alert" className="rounded-md border px-2.5 py-2 text-xs">+ <span data-slot="body">{S.common.refused(refusal)}</span>+ </NoticeStrip>+ )}{/* This dialog is its own confirmation, so what it will do stays on screen instead ofhiding behind a "?" the reader would have to open before deciding. */}<p className="text-xs text-gray-500 dark:text-gray-400">