import React from "react"; import { ResolvedMapProperty } from "../../types"; import { PropertyPreviewProps } from "../PropertyPreviewProps"; import { PropertyPreview } from "../PropertyPreview"; import { cn, defaultBorderMixin, Typography } from "@firecms/ui"; import { ErrorBoundary } from "../../components"; import { EmptyValue } from "../components/EmptyValue"; /** * @group Preview components */ export function MapPropertyPreview = Record>({ propertyKey, value, property, // entity, size }: PropertyPreviewProps) { if (property.dataType !== "map") { throw Error("Picked wrong preview component MapPropertyPreview"); } const mapProperty = property as ResolvedMapProperty; if (!mapProperty.properties || Object.keys(mapProperty.properties ?? {}).length === 0) { return ( ); } if (!value) return null; const mapPropertyKeys: string[] = Object.keys(mapProperty.properties) if (size === "tiny") return (
{mapPropertyKeys.map((key, index) => (
))}
); return (
{mapPropertyKeys && mapPropertyKeys.map((key, index) => { const childProperty = mapProperty.properties![key]; return (
{childProperty.name}
{!(childProperty.dataType === "map" || childProperty === "array") && }
{(childProperty.dataType === "map" || childProperty === "array") &&
}
); })}
); } export function KeyValuePreview({ value }: { value: any }) { if (typeof value !== "object") return null; if (!value) return ; return
{ Object.entries(value).map(([key, childValue]) => (
{key}
{typeof childValue !== "object" && {childValue && childValue.toString()} }
{typeof childValue === "object" &&
}
)) }
; }