Skip to content

Commit a248e7f

Browse files
committed
wip(ui): Setup metadata list names its page as its nav entry and leads with the label
Claude-Session: https://claude.ai/code/session_01L9qibwpXbWKjEuA5DF45BL Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9f13ee8 commit a248e7f

2 files changed

Lines changed: 79 additions & 11 deletions

File tree

‎ui/packages/app-shell/src/views/metadata-admin/ResourceListPage.tsx‎

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
import * as React from 'react';
16-
import { Link, Navigate, useNavigate, useParams, useSearchParams } from 'react-router-dom';
16+
import { Link, Navigate, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
1717
import { Plus, Search, RefreshCw, AlertTriangle, Lock, Copy } from 'lucide-react';
1818
import {
1919
Button,
@@ -51,6 +51,9 @@ import { Empty, EmptyTitle, EmptyDescription, EmptyValue } from '@object-ui/comp
5151
import { PageShell, WritabilityBadge } from './PageShell.js';
5252
import { PageHeader } from '../../layout/PageHeader.js';
5353
import { useInSetupApp } from '../../console/setupApp.js';
54+
import { useExpressionContext } from '../../providers/ExpressionProvider.js';
55+
import { useObjectTranslation } from '@object-ui/i18n';
56+
import { navEntryTitle } from './navEntryTitle.js';
5457
import { getIcon } from '../../utils/getIcon.js';
5558
import { MetadataTypeActions } from './MetadataTypeActions.js';
5659
import { CreatePackageDialog } from './PackagesPage.js';
@@ -187,6 +190,11 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
187190
// the description. Read off the route's `:appName`; the same page anywhere
188191
// else (the directory, Studio's "Open in Setup" target) keeps its shell.
189192
const inSetup = useInSetupApp();
193+
// objectstack#27356 — under Setup the header names the page as the sidebar
194+
// entry that opens it does ("Positions"); the type's label otherwise.
195+
const { app } = useExpressionContext();
196+
const location = useLocation();
197+
const { t: navT, language } = useObjectTranslation();
190198
// objectui#12183 — under a wall the security catalog is the platform
191199
// operator's: the server refuses this caller every write of the type,
192200
// whatever it holds (`catalog-scope.ts`). Not keyed on the scope: the server's
@@ -577,6 +585,13 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
577585
config.bundleMemberField,
578586
);
579587
const typeLabel = translateMetadataType(type, locale, entry?.label ?? type);
588+
const setupTitle =
589+
(inSetup && navEntryTitle(app, `/apps/${appName}`, location.pathname, location.search, navT, language)) || typeLabel;
590+
// objectstack#27356 — under Setup the label leads the identity cell, with the
591+
// API name beneath it, in place of a separate Label column.
592+
const primaryKey = config.primaryKey ?? 'name';
593+
const labelColumn = inSetup && columns[0]?.key === primaryKey ? columns.find((c) => c.key === 'label') : undefined;
594+
const shownColumns = labelColumn ? columns.filter((c) => c !== labelColumn) : columns;
580595
// The type offers SOME runtime write channel (the editors' type tier), and —
581596
// in the environment scope — the caller holds the capability the metadata
582597
// door requires. The server refuses either way; this is the half that says
@@ -826,13 +841,13 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
826841
}
827842
>
828843
<tr className={HEAD_ROW_TINT}>
829-
{columns.map((c) => (
844+
{shownColumns.map((c, ci) => (
830845
<th
831846
key={c.key}
832847
className={cn('px-3 text-left font-medium', inSetup ? 'h-9 py-0' : 'py-2')}
833848
style={c.width ? { width: c.width } : undefined}
834849
>
835-
{localizeColumnLabel(c)}
850+
{localizeColumnLabel(ci === 0 && labelColumn ? labelColumn : c)}
836851
</th>
837852
))}
838853
<th className={cn('px-3 text-right font-medium w-[80px]', inSetup ? 'h-9 py-0' : 'py-2')}>{t('engine.list.col.source', locale)}</th>
@@ -910,9 +925,11 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
910925
HOVER_ROW_TINT,
911926
)}
912927
>
913-
{columns.map((c, ci) => {
928+
{shownColumns.map((c, ci) => {
914929
const value = row.item[c.key];
915930
const cell = c.render ? c.render(value, row.item) : defaultCell(value);
931+
const labelValue = labelColumn ? row.item[labelColumn.key] : undefined;
932+
const hasLabel = labelValue != null && labelValue !== '';
916933
return (
917934
<td key={c.key} className={cellClass}>
918935
{ci === 0 ? (
@@ -935,12 +952,32 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
935952
<AlertTriangle className="w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0" />
936953
</span>
937954
)}
938-
<Link
939-
to={rowHref}
940-
className="text-primary hover:underline font-mono"
941-
>
942-
{cell}
943-
</Link>
955+
{labelColumn && hasLabel ? (
956+
<span className="min-w-0">
957+
<Link to={rowHref} className="text-primary hover:underline">
958+
{labelColumn.render ? labelColumn.render(labelValue, row.item) : defaultCell(labelValue)}
959+
</Link>
960+
<span
961+
className="block font-mono text-xs text-muted-foreground"
962+
data-testid="metadata-row-api-name"
963+
>
964+
{cell}
965+
</span>
966+
</span>
967+
) : (
968+
<Link
969+
to={rowHref}
970+
className="text-primary hover:underline font-mono"
971+
>
972+
{cell}
973+
</Link>
974+
)}
975+
</span>
976+
) : inSetup && c.key === 'description' && typeof value === 'string' && value !== '' ? (
977+
// objectstack#27356 — two lines at most, so a row
978+
// stays a row on a phone; the whole text on hover.
979+
<span className="line-clamp-2" title={value}>
980+
{cell}
944981
</span>
945982
) : (
946983
cell
@@ -1068,7 +1105,7 @@ function DefaultMetadataList({ type, appName }: { type: string; appName?: string
10681105
return (
10691106
<div className="flex flex-col h-full overflow-hidden">
10701107
<PageHeader
1071-
title={typeLabel}
1108+
title={setupTitle}
10721109
// `createElement`, not a JSX tag: the looked-up icon is a value
10731110
// (the convention ObjectView set).
10741111
icon={React.createElement(getIcon(config.iconName ?? 'layers'), { className: 'h-4 w-4' })}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The title a Setup list page takes from the app's own navigation
5+
* (objectstack#27356, row 5): the label of the entry that opens exactly this
6+
* page, so the page reads "Positions" as the sidebar row that opened it does,
7+
* in the served language, instead of the type registry's singular label.
8+
*
9+
* The entry is elected by `resolveActiveNavItem`, the one "which menu am I in"
10+
* matcher, and counts only when its own address is this page's path: an entry
11+
* that claims the page by prefix names a different page.
12+
*/
13+
14+
import { resolveActiveNavItem, resolveHref, resolveNavItemLabel } from '@object-ui/layout';
15+
import type { NavigationItem } from '@object-ui/types';
16+
17+
export function navEntryTitle(
18+
app: unknown,
19+
basePath: string,
20+
pathname: string,
21+
search: string,
22+
t: (key: string, options?: any) => string,
23+
locale: string | undefined,
24+
): string | undefined {
25+
const navigation = app && typeof app === 'object' ? (app as { navigation?: unknown }).navigation : undefined;
26+
if (!Array.isArray(navigation)) return undefined;
27+
const item = resolveActiveNavItem(navigation as NavigationItem[], pathname, search, basePath);
28+
if (!item || resolveHref(item, basePath).href.split(/[?#]/)[0] !== pathname) return undefined;
29+
const label = resolveNavItemLabel(item, t, undefined, locale);
30+
return label.trim() !== '' ? label : undefined;
31+
}

0 commit comments

Comments
 (0)