@@ -3,22 +3,63 @@ import PropTypes from 'prop-types';
3
3
import { config } from '../config' ;
4
4
5
5
export const DiffColumn = function ( { diff, prop, type, propClass } ) {
6
+ return (
7
+ < td className = { propClass } >
8
+ < DiffColumnContent diff = { diff } prop = { prop } type = { type } />
9
+ </ td >
10
+ ) ;
11
+ } ;
12
+
13
+ const DiffColumnContent = function ( { diff, prop, type } ) {
14
+ let renderOutput ;
15
+ const value = diff [ prop ] [ type ] ,
16
+ propIsWikidata = typeof prop == 'string' && / w i k i d a t a $ / . test ( prop ) ;
6
17
if ( prop === 'changeset' && type === 'modifiedOld' ) {
7
- return (
8
- < td className = { propClass } >
9
- < a
10
- target = "_blank"
11
- rel = "noopener noreferrer"
12
- className = "cmap-changeset-link"
13
- href = { `${ config . osmchaBase } changesets/${ diff [ prop ] [ type ] } ` }
14
- >
15
- { diff [ prop ] [ type ] }
16
- </ a >
17
- </ td >
18
+ // Link to the last changeset that affected the element before this
19
+ renderOutput = (
20
+ < a
21
+ target = "_blank"
22
+ rel = "noopener noreferrer"
23
+ className = "cmap-changeset-link"
24
+ href = { `${ config . osmchaBase } changesets/${ value } ` }
25
+ title = { `Go to changeset ${ value } ` }
26
+ >
27
+ { value }
28
+ </ a >
18
29
) ;
30
+ } else if ( propIsWikidata && typeof value === 'string' ) {
31
+ // The tag is a reference to Wikidata, transform the value into a link
32
+ // https://wiki.openstreetmap.org/wiki/Wikidata
33
+ const wikidataQIdArray = value . split ( ';' ) ,
34
+ renderArray = [ ] ;
35
+ wikidataQIdArray . forEach ( ( QId , index ) => {
36
+ const isValidWikidataQId = / ^ Q \d + $ / . test ( QId ) ;
37
+
38
+ if ( index !== 0 )
39
+ renderArray . push ( < span > ;</ span > ) ;
40
+
41
+ if ( isValidWikidataQId ) {
42
+ renderArray . push (
43
+ < a
44
+ target = "_blank"
45
+ rel = "noopener noreferrer"
46
+ className = "cmap-wikidata-link"
47
+ href = { `https://www.wikidata.org/wiki/${ QId } ` }
48
+ title = { `Go to Wikidata entity ${ QId } ` }
49
+ >
50
+ { QId }
51
+ </ a >
52
+ ) ;
53
+ } else {
54
+ renderArray . push ( < span > { QId } </ span > ) ;
55
+ }
56
+ } ) ;
57
+ renderOutput = ( < span > { renderArray } </ span > ) ;
19
58
} else {
20
- return < td className = { propClass } > { diff [ prop ] [ type ] } </ td > ;
59
+ // Standard tag, no processing needed
60
+ renderOutput = ( < span > { value } </ span > ) ;
21
61
}
62
+ return renderOutput ;
22
63
} ;
23
64
24
65
DiffColumn . propTypes = {
0 commit comments