Skip to content
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

Use AceEditor for Query Snippets #3973

Merged
merged 6 commits into from
Jul 17, 2019
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
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}
gabrieldutra marked this conversation as resolved.
Show resolved Hide resolved
/>
</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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative that I think makes better sense #3974

Copy link
Member Author

@gabrieldutra gabrieldutra Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the icons for the Query Snippets context or...

Suggested change
feedbackIcons

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a really nice and fun UX, but not a must. I have no strong opinion.

/>
</Modal>
);
Expand Down