Skip to content

Commit 12e039e

Browse files
committed
fix(app-shell): draw a served app label as served on every console surface that names an app
Claude-Session: https://claude.ai/code/session_01L6bhgX1ZNco5W3wXZFLVbh Co-authored-by: Claude <noreply@anthropic.com>
1 parent fdd0641 commit 12e039e

12 files changed

Lines changed: 143 additions & 53 deletions

File tree

‎ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import { Lock, PanelLeft } from 'lucide-react';
4040
// already reaches it through `PreviewDraftEmptyState`, so the eager graph
4141
// gains no new module.
4242
import { Button, DataEmptyState } from '@object-ui/components';
43-
import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
44-
import { resolveKeyedI18nLabel } from '../utils/index.js';
43+
import { useObjectTranslation } from '@object-ui/i18n';
44+
import { useServedAppLabel } from '../hooks/useServedAppLabel.js';
4545

4646
export interface AppNoAccessEmptyStateProps {
4747
/** The active app, as the console's metadata list carries it. */
@@ -65,9 +65,9 @@ export interface AppNoAccessEmptyStateProps {
6565

6666
export function AppNoAccessEmptyState({ app, setupPath, reason = 'no-navigation' }: AppNoAccessEmptyStateProps) {
6767
const { t } = useObjectTranslation();
68-
const { appLabel } = useObjectLabel();
68+
const { appLabel } = useServedAppLabel();
6969
// The same label the header's app switcher shows for this app.
70-
const label = appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) });
70+
const label = appLabel(app);
7171

7272
if (reason === 'menu-only') {
7373
return (

‎ui/packages/app-shell/src/console/ai/AiChatPage.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
1717
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
1818
import { useAuth } from '@object-ui/auth';
19-
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
19+
import { useObjectTranslation } from '@object-ui/i18n';
20+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
2021
import { toast } from 'sonner';
2122
import { Package as PackageIcon, Sparkles as SparklesIcon } from 'lucide-react';
2223
import { useAdapter } from '../../providers/AdapterProvider.js';
@@ -2181,7 +2182,7 @@ export function ChatPane({
21812182
// Narrow the loosely-typed provider apps once (see MetadataAppItem) so the
21822183
// derivations below read fields without per-access casts.
21832184
const metadataApps = apps as MetadataAppItem[] | undefined;
2184-
const { appLabel } = useObjectLabel();
2185+
const { appLabel } = useServedAppLabel();
21852186
// Fold-insensitive, measured: this walks every message irrespective of role
21862187
// and reads `draftReview`/`builderHandoff`, which the adapter spreads through.
21872188
const boundPackageId = useMemo(
@@ -2202,7 +2203,7 @@ export function ChatPane({
22022203
const app = (metadataApps ?? []).find(
22032204
(a) => a._packageId === boundPackageId,
22042205
);
2205-
return app ? appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) }) : boundPackageId;
2206+
return app ? appLabel(app) : boundPackageId;
22062207
}, [boundPackageId, metadataApps, appLabel, t]);
22072208

22082209
// ADR-0057 A1.b edit mode — the resolved name of the app being EDITED
@@ -2214,7 +2215,7 @@ export function ChatPane({
22142215
const app = (metadataApps ?? []).find(
22152216
(a) => a._packageId === editPackageId,
22162217
);
2217-
return app ? appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) }) : undefined;
2218+
return app ? appLabel(app) : undefined;
22182219
}, [editPackageId, metadataApps, appLabel, t]);
22192220

22202221
// objectui#11658 — the plan card's extend-mode scope chip names the existing
@@ -2223,7 +2224,7 @@ export function ChatPane({
22232224
const resolveAppLabel = useCallback(
22242225
(appName: string) => {
22252226
const app = (metadataApps ?? []).find((a) => a.name === appName);
2226-
return app ? appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) }) : undefined;
2227+
return app ? appLabel(app) : undefined;
22272228
},
22282229
[metadataApps, appLabel, t],
22292230
);
@@ -2387,7 +2388,7 @@ export function ChatPane({
23872388
if (!pkg || byPackage.has(pkg) || isPlatformBuiltinApp(app)) {
23882389
continue;
23892390
}
2390-
byPackage.set(pkg, appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) }));
2391+
byPackage.set(pkg, appLabel(app));
23912392
}
23922393
return Array.from(byPackage, ([id, label]) => ({ id, label }));
23932394
}, [metadataApps, appLabel, t]);

