import type { NodeRenderer } from './types'; import { ClickPopover } from './components/ClickPopover'; import useSWR from 'swr'; import { ExternalLinkIcon } from '@heroicons/react/outline'; const fetcher = (...args: Parameters) => fetch(...args).then((res) => { if (res.status === 200) return res.json(); throw new Error(`Content returned with status ${res.status}.`); }); function RRIDChild({ label }: { label: string }) { const { data, error } = useSWR(`https://scicrunch.org/resolver/${label}.json`, fetcher); if (!data && !error) { return Loading...; } const hit = data?.hits?.hits?.[0]; if (error || !hit) { return Error loading {label}.; } const { name: title, curie, description, supercategory, keywords, types: categories, } = hit?._source?.item ?? {}; const category = supercategory?.[0]?.name; const types = (categories?.map(({ name }: { name: string }) => name) as string[]) ?? []; const tags = (keywords?.map(({ keyword }: { keyword: string }) => keyword) as string[]) ?? []; return (

RRID: {category}

{title} {curie}

{description}

{types.length > 0 && ( <>
Categories
{types?.map((tag) => ( {tag} ))}
)} {tags.length > 0 && ( <>
Tags
{tags?.map((tag) => ( {tag} ))}
)}
); } export const RRID: NodeRenderer = (node) => { return ( }> RRID: {node.label} ); }; const RRID_RENDERERS: Record = { rrid: RRID, }; export default RRID_RENDERERS;