Conversation
- a simple wrapper around Monaco editor - pass a command and render it in read-only mode - allow minimal customization of the component (show/hide line numbers) - allow inline copy of the command re RI-7936
re RI-7936
Code Coverage - Frontend unit tests
Test suite run success5553 tests passing in 708 suites. Report generated by 🧪jest coverage report action from 0482118 |
pd-redis
left a comment
There was a problem hiding this comment.
None of the comments are deal-breakers, that is why I approve this PR
| import Router from 'uiSrc/Router' | ||
| import { StyledContainer } from './helpers/styles' | ||
| import { GlobalStyles } from 'uiSrc/styles/globalStyles' | ||
| import MonacoEnvironmentInitializer from 'uiSrc/components/MonacoEnvironmentInitializer/MonacoEnvironmentInitializer' |
There was a problem hiding this comment.
I am OK with this being setup here, but just for information, you can do the same per story, not necessarily on global level
There was a problem hiding this comment.
I agree, and initially tried that, but something failed. Anyway, I gave it another shot and now it worked as expected, so these helpers now live in the related story, instead of the global setup. c3e4a6a
Thanks for pointing it 👍
| @@ -0,0 +1,47 @@ | |||
| import { monaco as monacoEditor } from 'react-monaco-editor' | |||
There was a problem hiding this comment.
I would much more prefer to have an abstraction around monaco.
I know we used on quite few places already
There was a problem hiding this comment.
I agree completely with that. Initially, that's what I went for - to see whether we already have such a component. And I see there's already a MonacoEditor component, but it's quite complex with editing, inline editor, and dedicated editor features. For CommandView, we need something simpler - a read-only code display.
So, the way I see this abstraction layer:
- it should be something simple
- it should cover everything that can be accepted by Monaco Editor, at this point it should be a pass-through for all props
- still, it should be the central point, where all the core logic lives
- and serve as a layer where we can apply some specific customizations (now and in the future)
Still, I come up with this simple draft (which I'm not sure brings the value you wanted, so that’s why I put it in a separate pull request). #5417
But basically, this is how I see it at this point:
- start with something simple
- replace it later on all places where we use Monaco
- and leave it as the single abstraction point in the codebase
| const withFlexContainer = (Story: React.ComponentType) => ( | ||
| <div | ||
| style={{ | ||
| width: '100%', | ||
| height: '100%', | ||
| display: 'flex', | ||
| }} | ||
| > | ||
| <Story /> | ||
| </div> | ||
| ) |
There was a problem hiding this comment.
You can just merge the 2 decorators
| @@ -0,0 +1,64 @@ | |||
| import React, { useContext, useMemo, useRef } from 'react' | |||
| import ReactMonacoEditor, { monaco as monacoEditor } from 'react-monaco-editor' | |||
| const editorOptions = useMemo( | ||
| () => | ||
| merge({}, defaultMonacoOptions, COMMAND_VIEW_EDITOR_OPTIONS, { | ||
| lineNumbers: showLineNumbers ? 'on' : 'off', | ||
| }), | ||
| [showLineNumbers], | ||
| ) |
There was a problem hiding this comment.
Instead of use memo, why not just export 2 kind of options from constants and choose based on showLineNumbers
There was a problem hiding this comment.
Thanks for the suggestion! You're right that with the current binary choice for showLineNumbers, exporting two pre-built variants from constants would be simpler and cleaner. And since this prop typically doesn't change during the component's lifecycle, useMemo is indeed a safeguard for a problem we may never encounter.
export const COMMAND_VIEW_OPTIONS = {
withLineNumbers: { ...baseOptions, lineNumbers: 'on't },
withoutLineNumbers: { ...baseOptions, lineNumbers: 'off' },
}However, I decided to keep the merge approach with prop overrides for extensibility. Right now we only have a single config override, but I want to make it easy to add more in the future. With this pattern, adding another override is just one more line:
merge({}, defaultMonacoOptions, COMMAND_VIEW_EDITOR_OPTIONS, {
lineNumbers: showLineNumbers ? 'on' : 'off',
// wordWrap: enableWordWrap ? 'on' : 'off', // easy to add
// and many more...
})As for useMemo - normally I would drop it to keep things simpler, but I'm keeping it with the same reasoning. If we later introduce a prop that actually changes during the component's lifecycle, the safeguard is already in place.
| } | ||
|
|
||
| return ( | ||
| <S.EditorWrapper className={className} data-testid={dataTestId}> |
There was a problem hiding this comment.
I would not provide default test id, this makes it possible to have same test id on the same screen
…nt setup - Updated the storybook for CommandView component to use a new decorator for Monaco environment initialization. - Removed the previous Redis commands initializer and replaced it with Monaco setup for syntax highlighting. - Ensured that Monaco components are properly rendered within the story context. re #RI-7936
…ators re #RI-7936
3d70aa7
re #RI-7936
…r references - removed the editorRef and editorDidMount function as they were not utilized in this simple component re #RI-7936
…egration - Added CodeEditorWrapper component as a thin wrapper around the Monaco editor. - Created corresponding types for props to allow future customization. - Exported the new component and its types for use in other parts of the application. re #RI-7936
…react-monaco-editor re #RI-7936
What
Created a simple component for showing code snippets, later to be used for the Vector Search feature:
PS: You can review the Storybook examples for more details and usage instructions.
And open http://localhost:6006/?path=/docs/pages-vector-search-components-commandview--docs in your browser.
Testing
The component comes with a very minimal API, you need to pass only the command:
Copy command
There is an inline button that lets you copy the command.
Optional: You can attach a callback handler as well.
Note
Low Risk
Low risk UI addition: new wrapper components and read-only Monaco configuration with unit tests/storybook; minimal impact beyond new exports in
components/base.Overview
Adds a new
CodeEditorbase component as a thin wrapper aroundreact-monaco-editor, automatically deriving the Monaco theme fromThemeContext(with an override) and exporting it viacomponents/base.Introduces
CommandViewfor Vector Search to display a command string in a read-only Monaco editor with optional line numbers and an inlineCopyButton, plus Monaco option presets, Storybook stories, and unit tests covering rendering, language defaults/overrides, line-number toggling, and copy callback behavior.Written by Cursor Bugbot for commit 0482118. This will update automatically on new commits. Configure here.