Skip to content

Commit b4f4781

Browse files
feat(console): the install note says how many sample records an install loaded, and clears them in place (#30537)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuSy5eNPdVfiKwQVEHz8MX4y)_ Part of #30323 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:在应用市场详情页把应用安装到本运行时后,安装结果里会写明「本次安装载入了 N 条示例记录」,旁边直接有「清除示例数据」按钮;清除改用控制台自己的确认框(不再是浏览器原生弹窗),本次会话装过的应用会写明「最多删除 N 条」;离开详情页进入应用后,页面顶部有一条横幅提示该应用有示例数据,点「清除示例数据」会回到详情页并直接打开确认框;重装时说明示例数据会重新载入;「应该已经出现在应用切换器中」改成确定的说法。10 种语言。 - 为什么改:示例数据默认保留(维护者裁决),但客户不知道去哪里清,假客户、假收入会一直留在仪表盘上。 - 风险与回滚:只读安装应答里已有的 `seeded` 计数,不改服务端、不改清除规则(只删带示例记录键的行,用户新增和改过键的记录保留);横幅只在本次浏览器会话内有效;回滚即还原本 PR。 - 先看:`ui/packages/app-shell/src/console/marketplace/MarketplacePackagePage.tsx` 的 `doInstallLocal` 与 `purgeConfirmDialog`;`SampleDataLeaveBanner.tsx`(离页时发横幅);`sampleDataNotice.ts`(计数读取与会话记录)。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/console/marketplace/__tests__/MarketplacePackagePage.sampleDataNotice-30323.test.tsx`,预期 12 个用例全绿(需先建 `@object-ui/app-shell` 的依赖闭包)。 - 需要你做的:无,席位落地。 ## What changes Card #30323, the console half that the install answer already supports. Maintainer ruling on the card, verbatim: 「我觉得安装应用市场应用的时候是需要有初始数据的,这样客户才能看得到效果,但是呢,应该有界面功能能够帮助他清理数据」. Sample data stays on by default; this PR makes the cleanup easy to find. - **Premise, measured.** `POST /api/v1/marketplace/install-local` answers `data.seeded` with the seed run's counts (`mode: 'inline'`, `inserted`, `updated`, `skipped`, `errors`), so the claim's stop condition does not apply. Read live on base `70981e63`: a fresh install answered `inserted: 3`, a reinstall over live sample data `skipped: 3`, the purge `deleted: 3`, and a reinstall after the purge `inserted: 3` again (the card's "reinstalling reseeds"). - **The install note** (`doInstallLocal`). After a managed install, the result note says how many sample records the install left in place (`inserted + updated + skipped` of an `inline` run; `skipped` there means the row was already in the database), with a "Purge sample data" button in place. An install over an existing one adds that installing again loads the sample data again, including any that was cleared. No line for `skipped` / `refused` / `replayer` runs, an unmanaged copy, or an answer without `seeded`. - **Definite success sentence.** `marketplace.install.localSuccess` (shown only when the answer says `hotLoaded: true`) now reads "… is now in the app switcher." instead of "should now appear", in all 10 packs. - **The console's own confirm.** Both purge paths (local and cloud, from the note or the ⋯ menu) open an `AlertDialog` in place of `window.confirm`. When this session knows the install's count, the dialog says at most that many sample records go (the purge deletes only rows carrying a seed record's key, so the install's count is an upper bound). The purge rule and its doors are unchanged. - **A reach from the app's own pages**, through an existing generic block: the console's `banner` notification (`NotificationBanners`, drawn by `ConsoleLayout` above every page). `SampleDataLeaveBanner` raises it when the installer leaves the package page, for a package this session recorded loading sample data into. Its "Purge sample data" action navigates back to the package page, which opens the confirm once the listing says the sample data is still there. Clearing withdraws the banner; coming back to the page withdraws it while the page's own note speaks. - **Session record** (`sampleDataNotice.ts`): the reader `sampleRecordsLoaded()` and an in-memory map from manifest id to the count, name and page path, used by the confirm and the banner. A reseed from the ⋯ menu records its own count the same way. - **Types.** `LocalManagedInstallResult` and `LocalUnmanagedInstallResult` gain the optional `seeded` (`LocalInstallSeeded`) in `marketplaceApi.ts`. - **i18n.** New in all 10 packs under `marketplace.detail`: `sampleDataLoaded` and `purgeConfirmAtMost` (count families with each language's CLDR slots, as `purgeSuccess`), `sampleDataReloaded`, `sampleDataBannerTitle`, `sampleDataBannerMessage`. The banner and the note's button reuse `purgeSampleData`. - **Changeset.** `.changeset/30323-install-note-sample-data.md`, `@object-ui/app-shell` and `@object-ui/i18n` patch. Branch: the harness-assigned `claude/project-thread-6nrbkq`, not `claude/issue-30323-*`; the card is #30323. ## Tests - New `MarketplacePackagePage.sampleDataNotice-30323.test.tsx` (12 cases, the real `marketplaceApi` over one stubbed `fetch`, `window.confirm` stubbed to throw): the 369-record note with the definite sentence and the clear; inserted + updated + skipped over live data with the reinstall line; reinstall after clearing; CONTROL: `skipped`, `refused`, an inline run that left nothing, and no `seeded` draw no line; the note's clear opens the dialog with the count and its confirm purges and drops the clear; Cancel purges nothing; the ⋯ menu's purge on a visit with no install this session shows the dialog without a count; the banner is absent on the page, raised on leaving, its action navigates back and the page opens the confirm, clearing leaves no banner; CONTROL: no banner when nothing was loaded. - Moved pins: `MarketplacePackagePage.offlineLocalMenu-11627.test.tsx` and `MarketplacePackagePage.sampleDataRefusal-10432.test.tsx` click the dialog's confirm after the menu item (the purge now asks in the console's dialog). `ui/packages/i18n/src/__tests__/de-quote-pairing-3876.test.ts` counts one more matched „…“ span (104 to 105) for `sampleDataBannerTitle`. ## Acceptance notes - **Left open on the card (why `Part of`).** "The confirm says how many records will go" holds only for an install made in this console session. After a reload nothing serves a count: the purge door has no dry run and the install-local listing's `withSampleData` is presence only (`sampleDataInScope` reads `firstOnly`). A count after the fact needs the server to answer it, in `packages/cloud-connection`, outside this claim's surface. For the same reason the banner lasts for the console session, not across reloads; a standing per-app reach would need a mount outside `console/marketplace/**`. - The cloud install path (`installPackage`) answers no sample-data count, so its install note is unchanged; its purge confirm is the new dialog without a count. - Live UI screenshots: NOT MEASURED. This rig has no cloud marketplace (`cloudUrl` empty), so the package page cannot install from a catalog here; the page is covered by the tests above, on the answer shape the live server returned. ## Verification <details><summary>Live install-local readings (examples/app-showcase, objectstack dev --fresh, base 70981e6)</summary> Manifest `com.acme.rig` with one object `rig_note` and one dataset of three records keyed by `title`: - install: `seeded: {mode: "inline", inserted: 3, updated: 0, skipped: 0, errors: 0}`, `upgradedFrom: null`, `hotLoaded: true` - install again: `seeded: {mode: "inline", inserted: 0, updated: 0, skipped: 3, errors: 0}`, `upgradedFrom: "previous-marketplace-version"` - purge: `{deleted: 3, skipped: 0, errors: 0, withSampleData: false}`; the listing then answers `withSampleData: false` - install after the purge: `seeded: {mode: "inline", inserted: 3, ...}` </details> <details><summary>Tests, type-check, lint</summary> - `pnpm --dir ui exec vitest run packages/app-shell/src/console/marketplace packages/i18n packages/app-shell/src/views/metadata-admin/PackagesPage`: Test Files 164 passed (164), Tests 2028 passed, 13 skipped. - `pnpm --filter @object-ui/app-shell --filter @object-ui/i18n run type-check`: both Done, exit 0. - `eslint --no-inline-config` on the changed files: 0 errors (warnings are the files' existing `no-explicit-any` and one unused `code`). - `check:i18n-keys`, `check:i18n-drift`, `check:i18n-dead-keys` (ui): exit 0 each; drift: every changed `en` value followed by all nine packs. </details> <details><summary>Ablations (scripts/ablation-replace.mjs, restored to HEAD each time)</summary> - `sampleRecordsLoaded` returns `null`: 6 of 12 red (every count case), 6 controls green. - `openLocalPurgeConfirm` purges without the dialog: 3 red (note clear, Cancel, ⋯ menu dialog). - `SampleDataLeaveBanner` raises nothing on leaving: 1 red (the banner case). </details> <details><summary>Derived gates (dispatch-gates --commands, 35 families)</summary> All 35 derived families ran on `1470c715` with exit 0; `dispatch-gates --ran` answered 35 derived, 35 run, 0 NOT-MEASURED, 0 UNRUN. `pnpm check:changeset-fixed` (its roster is under `.changeset`) exit 0. After merging `origin/main` (head `eaf46b57`, which brought locale-pack edits from other PRs and merged cleanly), the derivation is the same 35-command list, and these were run again with exit 0: the marketplace + i18n + PackagesPage tests (164 files, 2028 passed), app-shell and i18n type-check, `check:i18n-keys`, `check:i18n-drift`, `check:type-check-coverage`, `check:type-check-debt`, `check:nul-bytes`, `check:published-files`, `check-empty-changeset`, `check-changeset-no-major`. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgVKAj6nUY3DxWKsvXb)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 67d5d53 commit b4f4781

19 files changed

Lines changed: 771 additions & 25 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): the install note says how many sample records an install loaded, and clears them in place
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
- **The install note.** After an install into this runtime, the package page's result now says how many sample records the install loaded, read from the install answer's own `data.seeded` report (`inserted + updated + skipped` of an `inline` run), with a "Purge sample data" button right there. An install over an existing one adds that installing again loads the sample data again, including any that was cleared. An install that loaded none (no seed datasets, a copy, a walled session with no active organization) shows nothing new. The success sentence is definite where the runtime answered that it loaded the app: "… is now in the app switcher."
12+
- **The console's own confirm.** Purging sample data (from the install note, or the ⋯ menu, local or cloud) asks in the console's dialog instead of the browser's. When this session installed the package, the dialog says how many sample records will go at most: the number the install loaded. The clearing rule is unchanged: only rows that carry a seed record's key are deleted.
13+
- **A reach from the app's own pages.** When the installer leaves the package page, a console banner (the `banner` notification `ConsoleLayout` draws above every page) says the app holds sample data, with a "Purge sample data" action that brings them back to the package page with the confirm open. Clearing withdraws it. It lasts for the console session; the runtime serves no count of sample rows after the install answer.
14+
- **Types.** `LocalManagedInstallResult` and `LocalUnmanagedInstallResult` gain the optional `seeded` (`LocalInstallSeeded`).
15+
- **Strings.** `@object-ui/i18n` gains `marketplace.detail.sampleDataLoaded`, `sampleDataReloaded`, `purgeConfirmAtMost` (count families), `sampleDataBannerTitle` and `sampleDataBannerMessage` in all 10 locales, and rewords `marketplace.install.localSuccess` in all 10.

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

