Repository navigation
Commit 56cac5e
feat(ui): undo a business-record delete from its toast through the recycle bin (#31795)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbPnyAMycuSU2XHXgpgorGJU)_
Part of #30239
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:删除一条业务对象记录后,“已删除”提示多了一个「撤销」按钮(控制台列表、插件列表、记录页三处)。撤销走回收站恢复接口 `POST
{data}/:object/recycle-bin/:entryId/restore`,按原 id
恢复,不会重新创建记录;恢复被拒时按原因给出七句之一(唯一值被占、父记录已彻底删除、包已卸载、父记录也在回收站、条目不存在、无权限、本部署没有回收站)。业务对象的删除确认改成只问“确定要删除这条记录吗?”,不再说“此操作无法撤销”;平台对象(`sys_`、`cloud_`、`ai_`)保持原文。
- 为什么改:ADR-0148 之后业务对象删除会进回收站,但控制台既拿不到
`recycleBinEntryId`(适配器丢了它),确认框还在说“无法撤销”,这和服务端的实际行为不一致。
- 风险与回滚:撤销按钮只在同时满足两点时出现:服务端返回了条目 id,并且调用者在该对象上有
`allowRestoreOwnDeleted`(经 `objectPermissionGrants`
读取,`manageRecycleBin`、`modifyAllRecords`
也算)。缺任一项时提示与今天逐字相同;批量删除的提示不变。`DataSource` 只做加法(`delete` 仍返回
boolean)。回滚即撤销本 PR。
- 先看:`ui/packages/core/src/actions/recordDelete.ts` 的 `successToast` 和
`undo`,再看 `core/src/actions/recycleBinRestore.ts`(拒绝码到语言包键的映射)和
`app-shell/src/utils/recycleBinRestore.ts`(权限判断)。
- 两分钟验证:在 `ui/` 下跑 `pnpm exec vitest run
packages/app-shell/src/hooks/__tests__/useObjectActions.deleteDialog-11695.test.tsx
-t 30239`,预期 8 个用例全绿(en、zh 各四个:往返、拒绝原因、无权限对照、无条目对照)。
- 需要你做的:无,席位落地。管理端回收站页面在第二个 PR(`Fixes #30239`),它复用本 PR 的拒绝原因映射。
## What changes
- **(A) `@object-ui/types` `DataSource`**, additive only:
`delete(resource, id, opts?)` options gain `onRecycleBinEntry?:
(entryId: string) => void`, and `DataSource` gains an optional
`restoreRecycleBinEntry?(resource, entryId)`. `delete` still resolves to
a boolean.
- **(A) `@object-ui/data-objectstack`**: `delete` calls
`onRecycleBinEntry` with the server's `recycleBinEntryId`, after the
delete's mutation event, only when the delete succeeded and the answer
carries a non-empty id. `restoreRecycleBinEntry` is the SDK's
`recycleBin.restore`. It emits no mutation event (the vocabulary has no
restore, and a restore is never a create), and a refusal is normalised
as every write's is, so a 409 `RESTORE_*` keeps its `code` and `details`
and is not a `ConcurrentUpdateError`.
- **`@object-ui/core`**:
- New `recycleBinRestoreRefusalText(t, error, labels)` with
`RECYCLE_BIN_RESTORE_REFUSAL_KEYS`. It maps the door's seven codes (the
spec's four `RECYCLE_BIN_RESTORE_REFUSAL_CODES` plus `RECORD_NOT_FOUND`,
`PERMISSION_DENIED`, `NOT_IMPLEMENTED`) to one `recycleBin.refusal.*`
sentence each, naming objects and fields by label with the machine name
as fallback. An unknown code answers `undefined`, so the caller keeps
its generic copy. The admin page in PR 2 reuses it.
- `recordDelete`: the host passes an optional `restore` (and
`refusalLabels`). With both an entry id and `restore`, the success toast
carries an `actions.undo` action. Undo restores, refreshes, and toasts
`restoredNamed` / `restoreSuccess`; a refusal toasts `restoreFailed`
with the refusal sentence, or the server message for an unknown code.
With neither, `toast.success(message)` is called with exactly one
argument, as today. The entry id is asked for only when `restore` is
present, so a host without it calls `delete(object, id)` exactly as
before.
- `recordDelete.entersRecycleBin(name)` is the engine's own predicate
(`!hasPlatformObjectPrefix`). It picks the confirm copy:
`objectActions.deleteConfirmQuestion` and
`console.objectView.bulkDeleteQuestion` for a business object, today's
keys for a platform object.
- **The hosts decide the grant; core reads no permission.**
- `app-shell` `useObjectActions` (console list) and `RecordDetailView`
(record page) build `restore` through the new
`utils/recycleBinRestore.ts`. That util reads
`usePermissions().effectiveObjects` as `MePermissionsProvider` does
(lowercase key, the key as given, then `'*'`) and folds it with
`objectPermissionGrants(…, 'allowRestoreOwnDeleted')`. On the record
page, a successful Undo also navigates back to the record.
- `plugin-view` `ObjectView` (the plugin list) does the same with a
local reader, since it cannot import app-shell, and its fallback
dictionary gains the new English keys.
- `plugin-detail` `DetailView`: the confirm reads
`detail.deleteConfirmQuestion` for a business object, per the amendment.
Platform objects and a declared `schema.deleteConfirmation` are
unchanged.
- **`@object-ui/i18n`**, every pack:
`objectActions.deleteConfirmQuestion`, `restoredNamed`,
`restoreSuccess`, `restoreFailed`; `detail.deleteConfirmQuestion`; the
`console.objectView.bulkDeleteQuestion` count family; and
`recycleBin.refusal.{uniqueValueTaken, parentPurged, packageUninstalled,
parentInRecycleBin, notFound, permissionDenied, notAvailable}`. zh-Hant
is generated with `gen:zh-hant`. Each question is the platform sentence
minus its permanence sentence.
- Changeset: `.changeset/30239-recycle-bin-undo-toast.md` (seven
`@object-ui/*` packages, patch).
## Tests
New:
- `core/src/actions/__tests__/recycleBinRestore.test.ts`: the key map
covers the spec's `RECYCLE_BIN_RESTORE_REFUSAL_CODES`; an `it.each` over
the seven codes checks the exact key and placeholders; the field label
falls back to the machine name; CONTROL: an unknown code and a codeless
error answer `undefined`.
- `core/src/actions/__tests__/recordDelete.test.ts`, new describe
"recordDelete and the recycle bin": business vs platform confirm copy; a
round trip where Undo restores once with `(object, entryId)`, never
calls `create`, refreshes and names the record; a refusal toasts its
sentence, not the server message; CONTROLs for an unknown code, no entry
id, no `restore`, and a batch.
- `i18n/src/__tests__/recycle-bin-delete-copy-30239.test.ts`: in every
pack, each question equals its platform sentence minus the permanence
sentence, the seven refusal sentences are distinct, none equals the
generic failure, and each carries en's placeholders; the restore toasts'
placeholders; exact en and zh-Hans sentences.
-
`app-shell/src/hooks/__tests__/useObjectActions.deleteDialog-11695.test.tsx`,
new `describe.each` en/zh "console list Delete undo", through the real
`MePermissionsProvider`: round trip; a refusal in the session language;
CONTROL with no grant (`delete` called with two arguments and a
one-argument toast); CONTROL with no entry id.
- `app-shell/src/utils/__tests__/recycleBinRestore-30239.test.ts`: the
grant fold (`allowRestoreOwnDeleted`, `manageRecycleBin`, `'*'`
`modifyAllRecords`, case), plus CONTROLs: no read, no row, permissions
not loaded, no restore on the data source.
- `data-objectstack/src/recycleBinEntry-30239.test.ts`: the entry id is
reported after the mutation event; no report without an id or for an
unconfirmed delete; restore calls `recycleBin.restore` with no create
and no event; a 409 refusal keeps `code` and `details`.
Edited pins. Each asserted the permanence sentence or key on a business
object, which this card retires; nothing else in them changes and no
assertion is removed:
- `app-shell/src/hooks/__tests__/useObjectActions.test.tsx`:
`objectActions.deleteConfirm` → `objectActions.deleteConfirmQuestion`,
and `console.objectView.bulkDeleteConfirm` →
`console.objectView.bulkDeleteQuestion` (crm_product).
-
`app-shell/src/hooks/__tests__/useObjectActions.deleteCascade-28472.test.tsx`:
`EN/ZH.objectActions.deleteConfirm` → `deleteConfirmQuestion`, and
`bulkDeleteConfirm_other` → `bulkDeleteQuestion_other`, as the base the
cascade line is appended to.
- `app-shell/src/views/RecordDetailView.deleteCascade-28472.test.tsx`:
`EN.objectActions.deleteConfirm` → `deleteConfirmQuestion`, the same
base.
-
`app-shell/src/views/RecordDetailView.deleteConfirmDialog-11001.test.tsx`:
the body is found by `deleteConfirmQuestion` (en and zh). The #27823
assertion "the body contains `This cannot be undone.`" becomes "the
dialog does not contain it" for this business record (crm_call). The
platform-object side is still pinned, unedited, in
`i18n/src/__tests__/record-delete-permanent-27823.test.ts`.
- `plugin-view/src/__tests__/ObjectView.gridDelete-10383.test.tsx`: the
two literal sentences lose ` This cannot be undone.`, and the docblock
bullet says why.
- `core/src/actions/__tests__/recordDelete.test.ts` (confirmCopy) and
`recordDelete.cascade-28472.test.ts`: the business-object cases expect
the Question keys.
- `i18n/src/__tests__/record-delete-permanent-27823.test.ts`: docblock
only, saying the sentence is now the platform keys'.
## Acceptance notes
- Before the delete, the console cannot know whether the server will
write a recycle-bin entry, so the confirm promises neither permanence
nor recovery. The toast tells the truth afterwards.
- A batch delete keeps today's toast, as the amendment confirmed: each
record writes its own entry, and one toast action would have to restore
N entries, any of which can be refused on its own. The admin page in PR
2 is where several entries are restored.
- `member_default` holds neither `allowRestoreOwnDeleted` nor
`manageRecycleBin`, so a default member sees no Undo until an admin
grants it. The restore door would refuse them anyway, and the toast
never offers an action the runtime refuses.
- Out of this PR: the admin recycle-bin page and its Setup nav item (PR
2), per-entry purge and "restore the parent first" (out of v1).
## Verification
Head `e6d5861b`. Branch cut from `c2bb879f`, with origin/main merged at
`e253f3ab` (five incoming commits; none touches this diff's files, and
no parallel fix was found).
<details><summary>Tests (ui vitest from ui/, under the verify
lock)</summary>
- core and i18n, 8 files: `Tests 155 passed (155)`.
- app-shell, plugin-view and plugin-detail delete files
(`useObjectActions.deleteDialog-11695`, `useObjectActions`,
`useObjectActions.deleteCascade-28472`,
`RecordDetailView.deleteConfirmDialog-11001`,
`RecordDetailView.deleteCascade-28472`, `ObjectView.gridDelete-10383`,
`DetailView`, `DetailView.permissions`): `Test Files 8 passed (8)`,
`Tests 78 passed (78)`.
- `recycleBinRestore-30239`, `recycleBinEntry-30239`, `onMutation`,
`bulkDelete`: all passed (52 tests).
- `pnpm exec turbo run type-check` on types, core, data-objectstack,
app-shell, plugin-view, plugin-detail and i18n: `Tasks: 75 successful,
75 total`.
</details>
<details><summary>Ablation (scripts/ablation-replace.mjs, anchor x1 ->
x0, restored blob == HEAD 1283125 and git diff HEAD
empty)</summary>
The undo attach line in `recordDelete.ts`, `if (!entryId || !restore)
{`, replaced by `if (true) {`, so no toast ever carries Undo.
`recordDelete.test.ts` with
`useObjectActions.deleteDialog-11695.test.tsx`: `Tests 7 failed | 29
passed (36)`. The 7 are the core round trip, the refusal and
unknown-code cases, and the app-shell round trip and refusal in en and
zh. The no-grant and no-entry CONTROLs stay green, as they should. The
core module is imported from `src`, so there is no dist leg.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 40 derived commands, each run at `e6d5861b`
with exit 0 (`check:type-check-debt` under the verify lock,
`check:query-options-erasure` alone). `--ran` reconciliation: `40
derived, 40 run, 0 NOT-MEASURED, 0 UNRUN`. `--tier`: no path-derived
mandate. `check-governed-merges --branch`: 0 of 36 paths hit the
register, not governed. Examples census (`git grep` of the touched copy,
keys and members in `ui/examples/**` and `ui/e2e/**`): no hit that reads
the changed copy. `eslint` on the touched sources and new tests: 0
errors. Changed lines 1432 (+1369 / -63): implementation about 420,
tests about 690, locale packs about 235. The body gates
(`check-changeset-no-major`, `check-adr-0087-registration`,
`check-closing-keyword-parity`, `check-partof-closing-keyword`) were run
on this body.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jR7jBcj3r4Rii4HA82)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jR7jBcj3r4Rii4HA82
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent cbc05db commit 56cac5e
37 files changed
Lines changed: 1378 additions & 66 deletions
File tree
- .changeset
- ui/packages
- app-shell/src
- hooks
- __tests__
- utils
- __tests__
- views
- core/src/actions
- __tests__
- data-objectstack/src
- i18n/src
- __tests__
- locales
- plugin-detail/src
- plugin-view/src
- __tests__
- types/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
| |||
139 | 147 | | |
140 | 148 | | |
141 | 149 | | |
142 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
143 | 154 | | |
144 | 155 | | |
145 | 156 | | |
| |||
177 | 188 | | |
178 | 189 | | |
179 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
144 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
145 | 160 | | |
146 | 161 | | |
147 | 162 | | |
| |||
160 | 175 | | |
161 | 176 | | |
162 | 177 | | |
163 | | - | |
| 178 | + | |
164 | 179 | | |
165 | 180 | | |
166 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments