@@ -2,15 +2,17 @@ import React from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import { config } from '../config' ;
4
4
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
- } ;
5
+ export class DiffColumn extends React . Component {
6
+ render ( ) {
7
+ return (
8
+ < td className = { this . props . propClass } >
9
+ < DiffColumnContent { ...this . props } { ...this . context } />
10
+ </ td >
11
+ ) ;
12
+ }
13
+ }
12
14
13
- const DiffColumnContent = function ( { diff, prop, type } ) {
15
+ const DiffColumnContent = function ( { diff, prop, type, tag2link } ) {
14
16
let renderOutput ;
15
17
const value = diff [ prop ] [ type ] ,
16
18
propIsWikidata = typeof prop == 'string' && / w i k i d a t a $ / . test ( prop ) ;
@@ -54,6 +56,21 @@ const DiffColumnContent = function({ diff, prop, type }) {
54
56
}
55
57
} ) ;
56
58
renderOutput = < span > { renderArray } </ span > ;
59
+ } else if ( tag2link [ prop ] && typeof value === 'string' ) {
60
+ // This is a foreign key which is defined in the tag2link DB.
61
+ // So, we render a clickable link.
62
+ renderOutput = (
63
+ < span >
64
+ < a
65
+ target = "_blank"
66
+ rel = "noopener noreferrer"
67
+ className = "cmap-wikidata-link"
68
+ href = { tag2link [ prop ] . replace ( / \$ 1 / g, value ) }
69
+ >
70
+ { value }
71
+ </ a >
72
+ </ span >
73
+ ) ;
57
74
} else {
58
75
// Standard tag, no processing needed
59
76
renderOutput = < span > { value } </ span > ;
@@ -67,3 +84,7 @@ DiffColumn.propTypes = {
67
84
type : PropTypes . string . isRequired ,
68
85
propClass : PropTypes . string
69
86
} ;
87
+
88
+ DiffColumn . contextTypes = {
89
+ tag2link : PropTypes . objectOf ( PropTypes . string )
90
+ } ;
0 commit comments