Skip to content

Commit

Permalink
[Console] Fix editor value resetting at layout change (#193516)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes the bug where the editor input resets when we resize the
page and the layout changes. The following fixes were applied:

- The `isVerticalLayout` prop was moved one level down. This removes
unnecessary rerendering of the editor when the layout is changed.
- Allowed the localstorage value to be undefined. Undefined means that
nothing is stored so we should display the default input. If an empty
string is stored, we should display an empty editor.
- Updates local storage with debounce every time when the editor input
is changes. This ensures the editor input is not reset when the editor
is rerendered.
- Updates the local storage value to `undefined` if it is an empty
string when data is being initialized at Main. This ensures that the
default input is displayed when we switch between tabs/pages and the
input is empty.

Before:



https://github.com/user-attachments/assets/a0535780-d75a-4df8-9e04-9d34b6f5f4f1




Now:




https://github.com/user-attachments/assets/7db46c2c-c35e-461f-99e8-b86c66fb6ae5

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
ElenaStoeva and kibanamachine authored Sep 24, 2024
1 parent 194d630 commit 3b8e56f
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 238 deletions.
2 changes: 1 addition & 1 deletion src/plugins/console/common/text_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export interface TextObject {
*
* Used to re-populate a text editor buffer.
*/
text: string;
text: string | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiSpacer } from '@elastic/eui';
import {
EuiFlexGroup,
EuiFlexItem,
EuiPanel,
EuiSpacer,
useIsWithinBreakpoints,
} from '@elastic/eui';

import { Settings } from './settings';
import { Variables } from './variables';

export interface Props {
isVerticalLayout: boolean;
}
export function Config() {
const isVerticalLayout = useIsWithinBreakpoints(['xs', 's', 'm']);

export function Config({ isVerticalLayout }: Props) {
return (
<EuiPanel
color="subdued"
Expand Down
Loading

0 comments on commit 3b8e56f

Please sign in to comment.