Skip to content

Commit 5f03db3

Browse files
madsbflovilmart
authored andcommitted
Add support for Polygon type (#759)
* Add support for Polygon type * Edit empty cell, add support for ‘Add a new column’ * Check for edits
1 parent fcd9e51 commit 5f03db3

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/components/BrowserCell/BrowserCell.react.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ let BrowserCell = ({ type, value, hidden, width, current, onSelect, onEditChange
7575
content = pieces.join(', ');
7676
} else if (type === 'GeoPoint') {
7777
content = `(${value.latitude}, ${value.longitude})`;
78+
} else if (type === 'Polygon') {
79+
content = value.coordinates.map(coord => `(${coord})`)
7880
} else if (type === 'Relation') {
7981
content = (
8082
<div style={{ textAlign: 'center', cursor: 'pointer' }}>

src/dashboard/Data/Browser/Editor.react.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,40 @@ let Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit }
4343
width={width}
4444
onCommit={encodeCommit} />
4545
);
46+
} else if (type === 'Polygon') {
47+
let encodeCommit = (json) => {
48+
try {
49+
let coordinates = JSON.parse(json);
50+
if (coordinates.length < 3) {
51+
throw 'Polygon must have at least 3 coordinates';
52+
}
53+
if (value && value.coordinates && value.coordinates.length === coordinates.length) {
54+
let dirty = coordinates.some((coord, index) => {
55+
if (value.coordinates[index][0] !== coord[0] || value.coordinates[index][1] !== coord[1]) {
56+
return true;
57+
}
58+
});
59+
if (!dirty) {
60+
throw 'No change in coordinates';
61+
}
62+
}
63+
let obj = {
64+
'__type': 'Polygon',
65+
coordinates
66+
}
67+
onCommit(obj);
68+
} catch (e) {
69+
onCommit(value);
70+
}
71+
}
72+
content = (
73+
<StringEditor
74+
value={JSON.stringify(value && value.coordinates || [['lat', 'lon']], null, 2)}
75+
resizable={true}
76+
multiline={true}
77+
width={width}
78+
onCommit={encodeCommit} />
79+
);
4680
} else if (type === 'Date') {
4781
if (readonly) {
4882
content = (

src/lib/Constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export const DataTypes = [
7171
'Object',
7272
'Array',
7373
'GeoPoint',
74+
'Polygon',
7475
'File',
7576
'Pointer',
7677
'Relation',

0 commit comments

Comments
 (0)