Lines changed: 129 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ import {
4343
TooltipContent,
4444
TooltipProvider,
4545
TooltipTrigger,
46+
AlertDialog,
47+
AlertDialogAction,
48+
AlertDialogCancel,
49+
AlertDialogContent,
50+
AlertDialogDescription,
51+
AlertDialogFooter,
52+
AlertDialogHeader,
53+
AlertDialogTitle,
4654
} from '@object-ui/components';
4755
import { ArrowLeft, ExternalLink, Download, AlertCircle, Package, Trash2, MoreHorizontal, CheckCircle2, ArrowUpCircle, Database, Loader2 } from 'lucide-react';
4856
import { useWorkspaceAdminStatus } from '@object-ui/auth';
4957
import { useObjectTranslation } from '@object-ui/i18n';
5058
import { useDisplayLocale } from '@object-ui/i18n';
5159
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
52-
import { useAdapter } from '@object-ui/react';
60+
import { useAdapter, useHasNotificationProvider } from '@object-ui/react';
5361
import { PackageIcon } from './PackageIcon.js';
5462
import { MarkdownText } from './MarkdownText.js';
5563
import { PluginDisclosure } from './PluginDisclosure.js';
@@ -84,6 +92,8 @@ import {
8492
import { useDependencyMissingText } from './dependencyMissing.js';
8593
import { useProtocolCheckSkippedText } from './protocolCheckSkipped.js';
8694
import { ProtocolCheckSkippedNote } from './ProtocolCheckSkippedNote.js';
95+
import { forgetSampleData, rememberSampleData, sampleDataNotice, sampleRecordsLoaded, takeClearConfirmRequest } from './sampleDataNotice.js';
96+
import { SampleDataLeaveBanner } from './SampleDataLeaveBanner.js';
8797
import { getCloudBase, getRuntimeConfig, isMarketplaceEnabled } from '../../runtime-config.js';
8898
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
8999
import { useMetadata } from '../../providers/MetadataProvider.js';
@@ -273,7 +283,16 @@ export function MarketplacePackagePage() {
273283
// objectstack#30326 — the install answer's `protocolCheckSkipped`, drawn:
274284
// installed, but its platform protocol range was not checked.
275285
protocolNote?: string;
286+
// objectstack#30323 — the sample records the install answer says it left
287+
// in place (`seeded`), and whether this was an install over an existing
288+
// one, which loads the sample data again. Cleared once they are purged.
289+
sampleData?: { count: number; reinstall: boolean };
276290
} | null>(null);
291+
// objectstack#30323 — the console's own confirm for a sample-data purge, in
292+
// place of the browser's: which install it purges, and how many sample
293+
// records this session knows that install loaded (`null`: none known).
294+
const [purgeConfirm, setPurgeConfirm] = useState<{ target: 'local' | 'cloud'; count: number | null } | null>(null);
295+
const hasNotificationProvider = useHasNotificationProvider();
277296
// ADR-0131 D6 — the install modes the package's latest manifest declares,
278297
// read from the manifest install-local judges, and the operator's pick among
279298
// them. Both are kept with the package they belong to, so a page that moves
@@ -305,7 +324,14 @@ export function MarketplacePackagePage() {
305324
let cancelled = false;
306325
(async () => {
307326
const items = await listLocalInstalls();
308-
if (!cancelled) setLocalInstalls(items);
327+
if (cancelled) return;
328+
setLocalInstalls(items);
329+
// objectstack#30323 — the app's sample-data banner brought the installer
330+
// here to clear: its action asks for the confirm of the package whose
331+
// page it opens, so the confirm opens once the listing says that
332+
// package's sample data is still there.
333+
const requested = items.find((i) => i.withSampleData && !i.notLoaded && takeClearConfirmRequest(i.manifestId));
334+
if (requested) setPurgeConfirm({ target: 'local', count: sampleDataNotice(requested.manifestId)?.count ?? null });
309335
})();
310336
return () => { cancelled = true; };
311337
}, [packageId, localResult, isAdmin]);
@@ -602,6 +628,9 @@ export function MarketplacePackagePage() {
602628
// Declaring none sends none, and the door's own default stands.
603629
const installMode = requestedInstallMode;
604630
if (offeredInstallModes && !installMode) return;
631+
// Read before the install answers: an install over an existing one loads
632+
// the package's sample data again, and its note says so.
633+
const reinstall = !!localInstall;
605634
setInstallingLocal(true);
606635
setLocalResult(null);
607636
try {
@@ -611,6 +640,15 @@ export function MarketplacePackagePage() {
611640
// admitted with its protocol range unchecked; each note below carries it.
612641
const protocolNote = protocolCheckSkippedText(result) ?? undefined;
613642
const withProtocolNote = protocolNote ? { protocolNote } : {};
643+
// objectstack#30323 — the answer's own count of the sample records the
644+
// install left in place. Remembered for this session: the clear confirm
645+
// reads it back, and the banner that follows the installer to the app is
646+
// raised from it. An unmanaged copy loads none (`seeded.mode: skipped`).
647+
const loaded = sampleRecordsLoaded(result);
648+
const withSampleData = loaded !== null ? { sampleData: { count: loaded, reinstall } } : {};
649+
if (loaded !== null) {
650+
rememberSampleData({ manifestId: result.manifestId, name, count: loaded, path: `${basePath}/system/marketplace/${packageId}` });
651+
}
614652
// An unmanaged copy (ADR-0131 D6): the package's metadata is this
615653
// runtime's own from now on, in the base the answer names; the answer
616654
// lists every protection lock the copy dropped, with the package's reason.
@@ -640,8 +678,8 @@ export function MarketplacePackagePage() {
640678
// and the page says when the app will appear.
641679
if (!result.hotLoaded) {
642680
setLocalResult(ignoredCopy
643-
? { ok: false, message: t('marketplace.install.unmanagedIgnored', { name }), ...withProtocolNote }
644-
: { ok: true, message: t('marketplace.install.localLoadsAtRestart', { version: result.version, name }), ...withProtocolNote });
681+
? { ok: false, message: t('marketplace.install.unmanagedIgnored', { name }), ...withProtocolNote, ...withSampleData }
682+
: { ok: true, message: t('marketplace.install.localLoadsAtRestart', { version: result.version, name }), ...withProtocolNote, ...withSampleData });
645683
return;
646684
}
647685
try {
@@ -650,12 +688,13 @@ export function MarketplacePackagePage() {
650688
// Non-fatal: the install succeeded; the app list will refresh on next navigation.
651689
}
652690
setLocalResult(ignoredCopy
653-
? { ok: false, message: t('marketplace.install.unmanagedIgnored', { name }), ...withProtocolNote }
691+
? { ok: false, message: t('marketplace.install.unmanagedIgnored', { name }), ...withProtocolNote, ...withSampleData }
654692
: {
655693
ok: true,
656694
message: t('marketplace.install.localSuccess', { version: result.version, name }),
657695
credentials: { packageId: result.manifestId, note: result.credentialNote },
658696
...withProtocolNote,
697+
...withSampleData,
659698
});
660699
emitMetadataRefresh();
661700
} catch (e: any) {
@@ -762,9 +801,6 @@ export function MarketplacePackagePage() {
762801
*/
763802
const doPurgeSampleData = async () => {
764803
if (!cloudInstall) return;
765-
if (!confirm(t('marketplace.detail.purgeConfirm'))) {
766-
return;
767-
}
768804
setSampleDataBusy('purge');
769805
setSampleDataMsg(null);
770806
try {
@@ -801,6 +837,13 @@ export function MarketplacePackagePage() {
801837
const inserted = r.inserted ?? 0;
802838
const updated = r.updated ?? 0;
803839
const errored = r.errors ?? 0;
840+
// objectstack#30323 — what the reseed left in place, for the clear
841+
// confirm and the banner, as an install's count is.
842+
const reseeded = sampleRecordsLoaded({ seeded: { mode: 'inline', inserted, updated, skipped: r.skipped } });
843+
if (reseeded !== null) {
844+
const name = data?.package ? localizePackage(data.package as any, language).displayName : localInstall.manifestId;
845+
rememberSampleData({ manifestId: localInstall.manifestId, name, count: reseeded, path: `${basePath}/system/marketplace/${packageId}` });
846+
}
804847
const base = t('marketplace.detail.reseedLocalSuccess', { inserted, updated });
805848
// A reseed can land some rows and fail others (the server only hard-fails
806849
// when ZERO rows write). Don't hide the partial failures behind a green
@@ -817,16 +860,17 @@ export function MarketplacePackagePage() {
817860

818861
const doPurgeLocalSampleData = async () => {
819862
if (!localInstall) return;
820-
if (!confirm(t('marketplace.detail.purgeConfirm'))) {
821-
return;
822-
}
823863
setSampleDataBusy('purge');
824864
setSampleDataMsg(null);
825865
try {
826866
const r = await purgeLocalSampleData(localInstall.manifestId);
827867
setLocalInstalls((prev) => prev.map((i) =>
828868
i.manifestId === localInstall.manifestId ? { ...i, withSampleData: false } : i,
829869
));
870+
// objectstack#30323 — cleared: the install note drops its clear, and the
871+
// session record and its banner go.
872+
forgetSampleData(localInstall.manifestId);
873+
setLocalResult((prev) => (prev?.sampleData ? { ...prev, sampleData: undefined } : prev));
830874
const removed = r.deleted ?? 0;
831875
setSampleDataMsg({
832876
ok: true,
@@ -854,6 +898,13 @@ export function MarketplacePackagePage() {
854898
? localInstalls.find((i) => !!data && i.manifestId === data.package.manifest_id)
855899
: localInstalls.find((i) => i.packageId === packageId)) ?? null;
856900

901+
// objectstack#30323 — the console's confirm for a local purge, with the
902+
// count this session knows the install left in place, when it knows one.
903+
const openLocalPurgeConfirm = () => {
904+
if (!localInstall) return;
905+
setPurgeConfirm({ target: 'local', count: sampleDataNotice(localInstall.manifestId)?.count ?? null });
906+
};
907+
857908
// The local-install menu and the two status banners, drawn by both the
858909
// catalog view and the marketplace-off local view below (objectui#11627).
859910
//
@@ -910,7 +961,7 @@ export function MarketplacePackagePage() {
910961
: t('marketplace.detail.addSampleData')}
911962
</DropdownMenuItem>
912963
<DropdownMenuItem
913-
onSelect={doPurgeLocalSampleData}
964+
onSelect={openLocalPurgeConfirm}
914965
disabled={sampleDataBusy !== null || !localInstall.withSampleData}
915966
className="text-destructive focus:text-destructive"
916967
>
@@ -944,6 +995,44 @@ export function MarketplacePackagePage() {
944995
</button>
945996
</div>
946997
);
998+
// objectstack#30323 — the purge confirm, in the console's own dialog. The
999+
// count line is drawn only when this session knows what the install loaded:
1000+
// the runtime serves no count of a package's sample rows after that answer.
1001+
const purgeConfirmDialog = (
1002+
<AlertDialog open={purgeConfirm !== null} onOpenChange={(open) => { if (!open) setPurgeConfirm(null); }}>
1003+
<AlertDialogContent data-testid="purge-sample-data-dialog">
1004+
<AlertDialogHeader>
1005+
<AlertDialogTitle>{t('marketplace.detail.purgeSampleData')}</AlertDialogTitle>
1006+
<AlertDialogDescription className="whitespace-pre-line">
1007+
{purgeConfirm?.count != null
1008+
? `${t('marketplace.detail.purgeConfirmAtMost', { count: purgeConfirm.count })}\n${t('marketplace.detail.purgeConfirm')}`
1009+
: t('marketplace.detail.purgeConfirm')}
1010+
</AlertDialogDescription>
1011+
</AlertDialogHeader>
1012+
<AlertDialogFooter>
1013+
<AlertDialogCancel>{t('common.cancel')}</AlertDialogCancel>
1014+
<AlertDialogAction
1015+
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
1016+
data-testid="purge-sample-data-confirm"
1017+
onClick={() => {
1018+
const target = purgeConfirm?.target;
1019+
setPurgeConfirm(null);
1020+
if (target === 'local') void doPurgeLocalSampleData();
1021+
else if (target === 'cloud') void doPurgeSampleData();
1022+
}}
1023+
>
1024+
{t('marketplace.detail.purgeSampleData')}
1025+
</AlertDialogAction>
1026+
</AlertDialogFooter>
1027+
</AlertDialogContent>
1028+
</AlertDialog>
1029+
);
1030+
// The banner that follows the installer to the app once they leave this
1031+
// page, for the package this page is about (`SampleDataLeaveBanner`).
1032+
const leaveBanner = hasNotificationProvider ? (
1033+
<SampleDataLeaveBanner manifestId={data?.package?.manifest_id ?? localInstall?.manifestId ?? null} />
1034+
) : null;
1035+
9471036
// objectui#12087 — the install-into-this-environment status, from the
9481037
// install answering until its app is served (or the wait expires). Drawn in
9491038
// the install dialog while it is open and on the page once it is closed, so
@@ -1009,6 +1098,29 @@ export function MarketplacePackagePage() {
10091098
<div className="flex-1">
10101099
{localResult.message}
10111100
{localResult.protocolNote ? <ProtocolCheckSkippedNote text={localResult.protocolNote} /> : null}
1101+
{/* objectstack#30323 — how many sample records the install loaded, and
1102+
the clear, right where the installer reads that it is installed. */}
1103+
{localResult.sampleData ? (
1104+
<div className="mt-2 whitespace-normal text-foreground" data-testid="install-sample-data">
1105+
<p>
1106+
{t('marketplace.detail.sampleDataLoaded', { count: localResult.sampleData.count })}
1107+
{localResult.sampleData.reinstall ? <>{' '}{t('marketplace.detail.sampleDataReloaded')}</> : null}
1108+
</p>
1109+
{localInstall?.manifestId && !localInstall.notLoaded ? (
1110+
<Button
1111+
size="sm"
1112+
variant="outline"
1113+
className="mt-2"
1114+
onClick={openLocalPurgeConfirm}
1115+
disabled={sampleDataBusy !== null}
1116+
data-testid="install-sample-data-clear"
1117+
>
1118+
<Trash2 className="h-4 w-4 mr-1.5" aria-hidden="true" />
1119+
{t('marketplace.detail.purgeSampleData')}
1120+
</Button>
1121+
) : null}
1122+
</div>
1123+
) : null}
10121124
{/* ADR-0131 D6 — each protection lock the unmanaged copy dropped, as
10131125
the answer states it: the item, the lock and the package's reason
10141126
verbatim, so the operator reads why the vendor locked an item
@@ -1100,6 +1212,8 @@ export function MarketplacePackagePage() {
11001212
)}
11011213
{sampleDataNote}
11021214
{localResultNote(null)}
1215+
{purgeConfirmDialog}
1216+
{leaveBanner}
11031217
<MarketplaceDisabled />
11041218
</div>
11051219
);
@@ -1395,7 +1509,7 @@ export function MarketplacePackagePage() {
13951509
: t('marketplace.detail.addSampleData')}
13961510
</DropdownMenuItem>
13971511
<DropdownMenuItem
1398-
onSelect={doPurgeSampleData}
1512+
onSelect={() => setPurgeConfirm({ target: 'cloud', count: null })}
13991513
disabled={sampleDataBusy !== null || cloudSampleDataRefused || !cloudInstall.withSampleData}
14001514
className="text-destructive focus:text-destructive"
14011515
>
@@ -1415,6 +1529,8 @@ export function MarketplacePackagePage() {
14151529
{!installOpen && deployNote}
14161530

14171531
{localResultNote(pkg.manifest_id)}
1532+
{purgeConfirmDialog}
1533+
{leaveBanner}
14181534

14191535
{/* `min-w-0` on each cell: a grid item's automatic minimum is its content's
14201536
width, so a long line in the README would widen the page past its edge
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The reach to the sample-data clear from the installed app's own pages
5+
* (objectstack#30323), through the console's generic banner: a `banner`
6+
* notification (`NotificationBanners`, drawn above every page's content by
7+
* `ConsoleLayout`), not a block of its own.
8+
*
9+
* While the installer is on the package page, the install note there carries
10+
* the count and the clear, so no banner stands. When they leave it, to the
11+
* app they just installed or anywhere else, a banner follows: the app has
12+
* sample data, with a "Clear sample data" action that brings them back to the
13+
* package page with the console's confirm open. Clearing withdraws it, and so
14+
* does coming back to the page; dismissing it is the installer's choice.
15+
*
16+
* It is raised only for a package this session recorded loading sample data
17+
* into (`sampleDataNotice.ts`), and only while a notification provider is
18+
* mounted: the page renders this component under that guard, since
19+
* `useNotifications()` throws outside one.
20+
*/
21+
22+
import { useEffect, useRef } from 'react';
23+
import { useNavigate } from 'react-router-dom';
24+
import { useNotifications } from '@object-ui/react';
25+
import { useObjectTranslation } from '@object-ui/i18n';
26+
import { attachBanner, requestClearConfirm, sampleDataNotice, withdrawBanner } from './sampleDataNotice.js';
27+
28+
export function SampleDataLeaveBanner({ manifestId }: { manifestId: string | null }) {
29+
const { notify, dismiss } = useNotifications();
30+
const { t } = useObjectTranslation();
31+
const navigate = useNavigate();
32+
// The cleanup below runs once the page is gone, so it reads the functions
33+
// of the last render rather than those of the render that set it up.
34+
const latest = useRef({ notify, dismiss, t, navigate });
35+
useEffect(() => {
36+
latest.current = { notify, dismiss, t, navigate };
37+
});
38+
39+
useEffect(() => {
40+
if (!manifestId) return;
41+
// Back on the package page: its install note speaks for the sample data.
42+
withdrawBanner(manifestId);
43+
return () => {
44+
const notice = sampleDataNotice(manifestId);
45+
if (!notice) return;
46+
const { notify: raise, dismiss: drop, t: tr, navigate: go } = latest.current;
47+
const id = raise({
48+
title: tr('marketplace.detail.sampleDataBannerTitle', { name: notice.name }),
49+
message: tr('marketplace.detail.sampleDataBannerMessage'),
50+
severity: 'info',
51+
displayType: 'banner',
52+
actions: [{
53+
label: tr('marketplace.detail.purgeSampleData'),
54+
variant: 'primary',
55+
onClick: () => {
56+
requestClearConfirm(notice.manifestId);
57+
go(notice.path);
58+
},
59+
}],
60+
});
61+
attachBanner(notice.manifestId, () => drop(id));
62+
};
63+
}, [manifestId]);
64+
65+
return null;
66+
}

0 commit comments

Comments
 (0)