Skip to content

Commit 8a2e725

Browse files
committed
feat: add resolveLabel function to handle label values in AppSidebar
1 parent e97aca0 commit 8a2e725

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

apps/studio/src/components/MetadataInspector.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import {
1515
} from 'lucide-react';
1616
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
1717

18+
/** Resolve a label value that may be a plain string or an i18n object {key, defaultValue} */
19+
function resolveLabel(val: unknown): string {
20+
if (typeof val === 'string') return val;
21+
if (val && typeof val === 'object' && 'defaultValue' in val) return String((val as any).defaultValue);
22+
if (val && typeof val === 'object' && 'key' in val) return String((val as any).key);
23+
return '';
24+
}
25+
1826
interface MetadataInspectorProps {
1927
metaType: string;
2028
metaName: string;
@@ -232,9 +240,9 @@ export function MetadataInspector({ metaType, metaName, packageId }: MetadataIns
232240
}
233241

234242
// Extract common meta fields
235-
const label = item.label || item.name || metaName;
243+
const label = resolveLabel(item.label) || item.name || metaName;
236244
const name = item.name || metaName;
237-
const description = item.description;
245+
const description = resolveLabel(item.description);
238246
const hasFQN = name.includes('__');
239247
const [namespace] = hasFQN ? name.split('__') : [null];
240248

apps/studio/src/components/app-sidebar.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ const SYSTEM_FQN_PREFIX = `${SYSTEM_NAMESPACE}__`;
139139
/** Legacy system object name prefix (namespace + single underscore) */
140140
const SYSTEM_LEGACY_PREFIX = `${SYSTEM_NAMESPACE}_`;
141141

142+
/** Resolve a label value that may be a plain string or an i18n object {key, defaultValue} */
143+
function resolveLabel(val: unknown): string {
144+
if (typeof val === 'string') return val;
145+
if (val && typeof val === 'object' && 'defaultValue' in val) return String((val as any).defaultValue);
146+
if (val && typeof val === 'object' && 'key' in val) return String((val as any).key);
147+
return '';
148+
}
149+
142150
/** Check if an object item is a system object */
143151
function isSystemObject(item: any): boolean {
144152
if (item.isSystem === true) return true;
@@ -399,7 +407,7 @@ export function AppSidebar({
399407
const isExpanded = expandedTypes.has(type) || !!searchQuery;
400408

401409
const filtered = items.filter((item: any) =>
402-
matchesSearch(item.label || item.name || '', item.name || '')
410+
matchesSearch(resolveLabel(item.label) || item.name || '', item.name || '')
403411
);
404412
if (filtered.length === 0 && searchQuery) return null;
405413

@@ -418,7 +426,7 @@ export function AppSidebar({
418426
<SidebarMenuSub>
419427
{filtered.map((item: any) => {
420428
const itemName = item.name || item.id || 'unknown';
421-
const itemLabel = item.label || item.name || 'Untitled';
429+
const itemLabel = resolveLabel(item.label) || item.name || 'Untitled';
422430
const fqnParts = itemName.includes('__') ? itemName.split('__') : [null, itemName];
423431
const namespace = fqnParts.length === 2 && fqnParts[0] ? fqnParts[0] : null;
424432

@@ -500,10 +508,10 @@ export function AppSidebar({
500508
<CollapsibleContent>
501509
<SidebarMenuSub>
502510
{systemObjects
503-
.filter((item: any) => matchesSearch(item.label || item.name || '', item.name || ''))
511+
.filter((item: any) => matchesSearch(resolveLabel(item.label) || item.name || '', item.name || ''))
504512
.map((item: any) => {
505513
const itemName = item.name || item.id || 'unknown';
506-
const itemLabel = item.label || item.name || 'Untitled';
514+
const itemLabel = resolveLabel(item.label) || item.name || 'Untitled';
507515

508516
return (
509517
<SidebarMenuSubItem key={itemName}>

0 commit comments

Comments
 (0)