-
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
Change Role Mappings editor to use CodeEditor #107459
Change Role Mappings editor to use CodeEditor #107459
Conversation
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.
Author's notes for reviewers
minLines={6} | ||
maxLines={30} | ||
isReadOnly={false} | ||
setOptions={{ | ||
showLineNumbers: true, | ||
fullWidth={true} | ||
height="300px" |
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.
This component doesn't support maxLines
/minLines
but it needs a height, so I just set it to 300px which seems reasonable (which equals around 17 lines), right in the middle).
fullWidth={true} | ||
height="300px" | ||
options={{ | ||
accessibilitySupport: 'off', |
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.
Disabling accessibilitySupport
sounds bad, but I think it's necessary. This prevents Monaco from enabling shortcuts such as these that appear to be selected by default on macOS:
None of these should be used when editing code. It just causes frustration when typing.
Seeing as this is also an optional UI for editing role mappings, I think it's safe to disable accessibilitySupport
here.
jest.mock('../../../../../../../../src/plugins/kibana_react/public', () => ({ | ||
...jest.requireActual('../../../../../../../../src/plugins/kibana_react/public'), | ||
useKibana: jest.fn().mockReturnValue({ | ||
services: { docLinks: { links: { apis: { createRoleMapping: 'createRoleMappingLink' } } } }, | ||
}), | ||
})); | ||
|
||
describe('JSONRuleEditor', () => { | ||
const mockChangeEvent = {} as monaco.editor.IModelContentChangedEvent; | ||
const renderView = (props: React.ComponentProps<typeof JSONRuleEditor>) => { | ||
const coreStart = coreMock.createStart(); | ||
return mountWithIntl( | ||
<KibanaContextProvider services={coreStart}> | ||
<JSONRuleEditor {...props} /> | ||
</KibanaContextProvider> | ||
); | ||
return shallowWithIntl(<JSONRuleEditor {...props} />); | ||
}; |
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.
Jest uses jsdom to render components, but Monaco requires a canvas. Instead of installing a separate package just to use for this test, I opted for a shallow render which still allows us to exercise these unit test cases.
Note that to use a shallow mock this has to be the top level component, so as a result I had to mock useKibana()
.
@elasticmachine merge upstream |
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.
Looks good, one question below.
import { KibanaContextProvider } from 'src/plugins/kibana_react/public'; | ||
import type { monaco } from '@kbn/monaco'; | ||
import { shallowWithIntl } from '@kbn/test/jest'; | ||
import { CodeEditor } from 'src/plugins/kibana_react/public'; |
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.
Have you tried using CodeEditorField
component? It renders the code editor like a form field with the correct border and padding so it looks a lot nicer than the plain Monaco editor.
Example here: x-pack/plugins/security/public/management/api_keys/api_keys_grid/create_api_key_flyout.tsx
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.
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.
Nice, looking much better! :)
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.
LGTM!
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
Resolves #107078.
Before:
After:
Manually tested various bits of functionality (error detection, syntax highlighting, scrolling, resizing, etc. All works fine with the new editor. Used
src/plugins/discover/public/application/components/json_code_editor/json_code_editor_common.tsx
for inspiration.