-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Console Monaco migration] Implement history #183181
Merged
Merged
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
00533b2
[Console] Implement method and url path autocomplete
yuliacech 6f2911b
[Console] Tests
yuliacech cc4f6ae
[Console] Implement url params autocomplete
yuliacech 084e274
[Console] Implement body params autocomplete suggestions
yuliacech 2562e53
[Console] Fix merge conflict issues
yuliacech 0485996
[Console] Fix merge conflict issues
yuliacech 5e17ca1
[Console] Remove console log
yuliacech 80f801d
[Console] Add template
yuliacech eb7f43c
Merge branch 'main' into console/implement_autocomplete_body
yuliacech fc47ebd
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine b00fa24
[Console] Clean up tests
yuliacech 3e0d610
[Console] Fix imports
yuliacech 9e192d1
[Console] Fix tokens parsing for nested objects
yuliacech a911984
Merge branch 'main' into console/implement_autocomplete_body
yuliacech c1b393d
[Console] Start migrating the console history to monaco
yuliacech 1abcc66
[Console] Implement console history in monaco
yuliacech 28bf9b7
Merge branch 'main' into console/migrate_history
yuliacech 8c03ef3
[Console] Remove unused imports
yuliacech 4c172b5
[Console] Fixed the new line insertion
yuliacech aa86dcf
Merge branch 'main' into console/migrate_history
yuliacech 9c33bfe
Merge branch 'main' into console/migrate_history
yuliacech 511722d
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 48c0fb6
[Console] Add comments
yuliacech cb83b15
Merge branch 'main' into console/migrate_history
yuliacech 42ff316
[Console] Fix types
yuliacech a7cfd66
[Console] Fix types
yuliacech 7f93171
[Console] Fix an issue when inserting a history request
yuliacech 77495e0
Merge branch 'main' into console/migrate_history
yuliacech ca60bbc
[Console] Add unit tests
yuliacech 5f6ed4e
Merge branch 'main' into console/migrate_history
yuliacech dc2e42e
Merge branch 'main' into console/migrate_history
yuliacech 67968c6
[Console] Fix inserting the history request on a line outside of a pa…
yuliacech c4e0741
Merge branch 'main' into console/migrate_history
yuliacech fb2b7dc
[Console] Fix merge conflict issues
yuliacech f5ae554
[Console] Fix eslint issues
yuliacech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/plugins/console/public/application/containers/console_history/history_viewer_monaco.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useCallback, useRef } from 'react'; | ||
import { css } from '@emotion/react'; | ||
import { CONSOLE_LANG_ID, CONSOLE_THEME_ID, monaco } from '@kbn/monaco'; | ||
import { CodeEditor } from '@kbn/code-editor'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { formatRequestBodyDoc } from '../../../lib/utils'; | ||
import { DevToolsSettings } from '../../../services'; | ||
import { useResizeCheckerUtils } from '../editor/monaco/hooks'; | ||
|
||
export const HistoryViewer = ({ | ||
settings, | ||
req, | ||
}: { | ||
settings: DevToolsSettings; | ||
req: { method: string; endpoint: string; data: string; time: string } | null; | ||
}) => { | ||
const divRef = useRef<HTMLDivElement | null>(null); | ||
const { setupResizeChecker, destroyResizeChecker } = useResizeCheckerUtils(); | ||
|
||
const editorDidMountCallback = useCallback( | ||
(editor: monaco.editor.IStandaloneCodeEditor) => { | ||
setupResizeChecker(divRef.current!, editor); | ||
}, | ||
[setupResizeChecker] | ||
); | ||
|
||
const editorWillUnmountCallback = useCallback(() => { | ||
destroyResizeChecker(); | ||
}, [destroyResizeChecker]); | ||
let renderedHistoryRequest: string; | ||
if (req) { | ||
const indent = true; | ||
const formattedData = req.data ? formatRequestBodyDoc([req.data], indent).data : ''; | ||
renderedHistoryRequest = req.method + ' ' + req.endpoint + '\n' + formattedData; | ||
} else { | ||
renderedHistoryRequest = i18n.translate('console.historyPage.noHistoryTextMessage', { | ||
defaultMessage: 'No history available', | ||
}); | ||
} | ||
return ( | ||
<div | ||
css={css` | ||
width: 100%; | ||
`} | ||
ref={divRef} | ||
> | ||
<CodeEditor | ||
languageId={CONSOLE_LANG_ID} | ||
value={renderedHistoryRequest} | ||
fullWidth={true} | ||
editorDidMount={editorDidMountCallback} | ||
editorWillUnmount={editorWillUnmountCallback} | ||
options={{ | ||
readOnly: true, | ||
fontSize: settings.fontSize, | ||
wordWrap: settings.wrapMode ? 'on' : 'off', | ||
theme: CONSOLE_THEME_ID, | ||
automaticLayout: true, | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As far as I understand, the request from history will always end up at column 1 unless it is not inside a request - then it might end up in the middle of the line if the cursor is there. In Ace editor, it always ends up at column 1. Should we do the same here for consistency?
In Ace editor:
Screen.Recording.2024-05-17.at.17.00.22.mov
In this PR:
Screen.Recording.2024-05-17.at.16.58.34.mov
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.
Thanks a lot, @ElenaStoeva! Another great catch, fixed in 67968c6