-
Notifications
You must be signed in to change notification settings - Fork 8.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
[Console Migration] Add action for auto indentation #181613
[Console Migration] Add action for auto indentation #181613
Conversation
Pinging @elastic/kibana-management (Team:Kibana Management) |
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.
Thanks a lot for implementing the auto-indent, @ElenaStoeva!
Since loosing any user content might be an issue, let's discuss in the team sync on how to approach auto-indentation of comments
c2ebb1d
to
09f5333
Compare
/ci |
...lugins/console/public/application/containers/editor/monaco/monaco_editor_actions_provider.ts
Outdated
Show resolved
Hide resolved
|
||
const autoIndentedText = getAutoIndentedRequests(parsedRequests, selectedText); | ||
|
||
this.editor.executeEdits('', [ |
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.
nit: I think for completeness sake we should use some kind of string to indicate that the edit was made by the auto-indent button
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.
Ah I wasn't sure how this string would be used... will it be visible to the user somehow or do you think we'll only need it for internal use? I added a translated string (in case it will be displayed to the user), let me know what you think.
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 think the string might be used for undo/redo actions which I don't think we currently have. I believe the value won't be displayed in the UI to the user though.
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 see... Then it might be good to store this in a constant in case it's needed somewhere. I added this change with 3e1264f.
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.
Thanks a lot for working on this feature, @ElenaStoeva!
I think that is a good approach to only auto-indent the requests that don't contain any comments.
I think though that we don't need to keep track of the text of the request in the parser: You are already using the model to get the text in the range of selected requests with model.getValueInRange
. Each request also has startLineNumber
and endLineNumber
. If you pass the model to the util auto-indent
function, you should be able to iterate over the requests array and for each you should know when it's the start line with the method (startLineNumber
) and where the request body begins (startLineNumber + 1
) and where the request body ends (endLineNumber
). With this line numbers you can get the text from the model and do the same check for comments. WDYT?
4f3da2b
to
50363cc
Compare
Thanks for the review @yuliacech! You're right, we don't need to add a |
845ccf7
to
addacb6
Compare
@@ -74,6 +74,10 @@ export const MonacoEditor = ({ initialTextValue }: EditorProps) => { | |||
return actionsProvider.current!.getDocumentationLink(docLinkVersion); | |||
}, [docLinkVersion]); | |||
|
|||
const autoIndentCallback = useCallback(async (event: React.MouseEvent) => { |
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.
nit: the argument "event" is now unused and can be deleted
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.
Nice catch! I removed it in 3e1264f.
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.
Thanks a lot for addressing my comments, @ElenaStoeva!
Latest changes LGTM 👍
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @ElenaStoeva |
Closes #180213
Summary
This PR adds an action for applying indentation to the selected requests in the Console Monaco editor.
Screen.Recording.2024-05-14.at.16.20.03.mov
Note: This PR doesn't auto-indent requests that contain comments. This will be part of a follow-up work (#182138).