Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/34094-marketplace-suggested-set-label.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@object-ui/app-shell': patch
---

fix(console): the Marketplace package page names a suggested binding's permission set by its label

Clause-②: no
Metadata-protocol: none

After a package that suggests a default audience binding is installed, the Marketplace package page shows "this app suggests granting SET to Everyone" with Grant and Dismiss, and later the accepted line with Revoke. Its prompt, its state lines and its Grant, Dismiss, Revoke and Reopen toasts named the permission set by its machine name (`crm_user`). They now name it by its label (`CRM user`), read from the package's own permission sets as this runtime serves them (`list('permission', { packageId })`, the read the Studio Access rail makes). A set with no label, or a read that is refused or fails, names the set by its machine name, with no error shown.

The Studio Access mount of the same banner and this page now draw the name through one shared helper, `suggestedSetLabel` (`components/suggestedSetLabel.ts`), so the two mounts cannot name the same set differently. No locale keys, props or exports change.
68 changes: 68 additions & 0 deletions ui/packages/app-shell/src/components/suggestedSetLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

import { useEffect, useState } from 'react';
import type { SuggestedBinding } from '../services/suggestedBindingsApi.js';
import { useMetadataClient } from '../views/metadata-admin/useMetadata.js';

/**
* How a suggested audience binding (ADR-0090 D5) names its permission set to
* a person: by the set's label (`ux-conventions.labels-over-machine-names`).
*
* A suggestion row carries only `permission_set_name`, so every mount of
* `SuggestedBindingsPanel` supplies the sets it can read and draws the
* prompt, the toasts and the state lines through this one function. A set
* the mount did not read, or one with an empty label, is named by its machine
* name.
*/
export interface PermissionSetLabelSource {
name: string;
label?: string;
}

export function suggestedSetLabel(
s: Pick<SuggestedBinding, 'permission_set_name'>,
sets: ReadonlyArray<PermissionSetLabelSource>,
): string {
return sets.find((p) => p.name === s.permission_set_name)?.label || s.permission_set_name;
}

