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

[Autocomplete Improvement] Allow query editor to resize #9528

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ruchidh
Copy link
Contributor

@ruchidh ruchidh commented Mar 12, 2025

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:

  • Added a resizable prop to CodeEditor (default: true for backward compatibility).
  • Wrapped the MonacoEditor in a Resizable container only when resizable is true.
  • Updated SingleLineInput to pass resizable={false} to CodeEditor, preventing unintended resizing.
  • Ensured multi-line editors retain the existing resizable behavior.

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

  • feat: [Autocomplete Improvement] Allow query editor to resize

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.

Project coverage is 61.75%. Comparing base (411e108) to head (b9049b7).

Files with missing lines Patch % Lines
...ashboards_react/public/code_editor/code_editor.tsx 61.53% 4 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
Linux_1 28.84% <ø> (ø)
Linux_2 ?
Linux_3 39.32% <ø> (ø)
Linux_4 28.76% <61.53%> (+<0.01%) ⬆️
Windows_1 28.86% <ø> (ø)
Windows_2 56.26% <ø> (ø)
Windows_3 39.33% <ø> (ø)
Windows_4 28.76% <61.53%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -175,29 +201,47 @@ export class CodeEditor extends React.Component<Props, {}> {
}
});

const editorComponent = (
Copy link
Member

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

Copy link
Contributor Author

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,

Copy link
Collaborator

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%"
Copy link
Member

@kavilla kavilla Mar 12, 2025

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.

Copy link
Contributor Author

@ruchidh ruchidh Mar 13, 2025

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

Copy link
Member

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.

Copy link
Collaborator

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

Copy link
Member

@ananzh ananzh left a 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?

@ananzh ananzh changed the title fix resize issue in monaco editor [Autocomplete Improvement] Allow query editor to resize Mar 13, 2025
_editor: monaco.editor.IStandaloneCodeEditor | null = null;

constructor(props: Props) {
super(props);
this.state = { editorHeight: (props.height as number) || 20 };
Copy link
Collaborator

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?

Copy link
Contributor Author

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>
);
}
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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

@ruchidh
Copy link
Contributor Author

ruchidh commented Mar 13, 2025

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?

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.

@ruchidh ruchidh requested a review from Maosaic as a code owner March 29, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants