Skip to content

Commit b054a79

Browse files
authored
Merge pull request #254 from Danysan1/wikidata
Link to Wikidata items
2 parents a84d08d + 2dfc9e5 commit b054a79

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

lib/featureDiff/DiffColumn.js

+53-12
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,63 @@ import PropTypes from 'prop-types';
33
import { config } from '../config';
44

55
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' && /wikidata$/.test(prop);
617
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>
1829
);
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>);
1958
} else {
20-
return <td className={propClass}>{diff[prop][type]}</td>;
59+
// Standard tag, no processing needed
60+
renderOutput = (<span>{value}</span>);
2161
}
62+
return renderOutput;
2263
};
2364

2465
DiffColumn.propTypes = {

public/css/style.css

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
background: rgba(204, 44, 71, 0.3);
243243
}
244244

245+
.cmap-wikidata-link,
245246
.cmap-changeset-link {
246247
color: #666;
247248
}

0 commit comments

Comments
 (0)