Skip to content

Commit 40914bd

Browse files
feat(console): a 「⋯」 package menu in Studio's top bar; Import on Setup → Packages (#37362)
Fixes #37139 Fixes #37349 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在 Studio 打开一个软件包时,有「管理元数据」权限的人会在顶栏左侧应用名(没有应用时是包名)右边看到「⋯」,里面是编辑软件包信息、导出、复制为新软件包、还原到上次发布、收编散落项、在设置中管理;「设置 > 软件包」页头的「新建」旁边多了「导入」。 - 属于 Studio 重构专题:Studio 首页删掉后,这些整包动作在界面上没有入口,这次补回来;顺带删掉 17 条已经没有页面在用、也从没发布过的界面文案。 - 出错时最多是某一项该灰没灰、或该能点却灰了,真正的操作仍由服务器把关,开发视图不变,可以直接撤回。 - 请确认一件事:「复制为新软件包」在只读的安装包上按开发视图的做法灰掉了(服务器本来就拒绝复制只读包),而菜单表里这一项写的是「—」。 ## What changes **One copy of each whole-package action.** `metadata-admin/packageActions.tsx` (new) holds what the development face's detail sheet used to write inline: the page's `/api/v1/packages` request helper, `revertPackage`, `exportPackageFile`, `adoptLooseItems` (+ `adoptedText`), `EditPackageDialog` (moved; still re-exported from `PackagesPage`), the Adopt confirmation (`AdoptLooseItemsDialog`) and the Duplicate form (`DuplicatePackageForm`). `PackageDetailSheet` now imports them; its testids, texts, requests and answers are unchanged (the existing sheet suites pass as they were). **Studio's 「⋯」 (`studio-design/StudioPackageMenu.tsx`, new).** Drawn by `StudioDesignSurface` into a new `menu` slot of `StudioBackToApp`, right of the app / package name and left of the Studio mark, only when the page has a current package that exists (never `~org` or `~all`) and `useCanAuthorMetadata()` holds. The six items, in the table's order: | Item | Runs | Greyed when | |:--|:--|:--| | Edit package info / 编辑软件包信息 | `EditPackageDialog` on the manifest `/api/v1/packages` lists | read-only package | | Export / 导出 | `exportPackageFile` | never | | Duplicate as a new package / 复制为新软件包 | `DuplicatePackageForm` in a dialog → `duplicatePackage` | read-only package (see Acceptance notes) | | Revert to last publish / 还原到上次发布 | a confirmation, then `revertPackage` | read-only package, or a known pending count of 0 | | Adopt loose items / 收编散落项 | `AdoptLooseItemsDialog`, then `adoptLooseItems` | read-only package | | Manage in Setup… / 在设置中管理… | navigates (through the unsaved-work veto) to `setupPackagePath(id)` | never | A greyed item carries its reason as its `title`. Writability or a pending count Studio has not learned yet greys nothing (the server's gate stays the authority, the same courtesy posture as the rest of Studio). Answers are toasts. After a revert or an adoption the surface bumps its publish nonce (pillars and the pending count re-read) and emits the metadata-refresh pulse; saved package info renames the bar's package name in place. 「发布全部草稿」 is not in the menu. **Setup → Packages (`PackagesPage.tsx`).** Import now sits in the administration face's header beside New Package, the same input and handler as the development face (also in the folded `⋯` on a narrow header). `?package=ID` on that page opens the package's detail sheet once the list has loaded, then drops the param with a replace (the `?new=package` pattern); an id the list does not name opens nothing. `PACKAGES_PACKAGE_PARAM` and `setupPackagePath` live in `packageSource.ts`. This is a page-local query param, not a route. **i18n.** Additive: `engine.studio.packageMenu.{trigger,editInfo,duplicate,revert,manageInSetup,noChanges,duplicateTitle,duplicateDescription,revertTitle,revertDescription}` in studio `en` and `zh`. Export and Adopt reuse the development face's own labels. **Rider #37349 (its own commit, `chore(i18n): remove the studio rows no screen reads`).** Removes 17 rows from studio `en` and `zh`: `engine.studio.menu.typeCount` and `engine.studio.newApp.{title,description,advancedHint,id,help.id,help.name,help.description,help.namespace,help.version,help.type,help.defaultDatasource,help.dependencies,nsDerived,created,exists,failed}`. `ui/scripts/check-i18n-dead-keys.mjs` lists exactly these 17 as confirmed, and a `git grep` outside the catalogue finds no reader. `engine.studio.newApp.nameTaken` and `engine.studio.newApp.appFailed` are still read by `PackageFormDialog` and stay. Released-ness, measured on `npm pack @object-ui/i18n@18.6.0`: its `dist/namespaces/studio/en.js` and `zh.js` carry none of the 17 (only the different `engine.studio.landing.newApp` / `newAppDescription`); control `engine.studio.changes` is present. So this is a plain removal: `Clause-②: no`, no Removed-translation-keys list. ⛔ No server, spec or route change. The development face is not retired. ## Tests - `studio-design/StudioPackageMenu-37139.test.tsx` (new, 26 cases), real `StudioDesignSurface`, metadata client and `MePermissionsProvider` over a fetch stub: - en and zh-CN: the 「⋯」 sits right of the name with the six items in order, labelled; no publish-all item. - en and zh-CN: greyed states — writable with changes greys nothing; a read-only installed package greys Edit, Duplicate, Revert, Adopt with the read-only reason; no pending changes greys Revert alone with its reason. - en and zh-CN: none on `~org`, none on `~all`, none without `manage_metadata` (with a same-page control that has it). - behaviour: Export reads the export door and downloads; Revert's Cancel sends nothing and its confirm sends `POST …/revert`, after which the pending count clears; Adopt confirms then sends `POST …/adopt-orphans` and says 3 moved; Duplicate opens on 「Copy of Sales」 / `ID-copy` and sends the duplicate body; Edit opens the edit dialog on the listed manifest; Manage in Setup… lands on `/apps/setup/component/developer/packages?face=admin&package=ID`. - one copy: both surfaces import the six shared names from `packageActions`, and neither spells the revert or adopt request in place. - `metadata-admin/PackagesPage.installedAppsUpdates-34722.test.tsx` (the admin face's harness): the three assertions that said the admin face has no Import now say it has; new describes pin, in en and zh, Import before New Package in one header group and Import installing the file and re-reading the list (development-face control); and `?package=ID` opening that package's detail (Disable, Delete) and dropping the param, with an unknown id opening nothing. <details><summary>Local runs (head 178bfae; its tree is the f332471b tree the runs read)</summary> ``` # scoped set, after rebasing on 80da086 (#37351 and #37348 included) pnpm --dir ui exec vitest run --maxWorkers=2 PACKAGES_PAGE_SUITES PACKAGE_FORM_DIALOG_SUITES \ EditPackageDialog CreatePackageDialog* StudioDesignSurface* StudioPackageMenu-37139 \ PackageCustomizationsPanel StudioAreaAppOpen-36906 studioAppEdit packages/i18n/ Test Files 223 passed (223) Tests 2862 passed | 13 skipped (2875) os-verify-lock: VERDICT command-exit 0 pnpm --filter @object-ui/app-shell type-check VERDICT command-exit 0 (src + tsconfig.test.json; --listFilesOnly reads both pin files) pnpm check:type-check-debt re-measure OK, 0 raw tsc errors; VERDICT command-exit 0 ``` NARROWED, declared: app-shell's whole package suite (2432 test files) was started and stopped by me after 31 minutes on the shared 4-core box with no file reported; the 223-file set above replaces it locally. CI's `Test UI` runs the whole package. </details> <details><summary>Ablations: each pin group red alone (ablation-replace, anchor x1 -> x0, restored to the HEAD blob, git diff HEAD empty)</summary> The tests import source through the ui vitest aliases, so there is no dist leg. ``` 1 StudioBackToApp: the {menu} slot deleted -t "six items" x en-US, x zh-CN 2 failed 2 menu: readOnly = false -t "read-only installed" x en-US, x zh-CN 2 failed 3 menu: noChanges = false -t "nothing changed" x en-US, x zh-CN 2 failed 4 surface: packageId !== null -> scopeSegment.length > 0 -t "~org" x en-US, x zh-CN 2 failed 5 surface: canAuthorPackage -> true -t "without manage_metadata" x en-US, x zh-CN 2 failed (control passed) 6 PackagesPage: actions back to adminFace ? newPackageButton -t "Import beside New Package" x header en/zh, x import en/zh 4 failed (control passed) 7 PackagesPage: ?package= effect opens nothing -t "one package" x opens-that-package 1 failed ``` Ablations 1 and 4 were first sent with a spelling the tool refused before running anything (an empty replacement; a replacement contained in its own anchor), so those first attempts measured nothing; the rows above are the re-runs with `--delete` and a distinct replacement. </details> <details><summary>Gates</summary> - Derived union (`dispatch-gates.mjs --commands`, the same 39 on the pre-rebase head 975fe6a3 and on 178bfae): `--ran` reconciliation 39 derived, 39 run, 0 NOT-MEASURED, exit 0. - 37 ran on 975fe6a3 (the same two commits before the rebase onto 80da086), all exit 0. - `check:type-check-debt` first answered exit 3 (PREREQUISITE NOT MET: it queued behind my own suite on the lock), then exit 0 under the lock on the rebased tree; `pnpm --dir ui exec vitest run scripts/` exit 0 there (172 files passed). - Push gates on 178bfae's tree: `check:test-source-alias` exit 0, `check:i18n-keys` exit 0, `overlap-check.mjs` VERDICT clean exit 0, `check:new-line-citations` 0 new. - `ui/scripts/check-i18n-dead-keys.mjs` lists the 17 rider rows as confirmed before the rider; the rider grep is empty after it. </details> ## Acceptance notes - **Duplicate is greyed on a read-only package**, though the table's column says 「—」 for it. The server refuses that duplicate (`DUPLICATE_SOURCE_NOT_A_BASE`, `requireDuplicableSource`) and the development face does not offer it there, so 「behave exactly as on the development face」 and the server both point that way. Raised in the report's open questions; flipping it is one line. - **Revert asks first in the menu; the development face's Revert still runs at once.** The table asks for the confirmation; the dispatch keeps the development face unchanged, so the confirmation is the menu's own (new `revertTitle` / `revertDescription` keys). The request is the shared `revertPackage`. - **Carried from #37134's report:** a Studio-only author (holds `manage_metadata`, not Setup → Packages' `setup.access` + `manage_platform_settings`) still has no New Package door. Not in this card's menu table, so not built here. Relatedly, such an author's 「Manage in Setup…」 leads to a page Setup refuses them; the table gives that item no greyed state, so it is drawn as specified. Both are in the report's open questions. - The development face is not retired; per the card, that is asked once this lands. ## Verification Read first: `studio-design/StudioPackageMenu.tsx` (the greyed-state rules and where each answer goes), then `metadata-admin/packageActions.tsx` (the moved code; diff it against the removed lines of `PackagesPage.tsx`), then the `?package=` effect in `PackagesPage.tsx`. Two-minute check: from the repo root, `pnpm --dir ui exec vitest run packages/app-shell/src/views/studio-design/StudioPackageMenu-37139.test.tsx`. Expect 26 passed. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmjeYX4T3tqfUCDu4K)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2e07e61 commit 40914bd

