Skip to content

Commit

Permalink
Use AceEditor for Query Snippets (getredash#3973)
Browse files Browse the repository at this point in the history
Co-Authored-By: Ran Byron <[email protected]>
  • Loading branch information
2 people authored and harveyrendell committed Nov 14, 2019
1 parent 61acbd7 commit 52fefe0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
19 changes: 19 additions & 0 deletions client/app/assets/less/ant.less
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,22 @@
}
}
}

// overrides for tall form components such as ace editor
.@{form-prefix-cls}-item {
&-children {
display: block; // so feeback icon positions correctly
}

// no change for short components, sticks to body for tall ones
&-children-icon {
top: auto !important;
bottom: 8px;

// makes the icon white instead of see-through
& svg {
background: white;
border-radius: 50%;
}
}
}
22 changes: 22 additions & 0 deletions client/app/components/AceEditorInput.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { forwardRef } from 'react';
import AceEditor from 'react-ace';

import './AceEditorInput.less';

function AceEditorInput(props, ref) {
return (
<div className="ace-editor-input">
<AceEditor
ref={ref}
mode="sql"
theme="textmate"
height="100px"
editorProps={{ $blockScrolling: Infinity }}
showPrintMargin={false}
{...props}
/>
</div>
);
}

export default forwardRef(AceEditorInput);
11 changes: 11 additions & 0 deletions client/app/components/AceEditorInput.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.ace-editor-input {
// hide ghost cursor when not focused
.ace_hidden-cursors {
opacity: 0;
}

// allow Ant Form feedback icon to hover scrollbar
.ace_scrollbar {
z-index: auto;
}
}
3 changes: 3 additions & 0 deletions client/app/components/dynamic-form/DynamicForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Icon from 'antd/lib/icon';
import { includes, isFunction } from 'lodash';
import Select from 'antd/lib/select';
import notification from '@/services/notification';
import AceEditorInput from '@/components/AceEditorInput';
import { Field, Action, AntdForm } from '../proptypes';
import helper from './dynamicFormHelper';

Expand Down Expand Up @@ -176,6 +177,8 @@ class DynamicForm extends React.Component {
return getFieldDecorator(name, options)(<InputNumber {...props} />);
} else if (type === 'textarea') {
return getFieldDecorator(name, options)(<Input.TextArea {...props} />);
} else if (type === 'ace') {
return getFieldDecorator(name, options)(<AceEditorInput {...props} />);
}
return getFieldDecorator(name, options)(<Input {...props} />);
}
Expand Down
1 change: 1 addition & 0 deletions client/app/components/proptypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Field = PropTypes.shape({
name: PropTypes.string.isRequired,
title: PropTypes.string,
type: PropTypes.oneOf([
'ace',
'text',
'textarea',
'email',
Expand Down
6 changes: 3 additions & 3 deletions client/app/components/query-snippets/QuerySnippetDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ class QuerySnippetDialog extends React.Component {
{ name: 'description', title: 'Description', type: 'text' },
{ name: 'snippet',
title: 'Snippet',
type: 'textarea',
required: true,
props: { autosize: { minRows: 3, maxRows: 6 } } },
type: 'ace',
required: true },
].map(field => ({ ...field, readOnly, initialValue: get(querySnippet, field.name, '') }));

return (
Expand Down Expand Up @@ -79,6 +78,7 @@ class QuerySnippetDialog extends React.Component {
fields={formFields}
onSubmit={this.handleSubmit}
hideSubmitButton
feedbackIcons
/>
</Modal>
);
Expand Down

0 comments on commit 52fefe0

Please sign in to comment.