Skip to content

Commit 59d6287

Browse files
committed
feat: support multiple values in KeyValueElement
1 parent 4564a25 commit 59d6287

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

src/components/AggregationPanel/AggregationPanelComponents.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,62 @@ import Icon from 'components/Icon/Icon.react';
44
import styles from './AggregationPanel.scss';
55

66
// Text Element Component
7-
export const TextElement = ({ text, style}) => (
7+
export const TextElement = ({ text, style }) => (
88
<div className="text-element" style={style}>
99
<p>{text}</p>
1010
</div>
1111
);
1212

1313
// Key-Value Element Component
1414
export const KeyValueElement = ({ item, appName, style, showNote }) => {
15+
const values = Array.isArray(item.value) ? item.value : [item.value];
16+
const urls = Array.isArray(item.url)
17+
? item.url
18+
: typeof item.url !== 'undefined'
19+
? [item.url]
20+
: [];
21+
const isRelativeUrls = Array.isArray(item.isRelativeUrl)
22+
? item.isRelativeUrl
23+
: typeof item.isRelativeUrl !== 'undefined'
24+
? [item.isRelativeUrl]
25+
: [];
26+
1527
const handleCopy = () => {
16-
copy(String(item.value));
28+
copy(values.join(' '));
1729
if (showNote) {
1830
showNote('Value copied to clipboard', false);
1931
}
2032
};
2133

34+
const renderValue = (value, idx) => {
35+
const url = urls[idx];
36+
const isRelative = isRelativeUrls[idx];
37+
38+
if (url) {
39+
return (
40+
<a
41+
key={idx}
42+
href={isRelative ? `apps/${appName}/${url}` : url}
43+
target="_blank"
44+
rel="noreferrer"
45+
>
46+
{value}
47+
</a>
48+
);
49+
}
50+
51+
return <span key={idx}>{value}</span>;
52+
};
53+
2254
return (
2355
<div className={styles.keyValue} style={style}>
2456
{item.key}:
25-
{item.url ? (
26-
<a href={item.isRelativeUrl ? `apps/${appName}/${item.url}` : item.url} target="_blank" rel="noreferrer">
27-
{item.value}
28-
</a>
29-
) : (
30-
<span>{item.value}</span>
31-
)}
57+
{values.map((val, idx) => (
58+
<React.Fragment key={idx}>
59+
{idx > 0 && ' '}
60+
{renderValue(val, idx)}
61+
</React.Fragment>
62+
))}
3263
<span className={styles.copyIcon} onClick={handleCopy}>
3364
<Icon name="clone-icon" width={12} height={12} fill="currentColor" />
3465
</span>

0 commit comments

Comments
 (0)