11 files changed

Lines changed: 1381 additions & 251 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): a 「⋯」 package menu in Studio's top bar, and Import on Setup → Packages
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
With the Studio home gone, the whole-package actions of the Packages page's development view had no button anywhere. They are back, in two places:
12+
13+
- **Studio's top bar.** Beside the app or package name at the left end there is now a 「⋯」 menu (zh: 软件包操作) with six items: Edit package info (编辑软件包信息), Export (导出), Duplicate as a new package (复制为新软件包), Revert to last publish (还原到上次发布), Adopt loose items (收编散落项) and Manage in Setup… (在设置中管理…). Each opens the same dialog and sends the same request as the development view's button; the answer appears as a toast. Revert now asks for confirmation first. On a read-only installed package, Edit, Duplicate, Revert and Adopt are greyed with the reason on hover; Revert is also greyed while nothing has changed since the last publish. Manage in Setup… opens Setup → Packages with that package's detail open, where it is enabled, disabled or deleted. The menu is shown only to people who can author metadata (`manage_metadata`), and not in the organization-flows scope or the all-packages view, where no package is open. Publishing every draft is not in the menu: Studio's Changes / Publish already do that.
14+
- **Setup → Packages.** Import now sits in the header beside New Package and works exactly as on the development view. A Setup → Packages address can open one package's detail directly by adding `&package=ID`.
15+
16+
The development view itself is unchanged.
17+
18+
New locale keys in the studio catalogue (en, zh): `engine.studio.packageMenu.trigger`, `.editInfo`, `.duplicate`, `.revert`, `.manageInSetup`, `.noChanges`, `.duplicateTitle`, `.duplicateDescription`, `.revertTitle`, `.revertDescription`.
19+
20+
Seventeen studio-catalogue rows that no screen read any more are removed: `engine.studio.menu.typeCount` and the app-worded `engine.studio.newApp.*` rows (`title`, `description`, `advancedHint`, `id`, `help.*`, `nsDerived`, `created`, `exists`, `failed`). None of them was in a published `@object-ui/i18n` release; `engine.studio.newApp.nameTaken` and `engine.studio.newApp.appFailed` are still used and stay.

