Fix: Resolve object ids in map keys
This commit is contained in:
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. This projec
|
||||
|
||||
### Fixed
|
||||
- Broken "Delivery History" link on OSS/Community editions.
|
||||
- Resolve object ids in map keys.
|
||||
|
||||
## [1.0.2] - 2026-04-30
|
||||
|
||||
|
||||
@@ -1979,6 +1979,29 @@ function ObjectIdMultiSelectPill({
|
||||
);
|
||||
}
|
||||
|
||||
function MapEntryKeyLabel({ keyClass, keyValue, schema }: { keyClass: ScalarType; keyValue: string; schema: Schema }) {
|
||||
if (keyClass.type === 'enum') {
|
||||
const variants = schema.enums[keyClass.enumName] ?? [];
|
||||
const variant = variants.find((v) => v.name === keyValue);
|
||||
return <>{variant?.label ?? keyValue}</>;
|
||||
}
|
||||
if (keyClass.type === 'objectId') {
|
||||
return <ObjectIdKeyLabel objectName={keyClass.objectName} keyValue={keyValue} schema={schema} />;
|
||||
}
|
||||
return <>{keyValue}</>;
|
||||
}
|
||||
|
||||
function ObjectIdKeyLabel({ objectName, keyValue, schema }: { objectName: string; keyValue: string; schema: Schema }) {
|
||||
const list = useObjectList(objectName, schema);
|
||||
const fromList = list.options.find((o) => o.id === keyValue)?.label;
|
||||
const { label: cheapLabel, loading } = useObjectLabel(objectName, fromList ? null : keyValue, schema);
|
||||
const display = fromList ?? cheapLabel;
|
||||
if (loading && !display) {
|
||||
return <Loader2 className="h-3 w-3 animate-spin text-muted-foreground" />;
|
||||
}
|
||||
return <>{display ?? keyValue}</>;
|
||||
}
|
||||
|
||||
interface MapFieldProps {
|
||||
keyClass: ScalarType;
|
||||
valueClass: MapValueType;
|
||||
@@ -2038,15 +2061,6 @@ function MapField({ keyClass, valueClass, value, onChange, readOnly, schema, min
|
||||
}
|
||||
};
|
||||
|
||||
const getKeyLabel = (key: string): string => {
|
||||
if (keyClass.type === 'enum') {
|
||||
const variants = schema.enums[keyClass.enumName] ?? [];
|
||||
const variant = variants.find((v) => v.name === key);
|
||||
if (variant) return variant.label;
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
const existingKeys = new Set(Object.keys(mapValue));
|
||||
|
||||
return (
|
||||
@@ -2063,7 +2077,7 @@ function MapField({ keyClass, valueClass, value, onChange, readOnly, schema, min
|
||||
className="flex flex-1 items-center gap-2 p-3 text-sm font-medium hover:bg-accent/50 rounded-t-md transition-colors [&[data-state=closed]>svg]:rotate-0 [&[data-state=open]>svg]:rotate-90"
|
||||
>
|
||||
<ChevronRight className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
||||
{getKeyLabel(key)}
|
||||
<MapEntryKeyLabel keyClass={keyClass} keyValue={key} schema={schema} />
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
{!readOnly && (
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
|
||||
import { useMemo } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { Check, X, HelpCircle, ChevronRight } from 'lucide-react';
|
||||
import { Check, X, HelpCircle, ChevronRight, Loader2 } from 'lucide-react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { jmapMapToArray, SECRET_MASK } from '@/lib/jmapUtils';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
||||
import { resolveSchema, resolveVariantForm, resolveForm } from '@/lib/schemaResolver';
|
||||
import { useObjectList, useObjectLabel } from '@/lib/objectOptions';
|
||||
import { formatSize, formatDuration } from '@/lib/durationFormat';
|
||||
import type { Schema, Field, FieldType, FormField, Form, Fields, EnumVariant } from '@/types/schema';
|
||||
import type { Schema, Field, FieldType, FormField, Form, Fields, EnumVariant, ScalarType } from '@/types/schema';
|
||||
|
||||
export interface DynamicViewProps {
|
||||
schema: Schema;
|
||||
@@ -401,7 +402,7 @@ function MapValue({
|
||||
schema,
|
||||
}: {
|
||||
value: unknown;
|
||||
keyClass: { type: string; enumName?: string };
|
||||
keyClass: ScalarType;
|
||||
valueClass: { type: string; objectName?: string };
|
||||
schema: Schema;
|
||||
}) {
|
||||
@@ -417,12 +418,7 @@ function MapValue({
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{entries.map(([k, v]) => {
|
||||
let keyLabel = k;
|
||||
if (keyClass.type === 'enum' && keyClass.enumName) {
|
||||
const variants = schema.enums[keyClass.enumName] ?? [];
|
||||
const variant = variants.find((e: EnumVariant) => e.name === k);
|
||||
if (variant) keyLabel = variant.label;
|
||||
}
|
||||
const keyLabel = <MapKeyLabel keyClass={keyClass} keyValue={k} schema={schema} />;
|
||||
|
||||
if (valueClass.type === 'object' && valueClass.objectName) {
|
||||
return (
|
||||
@@ -446,6 +442,29 @@ function MapValue({
|
||||
);
|
||||
}
|
||||
|
||||
function MapKeyLabel({ keyClass, keyValue, schema }: { keyClass: ScalarType; keyValue: string; schema: Schema }) {
|
||||
if (keyClass.type === 'enum') {
|
||||
const variants = schema.enums[keyClass.enumName] ?? [];
|
||||
const variant = variants.find((e: EnumVariant) => e.name === keyValue);
|
||||
return <>{variant?.label ?? keyValue}</>;
|
||||
}
|
||||
if (keyClass.type === 'objectId') {
|
||||
return <ObjectIdKeyLabel objectName={keyClass.objectName} keyValue={keyValue} schema={schema} />;
|
||||
}
|
||||
return <>{keyValue}</>;
|
||||
}
|
||||
|
||||
function ObjectIdKeyLabel({ objectName, keyValue, schema }: { objectName: string; keyValue: string; schema: Schema }) {
|
||||
const list = useObjectList(objectName, schema);
|
||||
const fromList = list.options.find((o) => o.id === keyValue)?.label;
|
||||
const { label: cheapLabel, loading } = useObjectLabel(objectName, fromList ? null : keyValue, schema);
|
||||
const display = fromList ?? cheapLabel;
|
||||
if (loading && !display) {
|
||||
return <Loader2 className="h-3 w-3 animate-spin text-muted-foreground" />;
|
||||
}
|
||||
return <>{display ?? keyValue}</>;
|
||||
}
|
||||
|
||||
function FieldTooltip({ description }: { description: string }) {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
|
||||
Reference in New Issue
Block a user