Skip to content

Commit

Permalink
forcing ace editor to refresh when it is shown (#5038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Lyons authored and williaster committed May 21, 2018
1 parent ce0011e commit 0e1fb62
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component
super(props);
this.onSqlExpressionChange = this.onSqlExpressionChange.bind(this);
this.onSqlExpressionClauseChange = this.onSqlExpressionClauseChange.bind(this);
this.handleAceEditorRef = this.handleAceEditorRef.bind(this);

this.selectProps = {
multi: false,
Expand All @@ -59,6 +60,10 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component
}
}

componentDidUpdate() {
this.aceEditorRef.editor.resize();
}

onSqlExpressionClauseChange(clause) {
this.props.onChange(this.props.adhocFilter.duplicateWith({
clause: clause && clause.clause,
Expand All @@ -73,6 +78,12 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component
}));
}

handleAceEditorRef(ref) {
if (ref) {
this.aceEditorRef = ref;
}
}

render() {
const { adhocFilter, height } = this.props;

Expand Down Expand Up @@ -101,6 +112,7 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component
</FormGroup>
<FormGroup>
<AceEditor
ref={this.handleAceEditorRef}
mode="sql"
theme="github"
height={(height - 100) + 'px'}
Expand Down
15 changes: 15 additions & 0 deletions superset/assets/src/explore/components/AdhocMetricEditPopover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default class AdhocMetricEditPopover extends React.Component {
this.onDragDown = this.onDragDown.bind(this);
this.onMouseMove = this.onMouseMove.bind(this);
this.onMouseUp = this.onMouseUp.bind(this);
this.handleAceEditorRef = this.handleAceEditorRef.bind(this);
this.refreshAceEditor = this.refreshAceEditor.bind(this);
this.state = {
adhocMetric: this.props.adhocMetric,
width: startingWidth,
Expand Down Expand Up @@ -137,6 +139,16 @@ export default class AdhocMetricEditPopover extends React.Component {
document.removeEventListener('mousemove', this.onMouseMove);
}

handleAceEditorRef(ref) {
if (ref) {
this.aceEditorRef = ref;
}
}

refreshAceEditor() {
setTimeout(() => this.aceEditorRef.editor.resize(), 0);
}

render() {
const {
adhocMetric: propsAdhocMetric,
Expand Down Expand Up @@ -200,6 +212,8 @@ export default class AdhocMetricEditPopover extends React.Component {
defaultActiveKey={adhocMetric.expressionType}
className="adhoc-metric-edit-tabs"
style={{ height: this.state.height, width: this.state.width }}
onSelect={this.refreshAceEditor}
animation={false}
>
<Tab className="adhoc-metric-edit-tab" eventKey={EXPRESSION_TYPES.SIMPLE} title="Simple">
<FormGroup>
Expand All @@ -216,6 +230,7 @@ export default class AdhocMetricEditPopover extends React.Component {
<Tab className="adhoc-metric-edit-tab" eventKey={EXPRESSION_TYPES.SQL} title="Custom SQL">
<FormGroup>
<AceEditor
ref={this.handleAceEditorRef}
mode="sql"
theme="github"
height={(this.state.height - 43) + 'px'}
Expand Down

0 comments on commit 0e1fb62

Please sign in to comment.