Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/components/DateTimeEditor/DateTimeEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export default class DateTimeEditor extends React.Component {

componentDidMount() {
document.body.addEventListener('click', this.checkExternalClick);
this.inputRef.current.addEventListener('keypress', this.handleKey);
document.body.addEventListener('touchend', this.checkExternalClick);
this.inputRef.current.addEventListener('keydown', this.handleKey);
}

componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
this.inputRef.current.removeEventListener('keypress', this.handleKey);
document.body.removeEventListener('touchend', this.checkExternalClick);
this.inputRef.current.removeEventListener('keydown', this.handleKey);
}

checkExternalClick(e) {
Expand All @@ -51,6 +53,16 @@ export default class DateTimeEditor extends React.Component {
if (e.keyCode === 13) {
this.commitDate();
this.props.onCommit(this.state.value);
e.preventDefault();
} else if (e.keyCode === 27) {
// ESC key - cancel editing
if (this.props.onCancel) {
this.props.onCancel();
} else {
this.props.onCommit(this.props.value);
}
e.preventDefault();
e.stopPropagation();
}
}

Expand Down
28 changes: 24 additions & 4 deletions src/components/GeoPointEditor/GeoPointEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default class GeoPointEditor extends React.Component {
this.latitudeRef.current.focus();
}
this.latitudeRef.current.setSelectionRange(0, String(this.state.latitude).length);
this.latitudeRef.current.addEventListener('keypress', this.handleKeyLatitude);
this.longitudeRef.current.addEventListener('keypress', this.handleKeyLongitude);
this.latitudeRef.current.addEventListener('keydown', this.handleKeyLatitude);
this.longitudeRef.current.addEventListener('keydown', this.handleKeyLongitude);
}

componentWillReceiveProps(props) {
Expand All @@ -48,8 +48,8 @@ export default class GeoPointEditor extends React.Component {
}

componentWillUnmount() {
this.latitudeRef.current.removeEventListener('keypress', this.handleKeyLatitude);
this.longitudeRef.current.removeEventListener('keypress', this.handleKeyLongitude);
this.latitudeRef.current.removeEventListener('keydown', this.handleKeyLatitude);
this.longitudeRef.current.removeEventListener('keydown', this.handleKeyLongitude);
}

checkExternalClick() {
Expand All @@ -73,12 +73,32 @@ export default class GeoPointEditor extends React.Component {
if (e.keyCode === 13 || e.keyCode === 44) {
this.longitudeRef.current.focus();
this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length);
e.preventDefault();
} else if (e.keyCode === 27) {
// ESC key - cancel editing
if (this.props.onCancel) {
this.props.onCancel();
} else {
this.props.onCommit(this.props.value);
}
e.preventDefault();
e.stopPropagation();
}
}

handleKeyLongitude(e) {
if (e.keyCode === 13) {
this.commitValue();
e.preventDefault();
} else if (e.keyCode === 27) {
// ESC key - cancel editing
if (this.props.onCancel) {
this.props.onCancel();
} else {
this.props.onCommit(this.props.value);
}
e.preventDefault();
e.stopPropagation();
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/components/NumberEditor/NumberEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export default class NumberEditor extends React.Component {
componentDidMount() {
this.inputRef.current.setSelectionRange(0, String(this.state.value).length);
document.body.addEventListener('click', this.checkExternalClick);
document.body.addEventListener('keypress', this.handleKey);
document.body.addEventListener('touchend', this.checkExternalClick);
document.body.addEventListener('keydown', this.handleKey);
}

componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
document.body.removeEventListener('keypress', this.handleKey);
document.body.removeEventListener('touchend', this.checkExternalClick);
document.body.removeEventListener('keydown', this.handleKey);
}

checkExternalClick(e) {
Expand All @@ -42,6 +44,17 @@ export default class NumberEditor extends React.Component {
handleKey(e) {
if (e.keyCode === 13) {
this.commitValue();
e.preventDefault();
} else if (e.keyCode === 27) {
// ESC key - cancel editing
if (this.props.onCancel) {
this.props.onCancel();
} else {
// If no onCancel callback, commit the original value
this.props.onCommit(this.props.value);
}
e.preventDefault();
e.stopPropagation();
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/components/StringEditor/StringEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export default class StringEditor extends React.Component {
componentDidMount() {
this.inputRef.current.setSelectionRange(0, this.state.value.length);
document.body.addEventListener('click', this.checkExternalClick);
document.body.addEventListener('keypress', this.handleKey);
document.body.addEventListener('touchend', this.checkExternalClick);
document.body.addEventListener('keydown', this.handleKey);
}

componentWillUnmount() {
document.body.removeEventListener('click', this.checkExternalClick);
document.body.removeEventListener('keypress', this.handleKey);
document.body.removeEventListener('touchend', this.checkExternalClick);
document.body.removeEventListener('keydown', this.handleKey);
}

checkExternalClick(e) {
Expand All @@ -44,7 +46,18 @@ export default class StringEditor extends React.Component {
// Otherwise, we submit
if (!this.props.multiline || !e.shiftKey) {
this.props.onCommit(this.state.value);
e.preventDefault();
}
} else if (e.keyCode === 27) {
// ESC key - cancel editing
if (this.props.onCancel) {
this.props.onCancel();
} else {
// If no onCancel callback, just commit the original value
this.props.onCommit(this.props.value);
}
e.preventDefault();
e.stopPropagation();
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/dashboard/Data/Browser/Editor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={!readonly}
width={width}
onCommit={onCommit}
onCancel={onCancel}
resizable={true}
/>
);
Expand All @@ -45,6 +46,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={true}
width={width}
onCommit={encodeCommit}
onCancel={onCancel}
/>
);
} else if (type === 'Polygon') {
Expand Down Expand Up @@ -83,6 +85,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
multiline={true}
width={width}
onCommit={encodeCommit}
onCancel={onCancel}
/>
);
} else if (type === 'Date') {
Expand All @@ -93,17 +96,18 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
readonly={true}
width={width}
onCommit={() => onCommit(value)}
onCancel={onCancel}
/>
);
} else {
content = <DateTimeEditor value={value || new Date()} width={width} onCommit={onCommit} />;
content = <DateTimeEditor value={value || new Date()} width={width} onCommit={onCommit} onCancel={onCancel} />;
}
} else if (type === 'Boolean') {
content = <BooleanEditor value={value} width={width} onCommit={onCommit} />;
} else if (type === 'Number') {
content = <NumberEditor value={value} width={width} onCommit={onCommit} />;
content = <NumberEditor value={value} width={width} onCommit={onCommit} onCancel={onCancel} />;
} else if (type === 'GeoPoint') {
content = <GeoPointEditor value={value} width={width} onCommit={onCommit} />;
content = <GeoPointEditor value={value} width={width} onCommit={onCommit} onCancel={onCancel} />;
} else if (type === 'File') {
content = <FileEditor value={value} width={width} onCommit={onCommit} onCancel={onCancel} />;
} else if (type === 'ACL') {
Expand All @@ -121,7 +125,7 @@ const Editor = ({ top, left, type, targetClass, value, readonly, width, onCommit
);
}
};
content = <StringEditor value={value ? value.id : ''} width={width} onCommit={encodeCommit} />;
content = <StringEditor value={value ? value.id : ''} width={width} onCommit={encodeCommit} onCancel={onCancel} />;
}

return <div style={{ position: 'absolute', top: top, left: left }}>{content}</div>;
Expand Down
Loading