MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / ResourceLine

Function ResourceLine

data-browser/src/views/ResourceLine.tsx:12–43  ·  view source on GitHub ↗

Renders a Resource in a small line item. Not a link. Useful in dropdown.

({ subject, clickable }: Props)

Source from the content-addressed store, hash-verified

10
11/** Renders a Resource in a small line item. Not a link. Useful in dropdown. */
12function ResourceLine({ subject, clickable }: Props): JSX.Element {
13 const resource = useResource(subject);
14 const title = useTitle(resource);
15 let [description] = useString(resource, urls.properties.description);
16
17 if (resource.loading) {
18 return <span about={subject}>Loading...</span>;
19 }
20 if (resource.error) {
21 return (
22 <ErrorLook about={subject}>
23 Error: {resource.getError().message}
24 </ErrorLook>
25 );
26 }
27
28 const TRUNCATE_LENGTH = 40;
29 if (description?.length >= TRUNCATE_LENGTH) {
30 description = description.slice(0, TRUNCATE_LENGTH) + '...';
31 }
32
33 return (
34 <span about={subject}>
35 {clickable ? (
36 <ResourceInline untabbable subject={subject} />
37 ) : (
38 <b>{title}</b>
39 )}
40 {description ? ` - ${description}` : null}
41 </span>
42 );
43}
44
45export default ResourceLine;

Callers

nothing calls this directly

Calls 4

useResourceFunction · 0.90
useTitleFunction · 0.90
useStringFunction · 0.90
getErrorMethod · 0.80

Tested by

no test coverage detected