@@ -4,31 +4,62 @@ import Icon from 'components/Icon/Icon.react';
4
4
import styles from './AggregationPanel.scss' ;
5
5
6
6
// Text Element Component
7
- export const TextElement = ( { text, style} ) => (
7
+ export const TextElement = ( { text, style } ) => (
8
8
< div className = "text-element" style = { style } >
9
9
< p > { text } </ p >
10
10
</ div >
11
11
) ;
12
12
13
13
// Key-Value Element Component
14
14
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
+
15
27
const handleCopy = ( ) => {
16
- copy ( String ( item . value ) ) ;
28
+ copy ( values . join ( ' ' ) ) ;
17
29
if ( showNote ) {
18
30
showNote ( 'Value copied to clipboard' , false ) ;
19
31
}
20
32
} ;
21
33
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
+
22
54
return (
23
55
< div className = { styles . keyValue } style = { style } >
24
56
{ 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
+ ) ) }
32
63
< span className = { styles . copyIcon } onClick = { handleCopy } >
33
64
< Icon name = "clone-icon" width = { 12 } height = { 12 } fill = "currentColor" />
34
65
</ span >
0 commit comments