‎ui/packages/app-shell/src/console/home/AppCard.tsx‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import { Star, StarOff, ArrowUpRight } from 'lucide-react';
1010
import { Card, CardContent, Button, Badge } from '@object-ui/components';
11-
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
12-
import { resolveKeyedI18nLabel, appRouteSegment } from '../../utils/index.js';
11+
import { useObjectTranslation } from '@object-ui/i18n';
12+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
13+
import { appRouteSegment } from '../../utils/index.js';
1314
import { useFavorites } from '../../hooks/useFavorites.js';
1415
import { getIcon } from '../../utils/getIcon.js';
1516
import { cn } from '@object-ui/components';
@@ -40,12 +41,12 @@ function hashStr(s: string): number {
4041

4142
export function AppCard({ app, onClick, isFavorite, index = 0 }: AppCardProps) {
4243
const { t } = useObjectTranslation();
43-
const { appLabel, appDescription } = useObjectLabel();
44+
const { appLabel, appDescription } = useServedAppLabel();
4445
const { toggleFavorite } = useFavorites();
4546

4647
const Icon = getIcon(app.icon);
47-
const label = appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) });
48-
const description = appDescription({ name: app.name, description: resolveKeyedI18nLabel(app.description, t) });
48+
const label = appLabel(app);
49+
const description = appDescription(app);
4950
const accent = ACCENTS[(hashStr(app.name) + index) % ACCENTS.length];
5051