/**
* The permission sets a package ships, as this runtime serves them, for a
* mount that holds no list of its own. A suggestion names one of the
* package's own sets (a set the package declares `isDefault`), so the read is
* scoped to the package server-side, the same `client.list('permission',
* { packageId })` the Studio Access rail makes.
*
* Read once per mount and per package, beside the panel's own read of the
* suggestions: a mount drawn right after an install reads the sets the
* install registered. A refused or failed read answers no sets, and every set
* is then named by its machine name.
*/
export function usePackagePermissionSets(packageId: string): ReadonlyArray<PermissionSetLabelSource> {
const client = useMetadataClient();
const [sets, setSets] = useState<ReadonlyArray<PermissionSetLabelSource>>([]);
// Keyed on the `packageId` primitive; the client is read through the
// effect's closure, never as a dependency (ui/AGENTS.md #10).
useEffect(() => {
let cancelled = false;
(client.list('permission', { packageId }) as Promise<Array<Record<string, unknown>> | null | undefined>)
.then((rows) => {
if (cancelled) return;
const next: PermissionSetLabelSource[] = [];
for (const row of rows ?? []) {
const name = typeof row?.name === 'string' ? row.name : '';
if (!name) continue;
next.push({ name, label: typeof row.label === 'string' ? row.label : undefined });
}
setSets(next);
})
.catch(() => {
/* refused or unavailable: every set is named by its machine name */
});
return () => {
cancelled = true;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [packageId]);
return sets;
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import { waitForServedApp, type ServedApp } from './waitForServedApp.js';
import { SuggestedBindingsPanel, type SuggestedBindingsStrings } from '../../components/SuggestedBindingsPanel.js';
import { ConnectorCredentialsStep } from './ConnectorCredentialsStep.js';
import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js';
import { suggestedSetLabel, usePackagePermissionSets } from '../../components/suggestedSetLabel.js';
import { errorCodeIs } from '@object-ui/types';
import { readTargetNamespaceRefusal } from './targetNamespaceRefusal.js';
import { MarketplaceNamespaceGate } from './MarketplaceNamespaceGate.js';
Expand Down Expand Up @@ -174,6 +175,43 @@ function versionEntryId(version: string): string {
return `marketplace-version-${version}`;
}

/**
* ADR-0090 D5 — a package's suggested audience bindings ("this app suggests
* granting SET to Everyone") on this page, with the deployment's decision on
* each. Accept/dismiss/revoke need `manage_metadata` server-side; the panel
* renders nothing for a caller without it (the list answers 403).
*
* The prompt, the toasts and the state lines name the set by its label
* (`suggestedSetLabel`), read from the package's own sets as this runtime
* serves them. The read is made on mount, as the panel's own read of the
* suggestions is, so a mount drawn after an install reads what it registered.
*/
function PackageSuggestedBindings({ packageId, className }: { packageId: string; className?: string }) {
const { t } = useObjectTranslation();
const sets = usePackagePermissionSets(packageId);
const set = (s: SuggestedBinding) => suggestedSetLabel(s, sets);
const strings: SuggestedBindingsStrings = {
describe: (s) =>
t(s.anchor === 'guest' ? 'marketplace.suggestedBindings.promptGuest' : 'marketplace.suggestedBindings.promptEveryone', { set: set(s) }),
confirm: t('marketplace.suggestedBindings.confirm'),
confirming: t('marketplace.suggestedBindings.confirming'),
dismiss: t('marketplace.suggestedBindings.dismiss'),
confirmedToast: (s) => t('marketplace.suggestedBindings.confirmedToast', { set: set(s), anchor: s.anchor }),
dismissedToast: (s) => t('marketplace.suggestedBindings.dismissedToast', { set: set(s) }),
guestUnsupported: t('marketplace.suggestedBindings.guestUnsupported'),
acceptedState: (s) => t('marketplace.suggestedBindings.acceptedState', { set: set(s) }),
notInForceState: (s) => t('marketplace.suggestedBindings.notInForceState', { set: set(s) }),
dismissedState: (s) => t('marketplace.suggestedBindings.dismissedState', { set: set(s) }),
revoke: t('marketplace.suggestedBindings.revoke'),
revoking: t('marketplace.suggestedBindings.revoking'),
revokedToast: (s) => t('marketplace.suggestedBindings.revokedToast', { set: set(s) }),
reopen: t('marketplace.suggestedBindings.reopen'),
reopening: t('marketplace.suggestedBindings.reopening'),
reopenedToast: (s) => t('marketplace.suggestedBindings.reopenedToast', { set: set(s) }),
};
return <SuggestedBindingsPanel packageId={packageId} strings={strings} className={className} />;
}

/**
* The page under the frame that fetches its strings first — the
* `marketplace` namespace (`MarketplaceNamespaceGate.tsx` says why).
Expand All @@ -196,37 +234,6 @@ function MarketplacePackagePageBody() {
// Dates and numbers on this surface read the display locale; a bare
// `toLocale*()` call used the MACHINE's locale (objectui#9909).
const displayLocale = useDisplayLocale();
// ADR-0090 D5 — install-time suggested audience bindings ("this app
// suggests granting <set> to Everyone"), surfaced right after a
// successful install into THIS runtime, with the deployment's decision on
// each. Accept/dismiss/revoke need `manage_metadata` server-side; the panel
// renders nothing for a caller without it (the list answers 403).
const suggestionStrings: SuggestedBindingsStrings = {
describe: (s: SuggestedBinding) =>
t(s.anchor === 'guest' ? 'marketplace.suggestedBindings.promptGuest' : 'marketplace.suggestedBindings.promptEveryone', { set: s.permission_set_name }),
confirm: t('marketplace.suggestedBindings.confirm'),
confirming: t('marketplace.suggestedBindings.confirming'),
dismiss: t('marketplace.suggestedBindings.dismiss'),
confirmedToast: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.confirmedToast', { set: s.permission_set_name, anchor: s.anchor }),
dismissedToast: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.dismissedToast', { set: s.permission_set_name }),
guestUnsupported: t('marketplace.suggestedBindings.guestUnsupported'),
acceptedState: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.acceptedState', { set: s.permission_set_name }),
notInForceState: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.notInForceState', { set: s.permission_set_name }),
dismissedState: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.dismissedState', { set: s.permission_set_name }),
revoke: t('marketplace.suggestedBindings.revoke'),
revoking: t('marketplace.suggestedBindings.revoking'),
revokedToast: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.revokedToast', { set: s.permission_set_name }),
reopen: t('marketplace.suggestedBindings.reopen'),
reopening: t('marketplace.suggestedBindings.reopening'),
reopenedToast: (s: SuggestedBinding) =>
t('marketplace.suggestedBindings.reopenedToast', { set: s.permission_set_name }),
};
const basePath = appName ? `/apps/${appName}` : '';
const { refresh: refreshMetadata } = useMetadata();
// The adapter `MetadataProvider` reads through: the deploy wait asks the
Expand Down Expand Up @@ -1065,7 +1072,7 @@ function MarketplacePackagePageBody() {
&& ((localInstall !== null && !localInstall.notLoaded) || cloudInstall !== null)
&& !installOpen
&& !resultCarriesPanel ? (
<SuggestedBindingsPanel packageId={manifestId} strings={suggestionStrings} />
<PackageSuggestedBindings packageId={manifestId} />
) : null;

// objectstack#30616 — the runtime's count of the sample rows a purge of this
Expand Down Expand Up @@ -1336,7 +1343,7 @@ function MarketplacePackagePageBody() {
its suggested audience bindings are confirmable right here. Not
for an unmanaged copy: nothing is registered under the package. */}
{localResult.ok && suggestFor && !localResult.unmanaged ? (
<SuggestedBindingsPanel packageId={suggestFor} strings={suggestionStrings} className="mt-2" />
<PackageSuggestedBindings packageId={suggestFor} className="mt-2" />
) : null}
{/* The package's connector credentials that still need an
administrator: set each one here, or skip it for Setup. */}
Expand Down Expand Up @@ -2134,7 +2141,7 @@ function MarketplacePackagePageBody() {
{deploy?.phase === 'served'
&& getRuntimeConfig().defaultEnvironmentId
&& getRuntimeConfig().defaultEnvironmentId === selectedEnv && (
<SuggestedBindingsPanel packageId={pkg.manifest_id} strings={suggestionStrings} />
<PackageSuggestedBindings packageId={pkg.manifest_id} />
)}

{/* The package's connector credentials, read from this runtime's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
* - CONTROL: a package not installed here does not read the list at all;
* - a list refused `403` (a caller without `manage_metadata`) renders no
* panel and no error.
*
* objectstack#34094 — the prompt and the Grant / Dismiss / Revoke toasts
* name the set by the label the package's own sets carry (read through the
* metadata client, stubbed here), the machine name only when the set has no
* label (CONTROL).
*/

import '@testing-library/jest-dom/vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';

const PKG = 'app.example.crm';

Expand All @@ -41,6 +46,9 @@ const api = vi.hoisted(() => ({
reopen: vi.fn(),
}));

// The package's permission sets as the metadata client lists them.
const meta = vi.hoisted(() => ({ list: vi.fn() }));

vi.mock('react-router-dom', () => ({
useNavigate: () => vi.fn(),
useParams: () => ({ packageId: 'pkg_1' }),
Expand All @@ -52,15 +60,21 @@ vi.mock('@object-ui/auth', async (importOriginal) => ({
useAuth: () => ({ activeOrganization: { id: 'org_1' } }),
}));

// `t` echoes the KEY, as the sibling suites do.
// `t` echoes the KEY, as the sibling suites do, and the interpolation values
// after it, so a pin reads which set a string names.
vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useObjectTranslation: () => ({
t: (key: string) => `«${key}»`,
t: (key: string, values?: Record<string, unknown>) => `«${key}»${values ? ` ${JSON.stringify(values)}` : ''}`,
language: 'en',
}),
}));

vi.mock('../../../views/metadata-admin/useMetadata', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useMetadataClient: () => meta,
}));

vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() } }));
vi.mock('../../../assistant/assistantBus', () => ({ emitMetadataRefresh: () => {} }));
vi.mock('../../../providers/MetadataProvider', () => ({ useMetadata: () => ({ refresh: () => {} }) }));
Expand Down Expand Up @@ -147,6 +161,7 @@ beforeEach(() => {
state.cloudInstall = null;
state.localInstalls = [];
state.installLocal = false;
meta.list.mockResolvedValue([]);
});

