Skip to content

Commit 95f88d4

Browse files
authored
fix(schema): use editor for rendering schema export instead of LG code for performance COMPASS-8980 (#6731)
1 parent 72c99fb commit 95f88d4

File tree

6 files changed

+38
-17
lines changed

6 files changed

+38
-17
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-e2e-tests/tests/auto-connect.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ describe('Automatically connecting from the command line', function () {
308308

309309
await browser.execute(() => {
310310
// eslint-disable-next-line @typescript-eslint/no-var-requires
311-
(require('electron').ipcRenderer as any).call(
312-
'test:show-connect-window'
313-
);
311+
require('electron').ipcRenderer.call('test:show-connect-window');
314312
});
315313

316314
// Switch to the other window

packages/compass-e2e-tests/tests/collection-schema-tab.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ describe('Collection schema tab', function () {
135135

136136
const exportSchemaContent = browser.$(Selectors.ExportSchemaOutput);
137137
await exportSchemaContent.waitForDisplayed();
138-
const text = await browser.$(Selectors.ExportSchemaOutput).getText();
138+
const text = await browser.getCodemirrorEditorText(
139+
Selectors.ExportSchemaOutput
140+
);
139141
const parsedText = JSON.parse(text);
140142
delete parsedText.$defs;
141143
expect(parsedText).to.deep.equal({

packages/compass-editor/src/editor.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ type MultilineEditorProps = EditorProps & {
14071407
editorClassName?: string;
14081408
actionsClassName?: string;
14091409
onExpand?: () => void;
1410+
onCopy?: () => void;
14101411
expanded?: boolean;
14111412
};
14121413

@@ -1420,6 +1421,7 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14201421
editorClassName,
14211422
actionsClassName,
14221423
darkMode: _darkMode,
1424+
onCopy,
14231425
onExpand,
14241426
expanded,
14251427
...props
@@ -1430,6 +1432,9 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14301432
const containerRef = useRef<HTMLDivElement>(null);
14311433
const editorRef = useRef<EditorRef>(null);
14321434

1435+
const onCopyRef = useRef(onCopy);
1436+
onCopyRef.current = onCopy;
1437+
14331438
useImperativeHandle(
14341439
ref,
14351440
() => {
@@ -1441,6 +1446,7 @@ const MultilineEditor = React.forwardRef<EditorRef, MultilineEditorProps>(
14411446
return editorRef.current?.unfoldAll() ?? false;
14421447
},
14431448
copyAll() {
1449+
onCopyRef.current?.();
14441450
return editorRef.current?.copyAll() ?? false;
14451451
},
14461452
prettify() {

packages/compass-schema/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@mongodb-js/compass-collection": "^4.49.2",
7676
"@mongodb-js/compass-components": "^1.34.2",
7777
"@mongodb-js/compass-connections": "^1.50.2",
78+
"@mongodb-js/compass-editor": "^0.36.2",
7879
"@mongodb-js/compass-field-store": "^9.25.2",
7980
"@mongodb-js/compass-logging": "^1.6.2",
8081
"@mongodb-js/compass-telemetry": "^1.4.2",

packages/compass-schema/src/components/export-schema-modal.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { type ChangeEvent, useCallback } from 'react';
22
import { connect } from 'react-redux';
33
import {
44
Button,
5-
Code,
5+
KeylineCard,
66
ModalBody,
77
ModalHeader,
88
ModalFooter,
@@ -15,6 +15,7 @@ import {
1515
Label,
1616
CancelLoader,
1717
} from '@mongodb-js/compass-components';
18+
import { CodemirrorMultilineEditor } from '@mongodb-js/compass-editor';
1819

1920
import type { RootState } from '../stores/store';
2021
import {
@@ -35,11 +36,17 @@ const contentContainerStyles = css({
3536
paddingBottom: spacing[400],
3637
});
3738

38-
const codeStyles = css({
39+
const codeEditorContainerStyles = css({
3940
maxHeight: `${spacing[1600] * 4 - spacing[800]}px`,
4041
overflow: 'auto',
4142
});
4243

44+
const codeStyles = css({
45+
'& .cm-editor': {
46+
paddingLeft: spacing[2],
47+
},
48+
});
49+
4350
const footerStyles = css({
4451
display: 'flex',
4552
gap: spacing[200],
@@ -139,17 +146,22 @@ const ExportSchemaModal: React.FunctionComponent<{
139146
onCancel={onCancelSchemaExport}
140147
/>
141148
)}
142-
{exportStatus === 'complete' && (
143-
<Code
144-
id="export-schema-content"
145-
data-testid="export-schema-content"
146-
language="json"
147-
className={codeStyles}
148-
copyable={true}
149-
onCopy={onExportedSchemaCopied}
150-
>
151-
{exportedSchema ?? 'Empty'}
152-
</Code>
149+
{exportStatus === 'complete' && exportedSchema && (
150+
<KeylineCard className={codeEditorContainerStyles}>
151+
<CodemirrorMultilineEditor
152+
data-testid="export-schema-content"
153+
language="json"
154+
className={codeStyles}
155+
copyable={true}
156+
showAnnotationsGutter={false}
157+
showLineNumbers={false}
158+
formattable={false}
159+
initialJSONFoldAll={false}
160+
readOnly
161+
text={exportedSchema}
162+
onCopy={onExportedSchemaCopied}
163+
></CodemirrorMultilineEditor>
164+
</KeylineCard>
153165
)}
154166
{exportStatus === 'error' && errorMessage && (
155167
<ErrorSummary

0 commit comments

Comments
 (0)