5152
const handleToggleFavorite = (e: React.MouseEvent) => {

‎ui/packages/app-shell/src/console/home/HomeAppsStrip.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import { useMemo, useState, type ReactNode } from 'react';
4040
import { Link } from 'react-router-dom';
4141
import { LayoutGrid, Plus, Settings, Star } from 'lucide-react';
4242
import { cn } from '@object-ui/components';
43-
import { useDisplayLocale, useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
44-
import { resolveKeyedI18nLabel } from '../../utils/index.js';
43+
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
44+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
4545
import { appAddressSegment } from '../../utils/appRoute.js';
4646
import { getIcon } from '../../utils/getIcon.js';
4747
import { timeAgo } from '../../utils/relativeTime.js';
@@ -168,7 +168,7 @@ export function HomeAppsStrip({
168168
lastOpened?: ReadonlyMap<string, string>;
169169
}) {
170170
const { t } = useObjectTranslation();
171-
const { appLabel } = useObjectLabel();
171+
const { appLabel } = useServedAppLabel();
172172
const displayLocale = useDisplayLocale();
173173
const [showAll, setShowAll] = useState(false);
174174

@@ -228,7 +228,7 @@ export function HomeAppsStrip({
228228
{/* `-ml-2` puts the first icon under the heading: a tile pads its icon 8 px. */}
229229
<div className="-ml-2 flex flex-wrap gap-1">
230230
{visible.map((app) => {
231-
const label = appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) });
231+
const label = appLabel(app);
232232
const fav = favNames.has(app.name);
233233
const openedAgo = timeAgo(lastOpened?.get(app.name), displayLocale, TILE_OPENED_TIME_FORMAT);
234234
return (

‎ui/packages/app-shell/src/console/home/HomePage.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { useNavTargetLabel, type NavTargetLabelOptions } from '../../hooks/useNa
2424
import { readObjectsByName } from '../../hooks/useObjectPresence.js';
2525
import { useFavorites } from '../../hooks/useFavorites.js';
2626
import { useObjectTranslation } from '@object-ui/i18n';
27-
// Its own line: the line above is the pack-hook binding `perm-home-namespace-3546.test.tsx` reads.
28-
import { useObjectLabel } from '@object-ui/i18n';
27+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
2928
import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth';
3029
import { useAgents, isAskAgent, agentHasCapability } from '@object-ui/plugin-chatbot/core';
3130
// May this session author metadata? Shared with the chat surfaces since the
@@ -46,7 +45,6 @@ import {
4645
filterActiveApps,
4746
matchAppBySegment,
4847
resolveHostAppSegment,
49-
resolveKeyedI18nLabel,
5048
} from '../../utils/index.js';
5149
import { useInboxBell } from '../../hooks/useInboxBell.js';
5250
import { openInboxNotification } from '../../layout/openInboxNotification.js';
@@ -364,7 +362,7 @@ export function HomePage() {
364362
// objectstack#29121 — by name: the object a row names is read alone (as its
365363
// icon below is), so Home never loads the whole registry for its rows.
366364
const targetLabel = useNavTargetLabel(BY_NAME);
367-
const { appLabel } = useObjectLabel();
365+
const { appLabel } = useServedAppLabel();
368366
const { favorites } = useFavorites();
369367
const { user } = useAuth();
370368
const { isAdmin, isResolved: isAdminResolved } = useWorkspaceAdminStatus();
@@ -509,7 +507,7 @@ export function HomePage() {
509507
item.type === 'record' && objectName
510508
? targetLabel({ kind: 'object', objectName }) ?? objectName
511509
: recentItemTypeLabel(t, item.type),
512-
app: app ? appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) }) : undefined,
510+
app: app ? appLabel(app) : undefined,
513511
icon: typeof objectIcon === 'string' && objectIcon !== '' ? objectIcon : undefined,
514512
};
515513
};
@@ -804,7 +802,7 @@ export function HomePage() {
804802
settingsHref={setupApp ? setupPath : undefined}
805803
settingsLabel={
806804
setupApp
807-
? appLabel({ name: setupApp.name, label: resolveKeyedI18nLabel(setupApp.label, t) })
805+
? appLabel(setupApp)
808806
: undefined
809807
}
810808
lastOpened={lastOpened}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ import {
4646
} from '@object-ui/components';
4747
import { ArrowLeft, ExternalLink, Download, AlertCircle, Package, Trash2, MoreHorizontal, CheckCircle2, ArrowUpCircle, Database, Loader2 } from 'lucide-react';
4848
import { useWorkspaceAdminStatus } from '@object-ui/auth';
49-
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
49+
import { useObjectTranslation } from '@object-ui/i18n';
5050
import { useDisplayLocale } from '@object-ui/i18n';
51+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
5152
import { useAdapter } from '@object-ui/react';
5253
import { PackageIcon } from './PackageIcon.js';
5354
import { MarkdownText } from './MarkdownText.js';
@@ -84,7 +85,7 @@ import { useDependencyMissingText } from './dependencyMissing.js';
8485
import { getCloudBase, getRuntimeConfig, isMarketplaceEnabled } from '../../runtime-config.js';
8586
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
8687
import { useMetadata } from '../../providers/MetadataProvider.js';
87-
import { appRouteSegment, filterActiveApps, resolveKeyedI18nLabel } from '../../utils/index.js';
88+
import { appRouteSegment, filterActiveApps } from '../../utils/index.js';
8889
import { waitForServedApp, type ServedApp } from './waitForServedApp.js';
8990
import { SuggestedBindingsPanel, type SuggestedBindingsStrings } from '../../components/SuggestedBindingsPanel.js';
9091
import { ConnectorCredentialsStep } from './ConnectorCredentialsStep.js';
@@ -186,7 +187,7 @@ export function MarketplacePackagePage() {
186187
// The adapter `MetadataProvider` reads through: the deploy wait asks the
187188
// same `GET /meta/app` the cache would, without the cache persisting it.
188189
const adapter = useAdapter();
189-
const { appLabel } = useObjectLabel();
190+
const { appLabel } = useServedAppLabel();
190191
// The runtime's own answer, read once per render -- the same read the
191192
// catalog page makes (objectui#5504). `false` means this runtime mounts no
192193
// marketplace at all, so there is no package to fetch and nothing to
@@ -969,8 +970,8 @@ export function MarketplacePackagePage() {
969970
<Button size="sm" onClick={() => navigate(`/apps/${appRouteSegment(deployApp)}`)}>
970971
{t('marketplace.install.openApp', {
971972
name: appLabel({
973+
...deployApp,
972974
name: String(deployApp.name ?? appRouteSegment(deployApp)),
973-
label: resolveKeyedI18nLabel(deployApp.label, t),
974975
}),
975976
})}
976977
</Button>

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
Package, Search, Store, AlertCircle, CheckCircle2, Settings, Loader2, ChevronDown, Copy, Check,
2727
} from 'lucide-react';
2828
import { useWorkspaceAdminStatus } from '@object-ui/auth';
29-
import { useDisplayLocale, useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
29+
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
30+
import { useServedAppLabel } from '../../hooks/useServedAppLabel.js';
3031
import { useAdapter } from '@object-ui/react';
3132
import { PackageIcon } from './PackageIcon.js';
3233
import { MarketplaceAccessDenied } from './MarketplaceAccessDenied.js';
@@ -47,7 +48,7 @@ import {
4748
import { getCloudBase, getRuntimeConfig, isMarketplaceEnabled } from '../../runtime-config.js';
4849
import { PageHeader } from '../../layout/PageHeader.js';
4950
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
50-
import { appRouteSegment, filterActiveApps, resolveKeyedI18nLabel } from '../../utils/index.js';
51+
import { appRouteSegment, filterActiveApps } from '../../utils/index.js';
5152
import { waitForServedApp, type ServedApp } from './waitForServedApp.js';
5253
import { splitPackageSuffix } from './middleTruncate.js';
5354
import { useDependencyMissingText } from './dependencyMissing.js';
@@ -309,7 +310,7 @@ export function MarketplacePage() {
309310
const { isAdmin, isResolved } = useWorkspaceAdminStatus();
310311
const { t, language } = useObjectTranslation();
311312
const dependencyMissingText = useDependencyMissingText();
312-
const { appLabel } = useObjectLabel();
313+
const { appLabel } = useServedAppLabel();
313314
// The adapter `MetadataProvider` reads through: the deploy wait asks the
314315
// same `GET /meta/app` the cache would, without the cache persisting it.
315316
const adapter = useAdapter();
@@ -619,8 +620,8 @@ export function MarketplacePage() {
619620
<Button size="sm" onClick={() => navigate(`/apps/${appRouteSegment(orgDeployApp)}`)}>
620621
{t('marketplace.install.openApp', {
621622
name: appLabel({
623+
...orgDeployApp,
622624
name: String(orgDeployApp.name ?? appRouteSegment(orgDeployApp)),
623-
label: resolveKeyedI18nLabel(orgDeployApp.label, t),
624625
}),
625626
})}
626627
</Button>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
* useServedAppLabel — what an app is called, and how it describes itself, on
11+
* every console surface that names an app (objectstack#30311).
12+
*
13+
* An app the `/meta/app` read served is already translated: `translateApp` in
14+
* `@objectstack/spec` writes its `label` and `description` for the request's
15+
* locale, and for an overridden app (a `.custom` pair) in the ruled label
16+
* order, the override's own text kept over the base package's translation
17+
* (objectstack#30353). So a served label is drawn as given. Running the
18+
* client bundle's `apps.<name>.label` lookup over it was a second translation
19+
* pass in which the base package's string won a rename back.
20+
*
21+
* The bundle (`useObjectLabel().appLabel` / `appDescription`) is asked only
22+
* for text no server translated: a pending draft under `?preview=draft`
23+
* (the item carries `_draft: true`), a keyed label (`{ key, defaultValue }`,
24+
* resolved through `t` as before), or an app with no label or description at
25+
* all. An unedited app reads the same text as before, because the server
26+
* serves the bundle's translation for it.
27+
*/
28+
29+
import { useCallback, useMemo } from 'react';
30+
import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
31+
import { resolveKeyedI18nLabel } from '../utils/index.js';
32+
import { metadataText } from './useNavTargetLabel.js';
33+
34+
/** The members of an app record this hook reads. */
35+
export interface ServedAppSource {
36+
name: string;
37+
label?: unknown;
38+
description?: unknown;
39+
_draft?: unknown;
40+
}
41+
42+
type KeyedLabel = { key: string; defaultValue?: string; params?: Record<string, any> };
43+
44+
/** A console-keyed label (`{ key, defaultValue }`): a key, not served text. */
45+
function isKeyedLabel(value: unknown): value is KeyedLabel {
46+
return !!value && typeof value === 'object' && typeof (value as { key?: unknown }).key === 'string';
47+
}
48+
49+
/** `label` / `description` as the server translated it, or `undefined` when it served none. */
50+
function servedText(app: ServedAppSource, value: unknown, language: string | undefined): string | undefined {
51+
if (app._draft === true || isKeyedLabel(value)) return undefined;
52+
return metadataText(value, language);
53+
}
54+
55+
/** The bundle's input for a value that is not served text: a keyed label through `t`, else a plain string. */
56+
function bundleFallback(value: unknown, t: (key: string, options?: any) => string): string | undefined {
57+
if (isKeyedLabel(value)) return resolveKeyedI18nLabel(value, t);
58+
return typeof value === 'string' ? value : undefined;
59+
}
60+
61+
export interface ServedAppLabels {
62+
/** The app's display name: the served label, else the bundle's. */
63+
appLabel: (app: ServedAppSource) => string;
64+
/** The app's description: the served one, else the bundle's; `undefined` when neither names one. */
65+
appDescription: (app: ServedAppSource) => string | undefined;
66+
}
67+
68+
export function useServedAppLabel(): ServedAppLabels {
69+
const { language, t } = useObjectTranslation();
70+
const { appLabel: bundleAppLabel, appDescription: bundleAppDescription } = useObjectLabel();
71+
72+
const appLabel = useCallback(
73+
(app: ServedAppSource) =>
74+
servedText(app, app.label, language)
75+
?? bundleAppLabel({ name: app.name, label: bundleFallback(app.label, t) }),
76+
[language, t, bundleAppLabel],
77+
);
78+
const appDescription = useCallback(
79+
(app: ServedAppSource) =>
80+
servedText(app, app.description, language)
81+
?? bundleAppDescription({ name: app.name, description: bundleFallback(app.description, t) }),
82+
[language, t, bundleAppDescription],
83+
);
84+
return useMemo(() => ({ appLabel, appDescription }), [appLabel, appDescription]);
85+
}

‎ui/packages/app-shell/src/layout/AppHeader.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ import { AppSwitcher } from './AppSwitcher.js';
8585
import type { ConnectionState } from '@object-ui/data-objectstack';
8686
import { useAdapter } from '../providers/AdapterProvider.js';
8787
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
88+
import { useServedAppLabel } from '../hooks/useServedAppLabel.js';
8889
import type { BreadcrumbItem as BreadcrumbItemType } from '@object-ui/types';
8990
import { useAuth, getUserInitials } from '@object-ui/auth';
9091
import { useMetadata } from '../providers/MetadataProvider.js';
9192
import { useBundledReads } from '../providers/bundledReads.js';
9293
import { readItemPreferLocal, useReadItemsByName } from '../hooks/useObjectPresence.js';
93-
import { resolveKeyedI18nLabel, preferLocal, matchAppBySegment, appStudioRoutePath } from '../utils/index.js';
94+
import { preferLocal, matchAppBySegment, appStudioRoutePath } from '../utils/index.js';
9495
import { appAddressSegment } from '../utils/appRoute.js';
9596
import { getIcon } from '../utils/getIcon.js';
9697
import { useNavigationContext } from '../context/NavigationContext.js';
@@ -474,7 +475,8 @@ export function AppHeader({
474475
// Same signal as the FAB and the `/ai` route guard.
475476
const { enabled: aiEnabled } = useAiSurfaceEnabled();
476477
const { t, language } = useObjectTranslation();
477-
const { objectPluralLabel, dashboardLabel, pageLabel, reportLabel, viewLabel, appLabel } = useObjectLabel();
478+
const { objectPluralLabel, dashboardLabel, pageLabel, reportLabel, viewLabel } = useObjectLabel();
479+
const { appLabel } = useServedAppLabel();
478480
// The dashboard, page and report lists are LAZY getters: reading one starts
479481
// its `/meta/:type` read. They are read below only on the route type that
480482
// names one (the phone bar's title), never destructured here, so a route of
@@ -1324,7 +1326,7 @@ export function AppHeader({
13241326
.filter((a: any) => a.active !== false && a.hidden === true && a.name !== 'account')
13251327
.map((app: any) => {
13261328
const AppIcon = getIcon(app.icon);
1327-
const label = appLabel({ name: app.name, label: resolveKeyedI18nLabel(app.label, t) });
1329+
const label = appLabel(app);
13281330
return (
13291331
<DropdownMenuItem
13301332
key={`hidden_app_${app.name}`}

0 commit comments

Comments
 (0)