Skip to content

Commit 972d95c

Browse files
douglasmuraokadplewis
authored andcommitted
fix(Database Browser): Avoid Parse transformations on array and object fields (#1223)
Fixes #983 When rendering/editing `Array` or `Object` type fields on `Database Browser`, we must avoid any transformations of generic data to the `ParseObject` format. Since these fields are generic, we can't assume it will contain Parse related content.
1 parent b377452 commit 972d95c

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/components/BrowserCell/BrowserCell.react.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ let BrowserCell = ({ type, value, hidden, width, current, onSelect, onEditChange
5252
content = dateStringUTC(value);
5353
} else if (type === 'Boolean') {
5454
content = value ? 'True' : 'False';
55-
} else if (type === 'Array') {
56-
content = JSON.stringify(value.map(val => val instanceof Parse.Object ? val.toPointer() : val))
57-
} else if (type === 'Object' || type === 'Bytes') {
55+
} else if (type === 'Object' || type === 'Bytes' || type === 'Array') {
5856
content = JSON.stringify(value);
5957
} else if (type === 'File') {
6058
if (value.url()) {

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class BrowserTable extends React.Component {
7878
});
7979
}
8080

81-
renderRow({ row, obj, rowWidth }) {
81+
renderRow({ row, obj, json, rowWidth }) {
8282
let attributes = obj.attributes;
8383
let index = row - this.state.offset;
8484
return (
@@ -101,6 +101,12 @@ export default class BrowserTable extends React.Component {
101101
} else if (type === 'Relation' && !attr && obj.id) {
102102
attr = new Parse.Relation(obj, name);
103103
attr.targetClassName = this.props.columns[name].targetClass;
104+
} else if (type === 'Array' || type === 'Object') {
105+
// This is needed to avoid unwanted conversions of objects to Parse.Objects.
106+
// When retrieving data from JSON, Parse-SDK will not try to convert any data.
107+
// Since array and object are generic types, we want to render them the way
108+
// they were stored in the database.
109+
attr = json[name];
104110
}
105111
}
106112
let current = this.props.current && this.props.current.row === row && this.props.current.col === j;
@@ -161,7 +167,7 @@ export default class BrowserTable extends React.Component {
161167
if (this.props.newObject && this.state.offset <= 0) {
162168
newRow = (
163169
<div style={{ marginBottom: 30, borderBottom: '1px solid #169CEE' }}>
164-
{this.renderRow({ row: -1, obj: this.props.newObject, rowWidth: rowWidth })}
170+
{this.renderRow({ row: -1, obj: this.props.newObject, json: {}, rowWidth: rowWidth })}
165171
</div>
166172
);
167173
}
@@ -170,7 +176,7 @@ export default class BrowserTable extends React.Component {
170176
for (let i = this.state.offset; i < end; i++) {
171177
let index = i - this.state.offset;
172178
let obj = this.props.data[i];
173-
rows[index] = this.renderRow({ row: i, obj: obj, rowWidth: rowWidth });
179+
rows[index] = this.renderRow({ row: i, obj, json: obj.toJSON(), rowWidth: rowWidth });
174180
}
175181

176182
if (this.props.editing) {
@@ -193,8 +199,20 @@ export default class BrowserTable extends React.Component {
193199
}
194200
let obj = this.props.current.row < 0 ? this.props.newObject : this.props.data[this.props.current.row];
195201
let value = obj;
202+
let json = obj.toJSON();
196203
if (!this.props.isUnique) {
197-
value = obj.get(name);
204+
if (type === 'Array' || type === 'Object') {
205+
if (!json) {
206+
json = obj.toJSON();
207+
}
208+
// This is needed to avoid unwanted conversions of objects to Parse.Objects.
209+
// When retrieving data from JSON, Parse-SDK will not try to convert any data.
210+
// Since array and object are generic types, we want to edit them the way
211+
// they were stored in the database.
212+
value = json[name];
213+
} else {
214+
value = obj.get(name);
215+
}
198216
}
199217
if (name === 'objectId') {
200218
if (!this.props.isUnique) {
@@ -204,18 +222,6 @@ export default class BrowserTable extends React.Component {
204222
value = new Parse.ACL({ '*': { read: true }, [obj.id]: { read: true, write: true }});
205223
} else if (name === 'password' && this.props.className === '_User') {
206224
value = '';
207-
} else if (type === 'Array') {
208-
if (value) {
209-
value = value.map(val => {
210-
if (val instanceof Parse.Object) {
211-
return val.toPointer();
212-
} else if (val && typeof val.getMonth === 'function') {
213-
return { __type: "Date", iso: val.toISOString() };
214-
}
215-
216-
return val;
217-
});
218-
}
219225
}
220226
let wrapTop = Math.max(0, this.props.current.row * ROW_HEIGHT);
221227
if (this.props.current.row > -1 && this.props.newObject) {

0 commit comments

Comments
 (0)