Skip to content

Commit d9aff15

Browse files
fix(app-shell): Setup record pages carry the managed-by note on the header chip (#13385) (#13424)
Closes #13385 Clause-②: yes (widening: RecordContextValue gains optional objectLabelNote; RecordTitleChip props gain optional objectLabelNote; nothing is refused) Closes #12614 This carries out the maintainer's ruling **B** on #13385 (comment 6369308948), which amends #12194 option a for Setup record pages only. #12614's remaining item is item 2, and this is that change. Item 1 was done in #23838. ## What changed - **Setup record pages draw no floating `ManagedByBadge`.** `RecordDetailView` leaves the badge out of `sharedChrome` (the floating row and the print chrome row) when the page is inside Setup. - **The header's object label carries the note instead.** `RecordDetailView` hands the badge's note to `RecordContextProvider` as the new host-injected `objectLabelNote`. `PageHeaderRenderer` (`page:header`) forwards it to `RecordTitleChip`. - **The chip shows it on hover and focus.** With a note, `RecordTitleChip` makes its object-label span a focusable (`tabIndex=0`) tooltip trigger, using the same `Tooltip` setup it already uses for copy-id. The tooltip reads e.g. "Organization · Managed by the identity provider" (zh: 「组织 · 由身份提供方管理」). The note is also the span's `aria-describedby`, pointing at an `sr-only` sibling, so the description is there whether or not the tooltip is open. Without a note, the label draws exactly as before (pinned on its exact HTML). - **`ManagedByBadge.tsx`** gains `useManagedByNote(managedBy)`, which shares the variant lookup with the badge. Its docblock records the Setup carve-out. - **No other changes.** List headers (`ObjectView`) and every record page outside Setup keep the badge unchanged. No shadcn file is touched, and no locale key is added. Both new members have doc comments saying they are host-injected and what they show. `RecordContextValue` has no zod mirror. It does have a type-level value-shape pin (`RecordContext.valueShape.pin.test.tsx`: the `MEMO_DEP_KEYS` must equal `keyof RecordContextValue`), and that pin went red under type-check until the new key was listed. The key is now in the provider's memo dependency list and in that pin. `RecordTitleChip` props have no mirror or snapshot. Docs: `packages/components/README.md` gains a short section on the label's host note. ## Judgment calls 1. **How Setup is detected: from the route.** `isSetupAppSegment(appName)` matches both the package id `com.objectstack.setup` and the name `setup`. It is the helper `ObjectView` already uses for its Setup-only list shape. A `sys_*` object opened in another app keeps the floating badge, as does a page with no `:appName`. 2. **Note text: the badge's existing tooltip title** (`managedByBadge.KEY.title`, e.g. `betterAuth.title`: 「由身份提供方管理」 / "Managed by the identity provider"). The `body` strings are paragraph-length. `platform` (and no value, or an unknown value) gives no note, as the badge draws nothing for them. No new locale keys, so no parity change. 3. **Gate kept.** The note sits behind the same `useCanAuthorMetadata()` gate as the badge, so a caller who could not see the badge sees no note either. 4. **Changeset levels:** `@object-ui/react` minor and `@object-ui/components` minor, because each adds an optional member to a published type. This follows the precedent of #13216, which scored `RecordTitleChip`'s optional `titleNode` minor. `@object-ui/app-shell` is patch. There is one changeset file and no `major`, and `check-changeset-no-major` is green. 5. **Surface:** the seat approved widening the declared surface by three files (`RecordContext.tsx`, `containers.tsx` (`PageHeaderRenderer`) and `RecordTitleChip.tsx`), because the chip is drawn by `page:header` in `@object-ui/components`, and `RecordDetailView` can only reach it through the host-injected `RecordContext`. The README section and the value-shape pin follow from those files. ## Tests New: - `packages/components/src/__tests__/record-title-chip.objectLabelNote-13385.test.tsx` (6): CONTROL, the label is byte-identical without a note (no focus stop, no `aria-describedby`); with a note, the label is a focusable trigger described by the note; focusing it opens a tooltip reading "Organization · NOTE"; a note with no label draws nothing; `PageHeaderRenderer` forwards the note from the context; CONTROL, a context with no note gives the plain label. - `packages/app-shell/src/views/RecordDetailView.setupManagedByChip-13385.test.tsx` (5), mounted on the real `/apps/:appName/:objectName/record/:recordId` route: a Setup `sys_organization` page (`com.objectstack.setup`, and `setup`) draws no floating badge and its header chip carries "Managed by the identity provider"; CONTROL, a business-app (`crm`) record page still draws the floating badge for an author, with no chip note; CONTROL, an end user in Setup sees neither; CONTROL, a `platform` object in Setup gives no note. - `packages/app-shell/src/views/ObjectView.setupListBadge-13385.test.tsx` (2): CONTROL, the list header still draws the badge for an author in Setup and in a business app. `ObjectView.tsx` itself is not in the diff. Updated: `RecordContext.valueShape.pin.test.tsx` lists `objectLabelNote`. Results: - **Every `RecordDetailView.*` test, every `*managedByBadge*` test (ObjectView, RecordDetailView, RecordFormPage), `page-header*` and `record-title-chip*`:** 98 files, 722 tests passed (`--maxWorkers=2`). This run was on the first commit, which is the same code as HEAD; the second commit changes only test files. - **`packages/react/src/context/`:** 13 files, 139 tests passed. - **Type-check** (`turbo run type-check --filter=@object-ui/react --filter=@object-ui/components --filter=@object-ui/app-shell`): 32/32 tasks successful. - **ESLint on touched files:** 0 errors (warnings only, all already in the base files). - **Gates:** `check:new-line-citations` reports 0 new; `check-changeset-presence` and `check-changeset-no-major` are green. **Ablation** (each restored from HEAD, and `git diff HEAD` empty afterwards): - With the Setup condition forced off in `RecordDetailView`, the 2 Setup cases went red and the other 5 in those two files stayed green. - With `RecordTitleChip` drawing the plain label whatever the note, 3 of 6 went red (the trigger, the tooltip and the header forward cases); the two CONTROLs and the no-label case stayed green. - With the forward removed from `PageHeaderRenderer`, only the forward case went red (1 of 6). **Screenshots:** not taken. Booting a Setup rig (objectstack dev server, console and a seeded admin) did not fit the time box. The 1280 px light and dark screenshots from the done-when are still owed. - [x] Adds no product-specific widget, dialog, hook or string (see AGENTS.md › Product-neutral renderer) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ad74e98 commit d9aff15

11 files changed

Lines changed: 643 additions & 10 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@object-ui/react': minor
3+
'@object-ui/components': minor
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
A record page inside the Setup app no longer draws the floating managed-by badge (the amber "Identity" chip at the top-right of an organization, team, business unit or user record) (objectui#13385). The header's object label ("Organization") carries the badge's note instead: hovering or focusing it shows "Organization · Managed by the identity provider", and the note is the label's accessible description. The note is the badge's own tooltip title, under the same gate: only a caller who can author metadata sees it, and a `platform` object shows none. Every record page outside Setup, a `sys_*` object opened in another app included, and every list header keep the badge unchanged.
8+
9+
`RecordContextValue` (`@object-ui/react`) gains an optional, host-injected `objectLabelNote`, which `page:header` forwards to `RecordTitleChip`. `RecordTitleChip` (`@object-ui/components`) gains an optional `objectLabelNote` prop: with it the object label becomes a focusable tooltip trigger described by the note; without it the label draws exactly as before.

‎packages/app-shell/src/components/ManagedByBadge.tsx‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js';
5959
* set (a backend whose `/me/permissions` omits `systemPermissions`, or no
6060
* permission provider at all) fails open, and the badge draws as before.
6161
*
62+
* ## Setup record pages carry it on the header chip instead (objectui#13385)
63+
*
64+
* A record page inside the Setup app draws no badge: the header already names
65+
* the object (「组织」 / "Organization"), and a second chip floating outside the
66+
* page tree repeated it. That page hands `useManagedByNote()` — the badge's
67+
* tooltip title, under the same gate — to the header's object-label chip,
68+
* which shows it on hover and focus. The list header and every record page
69+
* outside Setup keep the badge unchanged (maintainer ruling on objectui#13385,
70+
* option B; it amends objectui#12194 option a for Setup record pages only).
71+
*
6272
* What an end user needs is said elsewhere, and none of it reads this badge:
6373
* the toolbar hides the affordances the bucket closes, a locked form names
6474
* the missing permission above its fields (plugin-form's
@@ -156,17 +166,41 @@ const VARIANTS: Record<VariantKey, Variant> = {
156166
},
157167
};
158168

169+
/**
170+
* The variant a `managedBy` value draws, or `null` for none: no value,
171+
* `platform` (user-owned business data), or a value outside the union.
172+
* ADR-0103 / objectstack#3355 — the bucket IS the variant; nothing to derive.
173+
*/
174+
function variantOf(managedBy: string | undefined): Variant | null {
175+
if (!managedBy || managedBy === 'platform') return null;
176+
return VARIANTS[managedBy as VariantKey] ?? null;
177+
}
178+
179+
/**
180+
* The badge's one-line note for a `managedBy` bucket — its tooltip TITLE,
181+
* from the same `managedByBadge.<key>.title` locale key — for a host that
182+
* carries the note somewhere other than the badge (objectui#13385: a Setup
183+
* record page puts it on the header's object-label chip and draws no badge).
184+
*
185+
* Same answer as the badge, under the same gate: `null` for a caller who
186+
* cannot author metadata (objectui#12194) and for every bucket the badge
187+
* draws nothing for (`platform`, no value, an unknown value).
188+
*/
189+
export function useManagedByNote(managedBy: string | undefined): string | null {
190+
const { t } = useObjectTranslation();
191+
const canAuthor = useCanAuthorMetadata();
192+
if (!canAuthor) return null;
193+
const variant = variantOf(managedBy);
194+
if (!variant) return null;
195+
return t(`managedByBadge.${variant.i18nKey}.title`, { defaultValue: variant.title });
196+
}
197+
159198
export function ManagedByBadge({ managedBy, label, className }: ManagedByBadgeProps) {
160199
const { t } = useObjectTranslation();
161200
// objectui#12194 — an authoring aid: nothing for a caller who cannot author.
162201
const canAuthor = useCanAuthorMetadata();
163202
if (!canAuthor) return null;
164-
if (!managedBy || managedBy === 'platform') return null;
165-
// ADR-0103 — a `system` object that opened any write is admin/user-writable
166-
// data, not an engine-owned monitoring surface: pick the writable variant/copy.
167-
// objectstack#3355 — the bucket IS the variant now; nothing to derive.
168-
const variantKey = managedBy as VariantKey;
169-
const variant = VARIANTS[variantKey];
203+
const variant = variantOf(managedBy);
170204
if (!variant) return null;
171205
const Icon = variant.icon;
172206
const display = label ?? 'better-auth';
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectui#13385 — CONTROL: the list header keeps its lifecycle badge inside
11+
* Setup.
12+
*
13+
* The maintainer's ruling on objectui#13385 (option B) moves the badge's note
14+
* onto the header chip for Setup RECORD pages only; the list header
15+
* (`ObjectView`) keeps `ManagedByBadge` exactly as objectui#12194 left it, under
16+
* its `useCanAuthorMetadata` gate. This file pins that the Setup carve-out did
17+
* not reach the list: an author on a Setup list of a `better-auth` object sees
18+
* the badge, as on any other app's list.
19+
*
20+
* Direction, written before the run: GREEN before and after objectui#13385 —
21+
* it is a control; it goes RED only if the Setup condition is applied to the
22+
* list header too.
23+
*/
24+
25+
import * as React from 'react';
26+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
27+
import { render, cleanup, screen } from '@testing-library/react';
28+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
29+
import { createI18n, I18nProvider } from '@object-ui/i18n';
30+
import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/permissions';
31+
32+
vi.mock('@object-ui/auth', async (importOriginal) => ({
33+
...(await importOriginal<Record<string, unknown>>()),
34+
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null }),
35+
useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }),
36+
createAuthenticatedFetch: () => vi.fn(),
37+
}));
38+
39+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
40+
...(await importOriginal<Record<string, unknown>>()),
41+
useRealtimeSubscription: () => ({ lastMessage: null }),
42+
useConflictResolution: () => ({ hasConflicts: false, resolveAllConflicts: () => {} }),
43+
}));
44+
45+
vi.mock('sonner', () => ({
46+
toast: Object.assign(vi.fn(), {
47+
success: vi.fn(), error: vi.fn(), info: vi.fn(),
48+
warning: vi.fn(), loading: vi.fn(), dismiss: vi.fn(),
49+
}),
50+
}));
51+
52+
// The list body: the badge is drawn in the title, outside it.
53+
vi.mock('@object-ui/plugin-view', async (importOriginal) => ({
54+
...(await importOriginal<Record<string, unknown>>()),
55+
ObjectView: () => null,
56+
ViewTabBar: () => null,
57+
ManageViewsDialog: () => null,
58+
}));
59+
60+
vi.mock('./MetadataInspector', () => ({
61+
MetadataPanel: () => null,
62+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
63+
}));
64+
vi.mock('./RecordDetailView', () => ({ RecordDetailView: () => null }));
65+
66+
import { ObjectView } from './ObjectView';
67+
import { ExpressionProvider } from '../providers/ExpressionProvider';
68+
69+
const FIELDS = {
70+
id: { type: 'text', label: 'Id' },
71+
name: { type: 'text', label: 'Name' },
72+
};
73+
74+
const OBJECTS = [
75+
{ name: 'auth_user_12194', label: 'User', pluralLabel: 'Users', managedBy: 'better-auth', fields: FIELDS },
76+
{ name: 'plain_note_12194', label: 'Note', pluralLabel: 'Notes', fields: FIELDS },
77+
];
78+
79+
/** A `/me/permissions` answer holding exactly `held`. */
80+
function answer(held: string[]): MePermissionsResponse {
81+
return {
82+
authenticated: true,
83+
userId: 'u1',
84+
tenantId: null,
85+
roles: [],
86+
permissionSets: [],
87+
systemPermissions: held,
88+
objects: { '*': { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true } },
89+
fields: {},
90+
};
91+
}
92+
93+
/** An authoring caller. */
94+
const AUTHOR = answer(['manage_metadata']);
95+
96+
beforeEach(() => {
97+
vi.stubGlobal(
98+
'fetch',
99+
vi.fn(async () =>
100+
new Response(JSON.stringify({ data: [] }), {
101+
status: 200,
102+
headers: { 'content-type': 'application/json' },
103+
}),
104+
),
105+
);
106+
});
107+
108+
afterEach(() => {
109+
cleanup();
110+
vi.unstubAllGlobals();
111+
});
112+
113+
/**
114+
* Mount the list page for `objectName` under `perms`, wait for its H1 to read
115+
* `title`, and return the bucket of every badge on the page.
116+
*/
117+
async function badgeBuckets(app: string, objectName: string, title: string, perms: MePermissionsResponse) {
118+
const i18n = createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false });
119+
const dataSource = {
120+
find: vi.fn(async () => ({ data: [], total: 0 })),
121+
findOne: vi.fn(async () => null),
122+
create: vi.fn(async () => ({})),
123+
update: vi.fn(async () => ({})),
124+
delete: vi.fn(async () => ({})),
125+
} as never;
126+
render(
127+
<I18nProvider instance={i18n}>
128+
<MePermissionsProvider initialPermissions={perms}>
129+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'user' }}>
130+
<MemoryRouter initialEntries={[`/apps/${app}/${objectName}`]}>
131+
<Routes>
132+
<Route
133+
path="/apps/:appName/:objectName"
134+
element={<ObjectView dataSource={dataSource} objects={OBJECTS} onEdit={() => {}} />}
135+
/>
136+
</Routes>
137+
</MemoryRouter>
138+
</ExpressionProvider>
139+
</MePermissionsProvider>
140+
</I18nProvider>,
141+
);
142+
const heading = await screen.findByRole('heading', { level: 1 }, { timeout: 5000 });
143+
expect(heading.textContent).toContain(title);
144+
return Array.from(document.querySelectorAll('[data-testid="managed-by-badge"]')).map((b) =>
145+
b.getAttribute('data-bucket'),
146+
);
147+
}
148+
149+
describe('ObjectView — the list header keeps the badge inside Setup (objectui#13385 control)', () => {
150+
it('an author on a Setup list of a better-auth object sees the badge', async () => {
151+
expect(await badgeBuckets('com.objectstack.setup', 'auth_user_12194', 'Users', AUTHOR)).toEqual(['better-auth']);
152+
});
153+
154+
it('the same list in a business app draws it the same way', async () => {
155+
expect(await badgeBuckets('crm', 'auth_user_12194', 'Users', AUTHOR)).toEqual(['better-auth']);
156+
});
157+
});

0 commit comments

Comments
 (0)