‎ui/packages/app-shell/src/views/metadata-admin/PackagesPage.installedAppsUpdates-34722.test.tsx‎

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
* - a module package (`type: 'module'` declaring its app in `dependencies`)
2525
* is folded under that app's line and shown on demand;
2626
* - the columns are Name, Version, Status, Source, Update, and the developer
27-
* doors (Import, the platform switch, the Source chip's Show all) are not
28-
* drawn; New Package is, and lands in Studio (objectstack#36834).
27+
* doors (the platform switch, the Source chip's Show all) are not drawn;
28+
* New Package is, and lands in Studio (objectstack#36834), with Import
29+
* beside it (objectstack#37139; see the last describe of this file).
2930
* On the Studio door all of the developer doors and columns stay, and the
3031
* catalog is never asked.
3132
*
@@ -91,7 +92,7 @@ vi.mock('./PackageFormDialog', () => ({
9192
import { resolveHref } from '@object-ui/layout';
9293
import { PackageDetailSheet, PackagesPage, type InstalledPackageRow } from './PackagesPage';
9394
import { t } from './i18n';
94-
import { SETUP_NEW_PACKAGE_PATH } from './packageSource';
95+
import { SETUP_NEW_PACKAGE_PATH, setupPackagePath } from './packageSource';
9596
// The page's package form reaches the CEL authoring helpers, which load these
9697
// two lazily; loaded here so their first load is paid at import, not inside a
9798
// test's clocked window.
@@ -235,6 +236,10 @@ async function serve({
235236
if (path === '/api/v1/marketplace/install-local' && method === 'GET') {
236237
return reply(200, { success: true, data: { items: installs } });
237238
}
239+
// objectstack#37139 — Import: the file's manifest, installed.
240+
if (path === '/api/v1/marketplace/install-local' && method === 'POST') {
241+
return reply(200, { success: true, data: { manifestId: 'com.acme.imported' } });
242+
}
238243
const listing = /^\/api\/v1\/marketplace\/packages\/([^/]+)$/.exec(path);
239244
if (listing) {
240245
const id = decodeURIComponent(listing[1]);
@@ -499,7 +504,7 @@ describe('Setup → Installed Apps: an app is one line, its modules folded under
499504
describe('the two doors (objectstack#34722)', () => {
500505
const headers = () => screen.getAllByRole('columnheader').map((h) => h.textContent?.trim());
501506

502-
it('the administration face draws the administrator columns, New Package, and none of the developer doors', async () => {
507+
it('the administration face draws the administrator columns, New Package and Import, and none of the other developer doors', async () => {
503508
await serve({ packages: [HOTCRM, ...MODULES, TODO, CODE, PLATFORM] });
504509
renderAt(SETUP_URL);
505510
await settled();
@@ -512,9 +517,9 @@ describe('the two doors (objectstack#34722)', () => {
512517
row('engine.packages.installedApps.col.update'),
513518
row('engine.packages.col.actions'),
514519
]);
515-
expect(screen.queryByRole('button', { name: row('engine.packages.import') })).toBeNull();
516-
// objectstack#36834 — New Package is the administration face's one header
517-
// action; it lands in Studio (see the create case below).
520+
// objectstack#36834 — New Package lands in Studio (see the create case
521+
// below); objectstack#37139 — Import sits beside it.
522+
expect(screen.getByRole('button', { name: row('engine.packages.import') })).toBeInTheDocument();
518523
expect(screen.getByRole('button', { name: row('engine.packages.new') })).toBeInTheDocument();
519524
expect(screen.queryByTestId('pkg-show-platform')).toBeNull();
520525
expect(screen.queryByTestId('pkg-source-filter')).toBeNull();
@@ -631,12 +636,10 @@ describe('Setup → Packages: the administration face (objectstack#36834)', () =
631636

632637
expect(screen.getByTestId('pkg-source-picker-marketplace')).toHaveAttribute('data-state', 'on');
633638
expect(screen.queryByTestId('pkg-row-com.acme.code')).toBeNull();
634-
expect(screen.queryByRole('button', { name: row('engine.packages.import') })).toBeNull();
635639
// Clearing the filter stays on the administration face.
636640
fireEvent.click(screen.getByTestId('pkg-source-picker-all'));
637641
await waitFor(() => expect(query().get('face')).toBe('admin'));
638642
expect(await screen.findByTestId('pkg-row-com.acme.code')).toBeInTheDocument();
639-
expect(screen.queryByRole('button', { name: row('engine.packages.import') })).toBeNull();
640643
});
641644

642645
it('an unknown face is refused by name, not read as the development surface', async () => {
@@ -927,3 +930,76 @@ describe('Setup → Packages: a read-only base’s customizations in its detail
927930
await waitFor(() => expect(customizationReads).toEqual(['com.acme.code']));
928931
});
929932
});
933+
934+
// ---------------------------------------------------------------------------
935+
// objectstack#37139 — Import sits in Setup → Packages' header beside New
936+
// Package and works as it does on the development face; Studio's package
937+
// menu's 「Manage in Setup…」 opens this face on one package's row
938+
// (`?package=ID`).
939+
// ---------------------------------------------------------------------------
940+
941+
/** The header's Import, fed one package file. */
942+
async function importOn(lang: 'en' | 'zh') {
943+
const button = await screen.findByRole('button', { name: row('engine.packages.import', lang) });
944+
const input = document.querySelector('input[type="file"]') as HTMLInputElement;
945+
const file = new File([JSON.stringify({ id: 'com.acme.imported', name: 'Imported', version: '1.0.0' })], 'imported.json', {
946+
type: 'application/json',
947+
});
948+
fireEvent.change(input, { target: { files: [file] } });
949+
return button;
950+
}
951+
952+
describe('Setup → Packages: Import beside New Package (objectstack#37139)', () => {
953+
it.each(['en', 'zh'] as const)('%s: the header draws Import, then New Package', async (lang) => {
954+
await serve({ packages: [CODE] });
955+
renderAt(ADMIN_URL, lang);
956+
await screen.findByTestId('pkg-row-com.acme.code');
957+
const importButton = screen.getByRole('button', { name: row('engine.packages.import', lang) });
958+
const newButton = screen.getByRole('button', { name: row('engine.packages.new', lang) });
959+
expect(importButton.compareDocumentPosition(newButton) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
960+
expect(importButton.parentElement).toBe(newButton.parentElement);
961+
});
962+
963+
it.each(['en', 'zh'] as const)('%s: Import installs the file and re-reads the list, as on the development face', async (lang) => {
964+
await serve({ packages: [CODE] });
965+
renderAt(ADMIN_URL, lang);
966+
await screen.findByTestId('pkg-row-com.acme.code');
967+
const readsBefore = packagesReads;
968+
await importOn(lang);
969+
expect(
970+
await screen.findByText(t('engine.packages.import.success', lang === 'en' ? 'en-US' : 'zh-CN').replace('{id}', 'com.acme.imported')),
971+
).toBeInTheDocument();
972+
expect(writes).toEqual(['POST /api/v1/marketplace/install-local']);
973+
await waitFor(() => expect(packagesReads).toBeGreaterThan(readsBefore));
974+
});
975+
976+
it('CONTROL: the development surface’s Import sends the same request', async () => {
977+
await serve({ packages: [CODE] });
978+
renderAt(STUDIO_URL);
979+
await screen.findByTestId('pkg-row-com.acme.code');
980+
await importOn('en');
981+
await waitFor(() => expect(writes).toEqual(['POST /api/v1/marketplace/install-local']));
982+
});
983+
});
984+
985+
describe('Setup → Packages on one package’s row: `?package=ID` (objectstack#37139)', () => {
986+
it('opens that package’s detail on arrival and drops the param, keeping the face', async () => {
987+
await serve({ packages: [CODE, AUTHORED] });
988+
renderAt(setupPackagePath('app.b2r4'));
989+
const sheet = await screen.findByRole('dialog');
990+
expect(within(sheet).getByText('app.b2r4')).toBeInTheDocument();
991+
// The administration actions are there: Disable and Delete.
992+
expect(within(sheet).getByRole('button', { name: row('engine.packages.detail.disable') })).toBeInTheDocument();
993+
expect(within(sheet).getByRole('button', { name: row('engine.packages.detail.deletePackage') })).toBeInTheDocument();
994+
await waitFor(() => expect(query().has('package')).toBe(false));
995+
expect(query().get('face')).toBe('admin');
996+
});
997+
998+
it('an id the list does not name opens nothing, and the param is dropped', async () => {
999+
await serve({ packages: [CODE] });
1000+
renderAt(setupPackagePath('com.gone.away'));
1001+
await screen.findByTestId('pkg-row-com.acme.code');
1002+
await waitFor(() => expect(query().has('package')).toBe(false));
1003+
expect(screen.queryByRole('dialog')).toBeNull();
1004+
});
1005+
});

0 commit comments

Comments
 (0)