Renders a Resource in a small line item. Not a link. Useful in dropdown.
({ subject, clickable }: Props)
| 10 | |
| 11 | /** Renders a Resource in a small line item. Not a link. Useful in dropdown. */ |
| 12 | function 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 | |
| 45 | export default ResourceLine; |
nothing calls this directly
no test coverage detected