Skip to content

Commit 249437a

Browse files
committed
fix(schema): use code mirror for rendering schema export instead of leafygreen code for performance
1 parent fa09d6d commit 249437a

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
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/collection-schema-tab.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ describe('Collection schema tab', function () {
111111

112112
describe('with the enableExportSchema feature flag enabled', function () {
113113
beforeEach(async function () {
114-
// TODO(COMPASS-8819): remove web skip when defaulted true.
115-
skipForWeb(this, "can't toggle features in compass-web");
114+
// TODO(COMPASS-8819): remove when defaulted true
116115
await browser.setFeature('enableExportSchema', true);
117116
});
118117

@@ -135,7 +134,14 @@ describe('Collection schema tab', function () {
135134

136135
const exportSchemaContent = browser.$(Selectors.ExportSchemaOutput);
137136
await exportSchemaContent.waitForDisplayed();
138-
const text = await browser.$(Selectors.ExportSchemaOutput).getText();
137+
138+
let text = '';
139+
await browser.waitUntil(async function () {
140+
text = await browser.getCodemirrorEditorText(
141+
Selectors.ExportSchemaOutput
142+
);
143+
return text.includes('$schema:');
144+
});
139145
const parsedText = JSON.parse(text);
140146
delete parsedText.$defs;
141147
expect(parsedText).to.deep.equal({

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.1",
7676
"@mongodb-js/compass-components": "^1.34.1",
7777
"@mongodb-js/compass-connections": "^1.50.1",
78+
"@mongodb-js/compass-editor": "^0.36.1",
7879
"@mongodb-js/compass-field-store": "^9.25.1",
7980
"@mongodb-js/compass-logging": "^1.6.1",
8081
"@mongodb-js/compass-telemetry": "^1.4.1",

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

Lines changed: 24 additions & 11 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 {
@@ -34,11 +35,17 @@ const contentContainerStyles = css({
3435
paddingBottom: spacing[400],
3536
});
3637

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

43+
const codeStyles = css({
44+
'& .cm-editor': {
45+
paddingLeft: spacing[2],
46+
},
47+
});
48+
4249
const footerStyles = css({
4350
display: 'flex',
4451
gap: spacing[200],
@@ -137,15 +144,21 @@ const ExportSchemaModal: React.FunctionComponent<{
137144
/>
138145
)}
139146
{exportStatus === 'complete' && (
140-
<Code
141-
id="export-schema-content"
142-
data-testid="export-schema-content"
143-
language="json"
144-
className={codeStyles}
145-
copyable={true}
146-
>
147-
{exportedSchema ?? 'Empty'}
148-
</Code>
147+
<KeylineCard className={codeEditorContainerStyles}>
148+
<CodemirrorMultilineEditor
149+
id="export-schema-content"
150+
data-testid="export-schema-content"
151+
language="json"
152+
className={codeStyles}
153+
copyable={true}
154+
showAnnotationsGutter={false}
155+
showLineNumbers={false}
156+
formattable={false}
157+
initialJSONFoldAll={false}
158+
readOnly
159+
text={exportedSchema ?? 'Empty'}
160+
></CodemirrorMultilineEditor>
161+
</KeylineCard>
149162
)}
150163
{exportStatus === 'error' && errorMessage && (
151164
<ErrorSummary

0 commit comments

Comments
 (0)