Skip to content

Commit

Permalink
Removed EditRowDialog fixes for next PR
Browse files Browse the repository at this point in the history
  • Loading branch information
NinoZX committed Aug 31, 2020
1 parent dab2116 commit 4b24fb8
Showing 1 changed file with 18 additions and 93 deletions.
111 changes: 18 additions & 93 deletions src/dashboard/Data/Browser/EditRowDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export default class EditRowDialog extends React.Component {
super(props);

const { selectedObject } = this.props;
const { currentObject, openObjectPickers, expandedTextAreas } = this.initializeState(
const { currentObject, openObjectPickers } = this.initializeState(
selectedObject
);
this.state = { currentObject, openObjectPickers, expandedTextAreas };
this.state = { currentObject, openObjectPickers };

this.updateCurrentObject = this.updateCurrentObject.bind(this);
this.handleChange = this.handleChange.bind(this);
Expand All @@ -37,46 +37,42 @@ export default class EditRowDialog extends React.Component {
const newSelectedObject = props.selectedObject;
const previousSelectedObject = this.props.selectedObject;
if (newSelectedObject.id !== previousSelectedObject.id) {
const { currentObject, openObjectPickers, expandedTextAreas } = this.initializeState(
const { currentObject, openObjectPickers } = this.initializeState(
newSelectedObject
);
this.setState({ currentObject, openObjectPickers, expandedTextAreas });
} else if (newSelectedObject.updatedAt !== previousSelectedObject.updatedAt) {
this.updateCurrentObjectFromProps(newSelectedObject);
this.setState({ currentObject, openObjectPickers });
}
}

initializeState(newObject) {
const { columns } = this.props;
const currentObject = { ...newObject };
const openObjectPickers = {};
const expandedTextAreas = {};
columns.forEach(column => {
const { name, type } = column;
if (['Array', 'Object'].indexOf(type) >= 0) {
const stringifyValue = JSON.stringify(currentObject[name], null, 4);
currentObject[name] = stringifyValue;
const rows = stringifyValue ? stringifyValue.split('\n').length : 1;
expandedTextAreas[name] = { rows: rows, expanded: false };
currentObject[name] = JSON.stringify(currentObject[name], null, 2);
}
if (type === 'Polygon') {
const stringifyValue = JSON.stringify(
currentObject[name] = JSON.stringify(
(currentObject[name] && currentObject[name].coordinates) || [
['lat', 'lon']
],
null,
4
2
);
currentObject[name] = stringifyValue;
const rows = stringifyValue ? stringifyValue.split('\n').length : 1;
expandedTextAreas[name] = { rows: rows, expanded: false };
}
if (['Pointer', 'Relation'].indexOf(type) >= 0) {
if (type === 'Pointer') {
currentObject[name] =
(currentObject[name] && currentObject[name].id) || '';
openObjectPickers[name] = false;
}
if (type === 'Relation') {
openObjectPickers[name] = false;
}
});

return { currentObject, openObjectPickers, expandedTextAreas };
return { currentObject, openObjectPickers };
}

updateCurrentObject(newValue, name) {
Expand All @@ -85,36 +81,6 @@ export default class EditRowDialog extends React.Component {
this.setState({ currentObject });
}

updateCurrentObjectFromProps(newObject) {
const { columns } = this.props;
const { currentObject, expandedTextAreas } = this.state;
columns.forEach(column => {
const { name, type } = column;
if (['String', 'Number'].indexOf(type) >= 0) {
currentObject[name] = newObject[name];
}
if (['Array', 'Object'].indexOf(type) >= 0) {
const stringifyValue = JSON.stringify(newObject[name], null, 4);
currentObject[name] = stringifyValue;
const rows = stringifyValue ? stringifyValue.split('\n').length : 1;
expandedTextAreas[name].rows = rows;
}
if (type === 'Polygon') {
const stringifyValue = JSON.stringify(
(newObject[name] && newObject[name].coordinates) || [
['lat', 'lon']
],
null,
4
);
currentObject[name] = stringifyValue;
const rows = stringifyValue ? stringifyValue.split('\n').length : 1;
expandedTextAreas[name].rows = rows;
}
});
this.setState({ currentObject, expandedTextAreas });
}

handleChange(newValue, name, type, targetClass, toDelete) {
if (name == 'password') {
if (newValue === '') {
Expand Down Expand Up @@ -148,22 +114,8 @@ export default class EditRowDialog extends React.Component {
this.toggleObjectPicker(name, false);
} else {
if (['Array', 'Object', 'Polygon'].indexOf(type) >= 0) {
const { selectedObject } = this.props;
const { currentObject, expandedTextAreas } = this.state;
const oldStringifyValue = JSON.stringify(
type === 'Polygon'
? selectedObject[name].coordinates
: selectedObject[name],
null,
4
);
const stringifyValue = JSON.stringify(newValue, null, 4);
if (oldStringifyValue === stringifyValue) {
return;
}
currentObject[name] = stringifyValue;
const rows = stringifyValue ? stringifyValue.split('\n').length : 1;
expandedTextAreas[name].rows = rows;
const { currentObject } = this.state;
currentObject[name] = JSON.stringify(newValue, null, 2);
if (type === 'Polygon') {
newValue = {
__type: type,
Expand Down Expand Up @@ -211,15 +163,9 @@ export default class EditRowDialog extends React.Component {
this.setState({ openObjectPickers });
}

toggleExpandTextArea(name) {
const { expandedTextAreas } = this.state;
expandedTextAreas[name].expanded = !expandedTextAreas[name].expanded;
this.setState({ expandedTextAreas });
}

render() {
const { selectedObject, className, columns, onClose, schema, useMasterKey } = this.props;
const { currentObject, openObjectPickers, expandedTextAreas } = this.state;
const { currentObject, openObjectPickers } = this.state;

const fields = columns.map(column => {
const { name, type, targetClass } = column;
Expand Down Expand Up @@ -281,11 +227,6 @@ export default class EditRowDialog extends React.Component {
inputComponent = (
<TextInput
multiline={true}
rows={
expandedTextAreas[name] &&
expandedTextAreas[name].expanded &&
expandedTextAreas[name].rows
}
disabled={isDisabled}
value={currentObject[name]}
onChange={newValue => this.updateCurrentObject(newValue, name)}
Expand Down Expand Up @@ -416,29 +357,13 @@ export default class EditRowDialog extends React.Component {
inputComponent = <div />;
}

const description = (
<span>
{targetClass ? `${type} <${targetClass}>` : type}
<div style={{ marginTop: '2px' }}>
{expandedTextAreas[name] && expandedTextAreas[name].rows > 3 && (
<a
style={{ color: '#169cee' }}
onClick={() => this.toggleExpandTextArea(name)}
>
{expandedTextAreas[name].expanded ? 'collapse' : 'expand'}
</a>
)}
</div>
</span>
);

return (
<Field
key={name}
label={
<Label
text={name}
description={description}
description={targetClass ? `${type} <${targetClass}>` : type}
/>
}
labelWidth={33}
Expand Down

0 comments on commit 4b24fb8

Please sign in to comment.