afterEach(() => {
Expand Down Expand Up @@ -219,3 +234,94 @@ describe('objectstack#33158 — an installed package page draws its suggested bi
expect(toast.error).not.toHaveBeenCalled();
});
});

describe('objectstack#34094 — the prompt and the toasts name the set by its label', () => {
const SETS = [
{ name: 'crm_user', label: 'CRM user' },
{ name: 'crm_admin', label: 'CRM admin' },
];
const ACCEPTED = { ...PENDING, status: 'confirmed' as const, deployment_decision: true };
const DISMISSED = { ...PENDING, status: 'dismissed' as const, deployment_decision: true };

const installed = () => {
state.cloudInstall = { installationId: 'inst_1', version: '6.1.2', withSampleData: false };
};
const successTexts = () => (toast.success as ReturnType<typeof vi.fn>).mock.calls.map((c) => String(c[0]));

it('the prompt names the label, read from the package\'s own sets', async () => {
installed();
meta.list.mockResolvedValue(SETS);
api.list.mockResolvedValue([PENDING]);
await boot();
render(<MarketplacePackagePage />);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(row).toHaveTextContent('"set":"CRM user"'));
expect(row).toHaveTextContent('«marketplace.suggestedBindings.promptEveryone»');
expect(row).not.toHaveTextContent('"set":"crm_user"');
expect(meta.list).toHaveBeenCalledWith('permission', { packageId: PKG });
});

it('Grant, then Revoke: both toasts and the accepted line name the label', async () => {
installed();
meta.list.mockResolvedValue(SETS);
api.list.mockResolvedValue([PENDING]);
api.confirm.mockResolvedValue({ suggestion: ACCEPTED, bindingCreated: true });
api.dismiss.mockResolvedValue(DISMISSED);
await boot();
render(<MarketplacePackagePage />);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(row).toHaveTextContent('"set":"CRM user"'));

fireEvent.click(within(row).getByTestId('suggested-binding-confirm-crm_user'));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect(successTexts()[0]).toBe('«marketplace.suggestedBindings.confirmedToast» {"set":"CRM user","anchor":"everyone"}');
expect(row).toHaveTextContent('«marketplace.suggestedBindings.acceptedState» {"set":"CRM user"}');

fireEvent.click(within(row).getByTestId('suggested-binding-revoke-crm_user'));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(2));
expect(successTexts()[1]).toBe('«marketplace.suggestedBindings.revokedToast» {"set":"CRM user"}');
});

