Skip to content

Commit

Permalink
[Log Explorer] Update minimum height for JSON doc view (elastic#171553)
Browse files Browse the repository at this point in the history
## 📓 Summary

Closes elastic#171485 

This fix guarantees the JSON doc view will always get a minimum space
independently of the available space, to avoid the current scenario
where a scrollable flyout does not reserve enough space for the JSON tab
content tobe displayed (see recording in the related issue).


https://github.com/elastic/kibana/assets/34506779/2c539047-32cd-4213-bc6f-3062de151426

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
  • Loading branch information
tonyghiani and Marco Antonio Ghiani authored Nov 22, 2023
1 parent 721d68a commit dc29fb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { getHeight } from './get_height';
describe('getHeight', () => {
Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 500 });

const getMonacoMock = (lineCount: number) => {
const getMonacoMock = (lineCount: number, top: number = 200) => {
return {
getDomNode: jest.fn(() => {
return {
getBoundingClientRect: jest.fn(() => {
return {
top: 200,
top,
};
}),
};
Expand All @@ -29,10 +29,17 @@ describe('getHeight', () => {
} as unknown as monaco.editor.IStandaloneCodeEditor;
};
test('when using document explorer, returning the available height in the flyout', () => {
const monacoMock = getMonacoMock(500, 0);

const height = getHeight(monacoMock, true);
expect(height).toBe(475);
});

test('when using document explorer, returning the available height in the flyout has a minimun guarenteed height', () => {
const monacoMock = getMonacoMock(500);

const height = getHeight(monacoMock, true);
expect(height).toBe(275);
expect(height).toBe(400);
});

test('when using classic table, its displayed inline without scrolling', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { monaco } from '@kbn/monaco';
import { MARGIN_BOTTOM, MAX_LINES_CLASSIC_TABLE } from './source';
import { MARGIN_BOTTOM, MAX_LINES_CLASSIC_TABLE, MIN_HEIGHT } from './source';

export function getHeight(editor: monaco.editor.IStandaloneCodeEditor, useDocExplorer: boolean) {
const editorElement = editor?.getDomNode();
Expand All @@ -28,5 +28,5 @@ export function getHeight(editor: monaco.editor.IStandaloneCodeEditor, useDocExp
lineCount > MAX_LINES_CLASSIC_TABLE ? MAX_LINES_CLASSIC_TABLE : lineCount;
result = editor.getTopForLineNumber(displayedLineCount + 1) + lineHeight;
}
return result > 0 ? result : 0;
return Math.max(result, MIN_HEIGHT);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ interface SourceViewerProps {
export const MAX_LINES_CLASSIC_TABLE = 500;
// Displayed margin of the code editor to the window bottom when rendered in the document explorer flyout
export const MARGIN_BOTTOM = 25;
// Minimum height for the source content to guarantee minimum space when the flyout is scrollable.
export const MIN_HEIGHT = 400;

export const DocViewerSource = ({
id,
Expand Down

0 comments on commit dc29fb7

Please sign in to comment.