Refactor TagsDisplay component to handle string and array inputs for tags, ensuring proper rendering and fallback for empty values.
This commit is contained in:
parent
fdd16b2301
commit
ecca21fd6e
@ -4,14 +4,25 @@ import PropTypes from 'prop-types'
|
|||||||
|
|
||||||
const { Text } = Typography
|
const { Text } = Typography
|
||||||
|
|
||||||
const TagsDisplay = ({ tags = [], style }) => {
|
const TagsDisplay = ({ tags, style }) => {
|
||||||
if (tags.length == 0) {
|
let tagArray = []
|
||||||
|
if (typeof tags === 'string') {
|
||||||
|
tagArray = [tags]
|
||||||
|
} else if (Array.isArray(tags)) {
|
||||||
|
tagArray = tags
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!tagArray ||
|
||||||
|
tagArray.length === 0 ||
|
||||||
|
(tagArray.length === 1 && !tagArray[0])
|
||||||
|
) {
|
||||||
return <Text type='secondary'>n/a</Text>
|
return <Text type='secondary'>n/a</Text>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size={'small'} wrap style={style}>
|
<Space size={'small'} wrap style={style}>
|
||||||
{tags.map((tag, index) => (
|
{tagArray.map((tag, index) => (
|
||||||
<Tag key={index} color='blue' style={{ margin: 0 }}>
|
<Tag key={index} color='blue' style={{ margin: 0 }}>
|
||||||
{tag}
|
{tag}
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user