it('Dismiss: the toast names the label', async () => {
installed();
meta.list.mockResolvedValue(SETS);
api.list.mockResolvedValue([PENDING]);
api.dismiss.mockResolvedValue(DISMISSED);
await boot();
render(<MarketplacePackagePage />);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(row).toHaveTextContent('"set":"CRM user"'));
fireEvent.click(within(row).getByTestId('suggested-binding-dismiss-crm_user'));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect(successTexts()[0]).toBe('«marketplace.suggestedBindings.dismissedToast» {"set":"CRM user"}');
});

it('CONTROL: a set with no label is named by its machine name', async () => {
installed();
meta.list.mockResolvedValue([{ name: 'crm_user', label: '' }, { name: 'crm_admin', label: 'CRM admin' }]);
api.list.mockResolvedValue([PENDING]);
api.dismiss.mockResolvedValue(DISMISSED);
await boot();
render(<MarketplacePackagePage />);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(meta.list).toHaveBeenCalledTimes(1));
await new Promise((r) => setTimeout(r, 0));
expect(row).toHaveTextContent('«marketplace.suggestedBindings.promptEveryone» {"set":"crm_user"}');
fireEvent.click(within(row).getByTestId('suggested-binding-dismiss-crm_user'));
await waitFor(() => expect(toast.success).toHaveBeenCalledTimes(1));
expect(successTexts()[0]).toBe('«marketplace.suggestedBindings.dismissedToast» {"set":"crm_user"}');
});

it('CONTROL: a refused read of the sets names the set by its machine name, with no error', async () => {
installed();
meta.list.mockRejectedValue(refused(403, 'PERMISSION_DENIED', 'denied'));
api.list.mockResolvedValue([PENDING]);
await boot();
render(<MarketplacePackagePage />);
const row = await screen.findByTestId('suggested-binding-crm_user', undefined, { timeout: 8000 });
await waitFor(() => expect(meta.list).toHaveBeenCalledTimes(1));
await new Promise((r) => setTimeout(r, 0));
expect(row).toHaveTextContent('«marketplace.suggestedBindings.promptEveryone» {"set":"crm_user"}');
expect(toast.error).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ import { ObjectPicker } from '../metadata-admin/inspectors/ObjectPicker.js';
import { useDisplayLocale } from '@object-ui/i18n';
import { SuggestedBindingsPanel } from '../../components/SuggestedBindingsPanel.js';
import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js';
import { suggestedSetLabel as suggestedSetLabelOf } from '../../components/suggestedSetLabel.js';
import {
AppNavCanvas,
heldNavEntriesOf,
Expand Down Expand Up @@ -10858,8 +10859,7 @@ export function AccessPillar({
// (`ux-conventions.labels-over-machine-names`). The suggestions listed here
// are this package's own sets, which the rail read; a set the rail does not
// hold, or one with no label, is named by its machine name.
const suggestedSetLabel = (s: SuggestedBinding): string =>
perms.find((p) => p.name === s.permission_set_name)?.label || s.permission_set_name;
const suggestedSetLabel = (s: SuggestedBinding): string => suggestedSetLabelOf(s, perms);

return (
<div className="flex h-full flex-col">
Expand Down
Loading