-
Notifications
You must be signed in to change notification settings - Fork 983
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
[Autocomplete Improvement] Allow query editor to resize #9528
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ruchi Sharma <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9528 +/- ##
==========================================
- Coverage 61.78% 61.75% -0.03%
==========================================
Files 3807 3807
Lines 91933 91942 +9
Branches 14597 14601 +4
==========================================
- Hits 56802 56783 -19
- Misses 31452 31528 +76
+ Partials 3679 3631 -48
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Ruchi Sharma <[email protected]>
src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx
Show resolved
Hide resolved
@@ -175,29 +201,47 @@ export class CodeEditor extends React.Component<Props, {}> { | |||
} | |||
}); | |||
|
|||
const editorComponent = ( |
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.
moving the editor component outside of the return statement in theory shouldn't matter but given the amount of state issues we have and what is being rendered i'm a little bit worried about doing this. have we validated switching languages, have we validated the collapse feature, datat\ that are from a different language, etc
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 have tested across all languages switch and with single line too. it works fine.
This is just code abstraction, in a separate variable to make it more readable and optimized.
it will not impact, as it is not a change in logic. This was needed to avoid duplicate code, for multiple scenario, like for single inline we don't need resize but for multiline only we need resize, so abstracted the common code in a variable,
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 agree to Ruchi's comments. Since we are now rendering this in two conditionals, i think it makes sense to put it out like what she did. But yeah as long as she has tested thoroughly i think we good
onChange={onChange} | ||
editorWillMount={this._editorWillMount} | ||
editorDidMount={this._editorDidMount} | ||
width="100%" |
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 this might be a breaking change. the code editor technically is globally accessible. if anyone is added
i see that the parent component width is still the editor width however, i think it might make this prone to someone changing this value and not knowing where the original value came from.
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.
sorry i didn't get this one, can i get more context on this ?
someone changing this value and not knowing where the original value came from.
This width:100% is just making sure the child takes the full width of parent editor, the original width is alreay d being set in the parent component
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 width prop is passed to both the Resizable component and the inner div style. The Resizable component expects a numeric width value (width as number), but the width prop in the CodeEditor interface is defined as width?: string | number, meaning it could be either a string (like "100%") or a number. If someone changes the width prop to a string value (like "100%"), it might cause issues with the Resizable component, which expects a number. Additionally, there's no clear documentation or indication that the width prop needs to be a number when resizable is true, which could lead to confusion.
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 what Ruchi did is fine. Like she said, whether resizable: true or false
, the parent div
in the code below gets the passed width
prop. So that div will get the passed prop, and the code editor will just take 100%
width of whatever was set of the parent
src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx
Show resolved
Hide resolved
Signed-off-by: Ruchi Sharma <[email protected]>
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 don't think we need to bring in another dependency for resize. So CodeEditor is wrapped in the <div className="defaultEditor"
container. .defaultEditor
is the CSS class for the container div that wraps everything, including the Monaco editor. The <CodeEditor>
component is a child of this container and is a React wrapper around the actual Monaco editor. The DefaultEditor container could be resizable. In monaco-editor, there is a prop called automaticLayout. If it is true, then the Monaco editor detects this change and adjusts its internal layout according to the container change.
Can we pull the monaco-editor bump PR and research on top of that? I think we could utilize native browser capabilities without additional dependencies and limit the change to DefaultEditor for query only without affecting other components?
_editor: monaco.editor.IStandaloneCodeEditor | null = null; | ||
|
||
constructor(props: Props) { | ||
super(props); | ||
this.state = { editorHeight: (props.height as number) || 20 }; |
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.
where was this 20
from? Is it from previous code? And is this something we can leverage a varialbe instead of hard coding a 20
?
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.
So 20 is the default for one line height of editor that we have been using everywhere. I will assign this in a const
<ReactResizeDetector handleWidth handleHeight onResize={this._updateDimensions} /> | ||
</React.Fragment> | ||
); | ||
} |
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 a
code_editor.test.tsx
. Could we add some unit tests in there that acommpanies what you have added/changed? - Does this warrant some extra cypress tests to ensure that things are not broken? ie when changing it and going to back to another language, or changing editor, etc etc
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.
Updates the test with new changes.
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.
are you referring to the update on the snapshot test? I dont' think that tests the new functionality you added
So, current version of monaco editor does not support resizable, the default editor is not resizable, i will check in new version of monaco if they have fixed this. |
Description
This PR introduces a new resizable prop to the CodeEditor component, allowing conditional resizing based on the use case. The SingleLineInput component now explicitly disables resizing, ensuring a fixed-height editor for single-line inputs while keeping the resizing functionality for multi-line editors.
Changes:
Why?
Previously, resizing was not working. With this change, the resizing behavior is now configurable per component usage.
Testing:
Verified that multi-line editors remain resizable.
Confirmed that SingleLineInput remains a fixed height and does not show resizing controls.
Ensured no regressions in existing behavior.
Screenshot
Screen.Recording.2025-03-11.at.4.37.40.PM.mov
Changelog
Check List
yarn test:jest
yarn test:jest_integration