Skip to content

Commit 49bc3be

Browse files
feat(ui): the hosted unmanaged install dialog shows and edits its target namespace (#32263)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBGU8m9WENyvoKLyxe2kUbYo)_ Fixes #32040 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 改了什么:托管环境里以「非托管副本」安装应用时,安装对话框多了一个「目标命名空间」输入框,预填控制面给的默认值(经 #32182 的同源路由 `GET /api/v1/cloud-connection/install-namespace` 读取),可以修改,安装时作为 `target_namespace` 发出;托管安装不画输入框、不发这个键。 - 为什么改:#31482 之后服务端已能按命名空间复制,只差界面;之前对话框既不显示也不能改命名空间,冲突时也不能换名重试。 - 风险与回滚:只动界面和 11 种语言的 `marketplace` 懒加载文案,不动服务端和 `packages/spec`;读不到默认值(`503`/`502`)时输入框留空,手填仍可安装,空着则不发键、沿用控制面默认。回滚即 revert 本 PR。 - 先看:`MarketplacePackagePage.tsx` 的 `namespaceFieldShown` / `doInstall` 的 catch 分支,`marketplaceApi.ts` 的 `getInstallNamespace`,新文件 `targetNamespaceRefusal.ts`(三种拒绝怎么分)。 - 两分钟验证:`cd ui && pnpm exec vitest run packages/app-shell/src/console/marketplace/__tests__/MarketplacePackagePage.installMode-12288.test.tsx`,预期 46 条全绿;截图在项目文件夹 `ui-orders/32040-shots/`。 - 需要你做的:无,席位落地。⚠️ 默认值读的是 `data.namespace`,这个键名取自路由测试的转发样例,云端 PR #4206 本会话读不到,请席位核一下。 ## What changes - **The namespace read.** `marketplaceApi.getInstallNamespace(packageId)` calls `GET /api/v1/cloud-connection/install-namespace?package_id=…` with the same `withEnvAuth` + `credentials: 'include'` that `installPackage` uses, and returns the trimmed string at `data.namespace`, else `null`. `null` covers `503 CLOUD_UNCONFIGURED`, `502 EXTERNAL_SERVICE_ERROR`, any other refusal, a network failure and a non-string value: the field is empty, never a guessed name. - **The install body.** `installPackage` takes an optional `targetNamespace` and sends it as `target_namespace` on the hosted same-origin route only, only beside `installMode: 'unmanaged'`, trimmed, never blank. A managed install never carries the key, since the route refuses it there. - **The dialog.** For an unmanaged hosted install (never an update), the dialog draws a "Target namespace" field: a skeleton while the read is in flight (Install waits), then an editable input pre-filled with the default, or empty with a "no default could be read" hint. `data-state` on `install-target-namespace` is `loading`, `ready` or `refused`. - **Refusals**, sorted by `targetNamespaceRefusal.ts` from the error's `code` (read with `errorCodeIs`) and `details` (which `installPackage` already carries on its thrown error): - `409 RESOURCE_CONFLICT` with `details.namespace`: the dialog stays open, the field says the name is taken (localized, naming it), focus returns to the field, and Install is enabled for another name. - `400 INVALID_REQUEST` with `details.targetNamespace`: the server's sentence is shown beside the field. - `409 RESOURCE_CONFLICT` with `details.targetPackageId` (a second unmanaged copy): shown as a plain refusal in the dialog's result box, with no re-ask, since no namespace clears it (card item 3, stated not fixed). - **Strings.** Five keys under `marketplace.install.targetNamespace.*` in all 11 files of the `marketplace` lazy namespace (`zh-Hant` generated by `gen:zh-hant`). ⛔ Nothing in `src/locales/en.ts`. The German `taken` string adds one „…“ pair, so `de-quote-pairing-3876.test.ts` moves its two pins by one, with a dated line in each comment as earlier additions did. - **Changeset** `.changeset/32040-hosted-install-target-namespace.md`: `@object-ui/i18n` patch. `@object-ui/app-shell` is private and gets no row. `Clause-②: yes (widening)`: `@object-ui/i18n` gains five strings. `marketplaceApi`'s exported surface does widen (the new `getInstallNamespace` export and the optional `targetNamespace` input), but it lives in the private `@object-ui/app-shell`, so nothing it adds publishes. ## Why #31482 lets the control plane copy a package under a chosen namespace, and #32182 (#32083) added the same-origin read of its default. The dialog was the missing piece: it sent no namespace and drew no field. ## Verification - `MarketplacePackagePage.installMode-12288.test.tsx`: 46 / 46, 12 of them new (two new describes in the existing harness; `marketplaceApi` is not mocked, one stubbed `fetch` answers by path): default shown and sent, edited value sent, `503` / `502` empty field still installs a typed name, empty field sends no key, ownership `409` re-asks and installs a new name, `400` sentence beside the field, `targetPackageId` `409` gives no re-ask, managed install shows no field, reads no default and sends no key, plus `installPackage` / `getInstallNamespace` unit pins. - **Ablation** (`scripts/ablation-replace.mjs`, delete `...withNamespace,` from the hosted body): 6 tests go red (default sent, edited sent, both `503`/`502` typed-name cases, the re-ask case, the unit pin). Restored; `git diff HEAD` empty. - `vitest run packages/app-shell/src/console/marketplace packages/app-shell/src/__tests__ packages/i18n`: 183 files, all green after the German pin move (that suite holds the ADR-0060 `product-neutral-renderer.ratchet` test). - `type-check` of `@object-ui/app-shell` and `@object-ui/i18n`: clean. ESLint on the changed files: 0 errors. `node scripts/check-i18n-call-site-keys.mjs` (ui): clean. - Full `turbo run build --filter='!@objectstack/docs'`: 119 / 119. - Derived gates: every line of `dispatch-gates.mjs --commands`, plus `pnpm --dir ui run check:eager-closure`, `node scripts/check-sdui-manifest.mjs` and `pnpm --dir ui run check:spec-symbols`; results in the `--ran` reading below. - **Browser.** A hosted environment is not bootable in this container (no control plane). Shot against a real CRM dev boot and the console on Vite, with Playwright mocking the hosted routes (`runtime/config` patched to a cloud base with `installLocal: false`, the catalog, manifest, `install-namespace` and `install` answers). Seven dialog states in the project folder `ui-orders/32040-shots/`: loading, default shown, no default (`503`), name taken (`409`), malformed (`400`), second copy (`409 targetPackageId`), managed (no field). <details><summary><code>dispatch-gates --ran</code>: 39 derived, 39 run, 0 NOT-MEASURED; every exit 0</summary> `check:eager-closure` and `check:spec-symbols` (ui) ran beside the 39 and exited 0; `check-sdui-manifest` is one of the 39. Gate scripts ran on a shared box. </details> ## Known limits - The namespace key inside `data` is read as `namespace`, taken from the relay pin in `cloud-connection-plugin.test.ts`, which #32182's own body calls an illustrative fixture. Cloud PR #4206 is not readable from this session. If the control plane sends another key, the field is simply empty (a typed name still installs); it never sends a wrong value. - A second unmanaged copy of the same package is still refused, as the card says (item 3). ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (no spec change) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; lint passes on the changed files. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title and body are in English, except the maintainer brief. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzgQpfw8pDeXcPo2zvJ <!-- signed: domain:ui#2 · os-support-ai · session_01WGufzgQpfw8pDeXcPo2zvJ --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent e34723f commit 49bc3be

17 files changed

Lines changed: 502 additions & 10 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/i18n': patch
3+
---
4+
5+
feat(ui): the hosted unmanaged install dialog shows and edits the namespace its copy takes
6+
7+
Clause-②: yes (widening) — `@object-ui/i18n` gains five `marketplace.install.targetNamespace.*` strings; `marketplaceApi`'s new `getInstallNamespace` export and optional `targetNamespace` input live in the private `@object-ui/app-shell`, so they publish nothing
8+
Metadata-protocol: none
9+
10+
On a hosted environment, an unmanaged install now draws a "Target namespace" field in the install dialog, pre-filled with the default the control plane would use (read through `GET /api/v1/cloud-connection/install-namespace`), and sends the value as `target_namespace`. When no default can be read (the runtime is not connected, or the control plane did not answer) the field starts empty and a typed name still installs; an empty field sends nothing and the control plane's default stands. A managed install draws no field and sends no namespace.
11+
12+
If the namespace belongs to another package, the dialog stays open, says the name is taken and asks for another. A malformed or reserved namespace shows the server's sentence beside the field. A second unmanaged copy of the same package is still refused, and no new namespace is offered for it, since a different namespace does not clear that refusal.
13+
14+
The strings are in all eleven locales of the `marketplace` namespace.

‎ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx‎

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
DialogHeader,
2828
DialogTitle,
2929
Label,
30+
Input,
3031
Checkbox,
3132
Select,
3233
SelectContent,
@@ -72,6 +73,7 @@ import {
7273
getServedPackageBody,
7374
declaredInstallModesOf,
7475
installPackage,
76+
getInstallNamespace,
7577
installLocal,
7678
uninstallLocal,
7779
listLocalInstalls,
@@ -114,6 +116,7 @@ import { SuggestedBindingsPanel, type SuggestedBindingsStrings } from '../../com
114116
import { ConnectorCredentialsStep } from './ConnectorCredentialsStep.js';
115117
import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js';
116118
import { errorCodeIs } from '@object-ui/types';
119+
import { readTargetNamespaceRefusal } from './targetNamespaceRefusal.js';
117120
import { MarketplaceNamespaceGate } from './MarketplaceNamespaceGate.js';
118121
import { effectiveSolutionType, readListingTaxonomy } from './marketplaceTaxonomy.js';
119122
import { DetailLanguagesGroup } from './MarketplaceLanguages.js';
@@ -273,6 +276,13 @@ function MarketplacePackagePageBody() {
273276
// requested permissions before the install button is enabled.
274277
const [acknowledged, setAcknowledged] = useState(false);
275278
const [installing, setInstalling] = useState(false);
279+
// objectstack#32040 — the hosted unmanaged install's target namespace: the
280+
// control plane's default as read for one package (`null` while the read is
281+
// in flight), the value the operator edits, and the refusal drawn beside it.
282+
const [namespaceDefault, setNamespaceDefault] = useState<{ packageId: string; value: string | null } | null>(null);
283+
const [targetNamespace, setTargetNamespace] = useState('');
284+
const [namespaceError, setNamespaceError] = useState<string | null>(null);
285+
const namespaceInputRef = useRef<HTMLInputElement | null>(null);
276286
const [installResult, setInstallResult] = useState<{ ok: boolean; message: string } | null>(null);
277287
const [deploy, setDeploy] = useState<DeployState | null>(null);
278288
// Tracks whether the package has been installed into the current
@@ -416,6 +426,32 @@ function MarketplacePackagePageBody() {
416426
? requestedInstallMode
417427
: undefined;
418428

429+
// objectstack#32040 — an unmanaged hosted install (never an update) names
430+
// the namespace its copy takes: the field is drawn, pre-filled with the
431+
// control plane's default. A managed install draws no field and sends none.
432+
const namespaceFieldShown = installOpen && !dialogUpdate && hostedInstallMode === 'unmanaged';
433+
const namespaceLoading = namespaceFieldShown && namespaceDefault?.packageId !== packageId;
434+
useEffect(() => {
435+
if (!namespaceFieldShown || !packageId) return;
436+
let cancelled = false;
437+
setNamespaceDefault(null);
438+
setTargetNamespace('');
439+
setNamespaceError(null);
440+
void getInstallNamespace(packageId).then((value) => {
441+
if (cancelled) return;
442+
// No default (unconfigured, unreachable, refused): the field stays empty
443+
// and a typed name still installs.
444+
setNamespaceDefault({ packageId, value });
445+
setTargetNamespace(value ?? '');
446+
});
447+
return () => { cancelled = true; };
448+
}, [namespaceFieldShown, packageId]);
449+
// A refused namespace returns focus to its field once the install settles
450+
// (the field is disabled while it runs), so the operator types another.
451+
useEffect(() => {
452+
if (namespaceError && !installing) namespaceInputRef.current?.focus();
453+
}, [namespaceError, installing]);
454+
419455
// Seed cloud-install state so the primary CTA renders as "Installed" on
420456
// first paint instead of inviting another install.
421457
// NOTE: a tenant runtime (per-subdomain ObjectOS) has NO
@@ -630,8 +666,10 @@ function MarketplacePackagePageBody() {
630666
// ADR-0131 D6 — an install, never an update of the managed copy this
631667
// environment holds, sends the mode the package page resolved.
632668
const installMode = dialogUpdate ? undefined : hostedInstallMode;
669+
const askedNamespace = installMode === 'unmanaged' ? targetNamespace.trim() : '';
633670
setInstalling(true);
634671
setInstallResult(null);
672+
setNamespaceError(null);
635673
try {
636674
// objectui#12146 — an update never asks for sample data: the update
637675
// dialog draws no "Include sample data" control, so it sends what an
@@ -642,6 +680,7 @@ function MarketplacePackagePageBody() {
642680
environmentId: selectedEnv,
643681
seedSampleData: dialogUpdate ? false : seedSampleData,
644682
...(installMode ? { installMode } : {}),
683+
...(askedNamespace ? { targetNamespace: askedNamespace } : {}),
645684
});
646685
const name = data?.package ? localizePackage(data.package as any, language).displayName : packageId;
647686
// An unmanaged copy (ADR-0131 D6) is the environment's own base, not a
@@ -707,7 +746,17 @@ function MarketplacePackagePageBody() {
707746
});
708747
}
709748
} catch (e: any) {
710-
setInstallResult({ ok: false, message: installRefusalText(e) });
749+
// A refusal of the typed namespace is drawn beside the field, and the
750+
// dialog stays open for another name. A second copy of the same package
751+
// (`details.targetPackageId`) is not one: no namespace clears it.
752+
const nsRefusal = askedNamespace ? readTargetNamespaceRefusal(e) : null;
753+
if (nsRefusal) {
754+
setNamespaceError(nsRefusal.kind === 'taken'
755+
? t('marketplace.install.targetNamespace.taken', { namespace: nsRefusal.namespace })
756+
: nsRefusal.message);
757+
} else {
758+
setInstallResult({ ok: false, message: installRefusalText(e) });
759+
}
711760
} finally {
712761
setInstalling(false);
713762
}
@@ -1959,6 +2008,38 @@ function MarketplacePackagePageBody() {
19592008
</div>
19602009
)}
19612010

2011+
{namespaceFieldShown && !envsError && (
2012+
<div className="space-y-1.5" data-testid="install-target-namespace" data-state={namespaceLoading ? 'loading' : (namespaceError ? 'refused' : 'ready')}>
2013+
<Label htmlFor="install-target-namespace-input">{t('marketplace.install.targetNamespace.label')}</Label>
2014+
{namespaceLoading ? (
2015+
<Skeleton className="h-9 w-full" data-testid="install-target-namespace-loading" />
2016+
) : (
2017+
<Input
2018+
id="install-target-namespace-input"
2019+
ref={namespaceInputRef}
2020+
value={targetNamespace}
2021+
onChange={(e) => { setTargetNamespace(e.target.value); setNamespaceError(null); }}
2022+
placeholder={t('marketplace.install.targetNamespace.placeholder')}
2023+
disabled={installing || installResult?.ok === true}
2024+
aria-invalid={namespaceError ? true : undefined}
2025+
aria-describedby={namespaceError ? 'install-target-namespace-error' : 'install-target-namespace-hint'}
2026+
autoComplete="off"
2027+
spellCheck={false}
2028+
className="font-mono"
2029+
/>
2030+
)}
2031+
{namespaceError ? (
2032+
<p id="install-target-namespace-error" role="alert" className="text-sm text-destructive">{namespaceError}</p>
2033+
) : (
2034+
<p id="install-target-namespace-hint" className="text-xs text-muted-foreground">
2035+
{namespaceDefault !== null && namespaceDefault.packageId === packageId && namespaceDefault.value === null
2036+
? t('marketplace.install.targetNamespace.noDefault')
2037+
: t('marketplace.install.targetNamespace.hint')}
2038+
</p>
2039+
)}
2040+
</div>
2041+
)}
2042+
19622043
{containsCode && !envsError && (
19632044
<div className="space-y-3">
19642045
<PluginDisclosure version={pkg.latest_version} />
@@ -2010,7 +2091,7 @@ function MarketplacePackagePageBody() {
20102091
{!envsError && (
20112092
<Button
20122093
onClick={doInstall}
2013-
disabled={!selectedEnv || installing || installResult?.ok === true || deploy !== null || (containsCode && !acknowledged)}
2094+
disabled={!selectedEnv || installing || installResult?.ok === true || deploy !== null || (containsCode && !acknowledged) || namespaceLoading}
20142095
>
20152096
{dialogUpdate
20162097
? (installing ? t('marketplace.action.updating') : t('marketplace.action.updateTo', { defaultValue: 'Update' }))

0 commit comments

Comments
 (0)