Repository navigation
Commit affba40
fix(app-shell): metadata history Back to item opens the item under every route nesting (#29316)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbKeKvZtRKpgpNfnuuBoDndk)_
Fixes #28626
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:元数据条目历史页的「Back to item」不再按匹配到的路由回退,改为从当前 URL
去掉最后一段(`history`)并保留查询串,因此回到 `…/metadata/TYPE/NAME`。
- **为什么改**:原写法 `../NAME`
相对路由解析,会丢掉整条路由:有应用时落到以条目名命名的类型列表,无应用时落到应用根下的路径,并且丢掉 `?package=` /
`?scope=environment`。目前在线上只有 Setup 的数据源历史页还会走到这条链接。
- **风险与回滚**:只改一个按钮的跳转目标;Studio「All metadata」区域的链接分支没动。回滚即还原
`ResourceHistoryPage.tsx` 一处。
-
**先看**:`ui/packages/app-shell/src/views/item-tools/ResourceHistoryPage.tsx`
的 `goBackToItem`;新测试 `ResourceHistoryPage.backToItem-28626.test.tsx`。
- **两分钟验证**:`pnpm --dir ui exec vitest run
packages/app-shell/src/views/item-tools/ResourceHistoryPage.backToItem-28626.test.tsx`,预期
6/6 通过。
- **需要你做的**:无,席位落地。
## What changes
`MetadataResourceHistoryPage` built its non-area **Back to item** link
as `navigate('../NAME')`. React Router resolves that `..` against the
matched route, not the URL, so it drops the whole matched route:
- with an active app (`/apps/:appName/*` → `metadata` →
`:type/:name/history`) it landed on `/apps/setup/metadata/NAME`, the
`:type` route, which Setup then sends to Studio's list of a type named
after the item;
- with no app (`/apps/:appName/*` → `metadata/:type/:name/history`) it
landed on `/apps/setup/NAME`;
- under the exported `MetadataResourceRouter` (`component/:ns/:name/*`,
type in `?type=`) it landed on `/apps/APP/NAME`;
- the query (`?package=`, `?scope=environment`, `?type=`) was dropped
every time.
The non-area branch now cuts the URL's own last segment as it is spelled
and keeps the query: `navigate({ pathname:
pathname.replace(LAST_SEGMENT, ''), search })`, where the pattern is a
slash, one or more non-slash characters and an optional trailing slash
at the end of the path. A relative `navigate({ pathname: '..', search },
{ relative: 'path' })` was tried first and dropped: the router resolves
it against the decoded match pathname, so an encoded name came back
decoded (`sales%20db` → `sales db`). The encoded-name test row pins
that.
The Studio "All metadata" area branch (built from `areaHost.basePath`)
is unchanged and is the test's control row.
**Reach today.** Since #28818 every Setup metadata route except the
datasource's redirects to Studio's area, so in the Console only the
datasource history page (with and without an active app) still reaches
this link. The exported router is not mounted by the Console
(`component/metadata/resource/*` is caught by `LegacyMetadataRedirect`),
but a host can mount it, and the fix covers it too.
## Tests
New
`ui/packages/app-shell/src/views/item-tools/ResourceHistoryPage.backToItem-28626.test.tsx`:
the real page and React Router, the metadata client stubbed. Six rows:
both `AppContent` nestings, the query kept under both, an encoded name
kept encoded, the exported router's splat with `?type=`, and the Studio
area as control.
- Fix head `da4f9be7`: 6 passed.
- Red on the current line: the same file against `origin/main`'s page
(`8a8a03d3`, restored from base, then restored to `HEAD` and proven by
hash and an empty `git diff HEAD`): 5 failed, 1 passed (the Studio
control). The relative-`..` variant (`6108d08c`) was 5 passed, 1 failed
(encoded name).
## Acceptance notes
- Only the datasource history page reaches this link live in the Console
today, as measured above.
- Datasource names are `^[a-z_][a-z0-9_]*$` in the spec, so the decoded
spelling never bites the live datasource page; the encoded-name row
guards the exported router with other names.
## Verification
All on head `da4f9be7`.
<details><summary>Tests and type-check</summary>
- `pnpm --dir ui exec vitest run
packages/app-shell/src/views/item-tools/ResourceHistoryPage.backToItem-28626.test.tsx`:
Tests 6 passed (6).
- Reverse leg, `origin/main`'s page restored into the tree: Tests 5
failed, 1 passed (6); restored to `HEAD`, hash matched, `git diff HEAD`
empty.
- Every ui test file that names the page (`git grep -l` on
`ResourceHistoryPage` / `MetadataResourceHistoryPage`, 21 files across
app-shell and the console): Test Files 21 passed (21), Tests 306 passed
(306). CI's Test UI runs the rest.
- `pnpm exec turbo run type-check --filter=@object-ui/app-shell`: Tasks
65 successful, 65 total.
- `pnpm --dir ui exec vitest run scripts/`: Test Files 169 passed, 2
skipped (171).
</details>
<details><summary>Derived gates</summary>
- `node scripts/pm/dispatch-gates.mjs --ran`: 34 derived families, 34
run, 0 NOT-MEASURED; every one exit 0, `check-sdui-manifest` included
(no registry change).
- `PR_BODY=... node scripts/check-partof-closing-keyword.mjs`: exit 0.
- `pnpm --dir ui check:new-line-citations`: 0 new citations, exit 0.
- Full dogfood battery: n/a (no `!` in the title, no narrowing arm).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QsR2jSipqJ9BXYCu6y2jgs)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ba1f164 commit affba40
3 files changed
Lines changed: 183 additions & 5 deletions
File tree
- .changeset
- ui/packages/app-shell/src/views/item-tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 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 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
| |||
110 | 116 | | |
111 | 117 | | |
112 | 118 | | |
113 | | - | |
| 119 | + | |
114 | 120 | | |
115 | 121 | | |
116 | 122 | | |
| |||
0 commit comments