Skip to content

Fix #983 verify the whole array to check Parse.Objects into generic objects #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
17 changes: 16 additions & 1 deletion src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ import React from 'react';
import styles from 'components/BrowserCell/BrowserCell.scss';
import { unselectable } from 'stylesheets/base.scss';

const detectArray = (value) => {
if (Array.isArray(value)) {
return value.map(detectArray);
} else if (value instanceof Parse.Object) {
return value.toPointer();
} else if (typeof value === 'object') {
Object.keys(value).forEach(key => {
value[key] = detectArray(value[key]);
});
return value;
} else {
return value;
}
};

let BrowserCell = ({ type, value, hidden, width, current, onSelect, onEditChange, setRelation, onPointerClick }) => {
let content = value;
let classes = [styles.cell, unselectable];
Expand Down Expand Up @@ -53,7 +68,7 @@ let BrowserCell = ({ type, value, hidden, width, current, onSelect, onEditChange
} else if (type === 'Boolean') {
content = value ? 'True' : 'False';
} else if (type === 'Array') {
content = JSON.stringify(value.map(val => val instanceof Parse.Object ? val.toPointer() : val))
content = JSON.stringify(detectArray(value));
} else if (type === 'Object' || type === 'Bytes') {
content = JSON.stringify(value);
} else if (type === 'File') {
Expand Down
22 changes: 13 additions & 9 deletions src/dashboard/Data/Browser/BrowserTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ const READ_ONLY = [ 'objectId', 'createdAt', 'updatedAt' ];

let scrolling = false;

const detectArray = (value) => {
if (Array.isArray(value)) {
return value.map(detectArray);
} else if (value instanceof Parse.Object) {
return value.toPointer();
} else if (value && typeof value.getMonth === 'function') {
return { __type: 'Date', iso: value.toISOString() };
} else {
return value;
}
};

export default class BrowserTable extends React.Component {
constructor() {
super();
Expand Down Expand Up @@ -211,15 +223,7 @@ export default class BrowserTable extends React.Component {
value = '';
} else if (type === 'Array') {
if (value) {
value = value.map(val => {
if (val instanceof Parse.Object) {
return val.toPointer();
} else if (val && typeof val.getMonth === 'function') {
return { __type: "Date", iso: val.toISOString() };
}

return val;
});
value = detectArray(value);
}
}
let wrapTop = Math.max(0, this.props.current.row * ROW_HEIGHT);
Expand Down