-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add source editor component #4419
Conversation
PS: For now the dark theme is only supported when specified via props. I guess we can do something better with that once we do some other improvements 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the questions and minor glitch in the docs, me gusta!
* `[{ row: 0, column: 2, type: 'error', text: 'Some error.'}]` | ||
* The type value must be one of `error`, `warning`, or `info`. | ||
*/ | ||
annotations: PropTypes.array, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth using a PropTypes.shape
here or do we not bother because this typically comes from the backend anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm most of the time against those shape objects, as you need to define the whole schema of an object (or an array of objects in this case) in a way that is not very readable and it's easy to make you waste more time removing warnings than helping catching errors. Additionally, in this case the shape is highly dependant on ace, and they don't even have good documentation for it. For instance, the column
property didn't seem to have any effect when I tested it, as all annotations appear in the gutter on the right of the editor. I also had to go to the source code to see what types were supported.
In my opinion, having an example and the vales the type
property accepts is good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me :)
editorProps={{ $blockScrolling: 'Infinity' }} | ||
focus={this.props.focus} | ||
fontSize={this.props.fontSize} | ||
mode="text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to extract this into an optional prop, too?
Might come in handy if we ever use this to display/edit JSON or other modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main problem is that each mode requires an import
from brace
. I couldn't find a way of importing all the modes brace provides, and I'm unsure if it's even safe to do so. I can play a bit more with it and see how it goes. Otherwise I would vote for extending the component when we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah makes sense, let's not overcomplicated it for now.
value={code} /> | ||
``` | ||
|
||
Non-resizable editor without toolbar and with custom height and width: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
States that the editor isn't resizable, when in fact it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was me changing props and texts last minute 😅 Will fix it.
@kroepke addressed your comments and other things I saw:
|
1bf7adf
to
66d8c0e
Compare
I rebased this against master and also removed the hack to reset the undo history. The issue was fixed upstream. |
The failing test is unrelated to the changes, but to the new year 🎉 I'll submit another PR fixing it. |
This is unfortunately not possible when setting `width` to `Infinity`, but at least can be used when it has other values.
Reset undo history when the editor is fully loaded to avoid that users clear textare performing an undo command. The problem behind this is that the editor is created empty and ReactAce does a `setValue` to set the given value for the editor. This is registered as a change by ace, so when pressing undo in an apparently not-changed input, the input is reset. Fixes Graylog2/graylog-plugin-pipeline-processor#224
Copying uses our ClipboardButton component that works without external dependencies. Pasting is currently not possible without the user triggering a system event for it, so we just show a small tooltip.
Hovering over the buttons should display a tooltip with the action they perform.
We only add support for languages that make more sense to write from the web interface.
- Do not resize editor when is not resizable - Do not get text selection when copy button cannot be used
I also noticed an error when using the component in an uncontrolled way, so I updated the examples and added a note on that regard.
This was fixed upstream in securingsincity/react-ace#345
0072e38
to
367638d
Compare
onSuccess={this.focusEditor} | ||
text={this.state.selectedText} | ||
buttonTitle="Copy (Ctrl+C / ⌘C)" | ||
disabled={this.isCopyDisabled} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This passes the isCopyDisabled
function instead of executing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good finding! This got broken in one of the changes I did.
buttonTitle="Copy (Ctrl+C / ⌘C)" | ||
disabled={this.isCopyDisabled} /> | ||
<OverlayTrigger placement="top" trigger="click" overlay={overlay} rootClose> | ||
<Button bsStyle="link" bsSize="sm" title="Paste (Ctrl+V / ⌘V)" disabled={this.isPasteDisabled}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This passes the isPasteDisabled
function instead of executing it.
This PR moves the source code editor we used in the pipelines to the web interface, so other plugins can reuse it if they need it.
I manage to make a few improvements in there, hopefully they will improve the experience of using it:
Bonus: Add dark theme support!
*Dispatching a pasting event from JS doesn't really work for privacy reasons, so the user must trigger an action in the OS. The button therefore only shows a small tooltip indicating it can be done in the Edit menu.