Renders a value in a fitting way, depending on its DataType
({ value, datatype, noMargin }: Props)
| 22 | |
| 23 | /** Renders a value in a fitting way, depending on its DataType */ |
| 24 | function ValueComp({ value, datatype, noMargin }: Props): JSX.Element { |
| 25 | try { |
| 26 | switch (datatype) { |
| 27 | case Datatype.ATOMIC_URL: { |
| 28 | const resource = valToResource(value); |
| 29 | if (typeof resource == 'string') { |
| 30 | return <ResourceInline subject={resource} />; |
| 31 | } |
| 32 | return <Nestedresource resource={resource} />; |
| 33 | } |
| 34 | case (Datatype.DATE, Datatype.TIMESTAMP): |
| 35 | return <DateTime date={valToDate(value)} />; |
| 36 | case Datatype.MARKDOWN: |
| 37 | return <Markdown text={valToString(value)} noMargin={noMargin} />; |
| 38 | case Datatype.RESOURCEARRAY: |
| 39 | return <ResourceArray subjects={valToArray(value)} />; |
| 40 | default: |
| 41 | return <div>{valToString(value)}</div>; |
| 42 | } |
| 43 | } catch (e) { |
| 44 | return ( |
| 45 | <ErrMessage> |
| 46 | {e.message} original value: {value.toString()} |
| 47 | </ErrMessage> |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | export default ValueComp; |
nothing calls this directly
no test coverage detected