Skip to content

Commit

Permalink
[Discover] Fix height of JSON tab in Document flyout when using Docum…
Browse files Browse the repository at this point in the history
…ent explorer in Safari (#129348)
  • Loading branch information
jughosta authored Apr 4, 2022
1 parent 513c81b commit feab5eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ interface JsonCodeEditorCommonProps {
jsonValue: string;
onEditorDidMount: (editor: monaco.editor.IStandaloneCodeEditor) => void;
width?: string | number;
height?: string | number;
hasLineNumbers?: boolean;
}

export const JsonCodeEditorCommon = ({
jsonValue,
width,
height,
hasLineNumbers,
onEditorDidMount,
}: JsonCodeEditorCommonProps) => {
Expand All @@ -55,6 +57,7 @@ export const JsonCodeEditorCommon = ({
<CodeEditor
languageId={XJsonLang.ID}
width={width}
height={height}
value={jsonValue || ''}
editorDidMount={onEditorDidMount}
aria-label={codeEditorAriaLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const DocViewerSource = ({
hasLineNumbers,
}: SourceViewerProps) => {
const [editor, setEditor] = useState<monaco.editor.IStandaloneCodeEditor>();
const [editorHeight, setEditorHeight] = useState<number>();
const [jsonValue, setJsonValue] = useState<string>('');
const { uiSettings } = useDiscoverServices();
const useNewFieldsApi = !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE);
Expand All @@ -59,7 +60,9 @@ export const DocViewerSource = ({
}
}, [reqState, hit]);

// setting editor height based on lines height and count to stretch and fit its content
// setting editor height
// - classic view: based on lines height and count to stretch and fit its content
// - explorer: to fill the available space of the document flyout
useEffect(() => {
if (!editor) {
return;
Expand All @@ -76,12 +79,11 @@ export const DocViewerSource = ({
}

if (!jsonValue || jsonValue === '') {
editorElement.style.height = '0px';
setEditorHeight(0);
} else {
editorElement.style.height = `${height}px`;
setEditorHeight(height);
}
editor.layout();
}, [editor, jsonValue, useDocExplorer]);
}, [editor, jsonValue, useDocExplorer, setEditorHeight]);

const loadingState = (
<div className="sourceViewer__loading">
Expand Down Expand Up @@ -128,6 +130,7 @@ export const DocViewerSource = ({
<JSONCodeEditorCommonMemoized
jsonValue={jsonValue}
width={width}
height={editorHeight}
hasLineNumbers={hasLineNumbers}
onEditorDidMount={(editorNode: monaco.editor.IStandaloneCodeEditor) => setEditor(editorNode)}
/>
Expand Down

0 comments on commit feab5eb

Please sign in to comment.