Skip to content

Commit 28fe286

Browse files
committed
added autocomplete + fixed up tests
1 parent 59c4696 commit 28fe286

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

packages/compass-indexes/src/components/create-index-form/create-index-form.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ function CreateIndexForm({
151151
) : null}
152152
</div>
153153

154-
{showIndexesGuidanceQueryFlow && <QueryFlowSection />}
154+
{showIndexesGuidanceQueryFlow && (
155+
<QueryFlowSection
156+
schemaFields={schemaFields}
157+
serverVersion={serverVersion}
158+
/>
159+
)}
155160

156161
{/* TODO in CLOUDP-314036: update the accordion design */}
157162
<Accordion data-testid="create-index-modal-toggle-options" text="Options">

packages/compass-indexes/src/components/create-index-form/query-flow-section.spec.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@ import QueryFlowSection from './query-flow-section';
44
import { expect } from 'chai';
55

66
describe('QueryFlowSection', () => {
7+
const renderComponent = () => {
8+
render(<QueryFlowSection schemaFields={[]} serverVersion="5.0.0" />);
9+
};
710
it('renders the input query section with a code editor', () => {
8-
render(<QueryFlowSection />);
9-
const codeEditor = screen.getByTestId('query-flow-section-json-editor');
11+
renderComponent();
12+
const codeEditor = screen.getByTestId('query-flow-section-code-editor');
1013
expect(codeEditor).to.be.visible;
1114
});
1215

1316
it('renders the "Show me suggested index" button', () => {
14-
render(<QueryFlowSection />);
17+
renderComponent();
1518
const buttonElement = screen.getByText('Show me suggested index');
1619
expect(buttonElement).to.be.visible;
1720
});
1821

1922
it('renders the suggested index section with formatted index code', () => {
20-
render(<QueryFlowSection />);
23+
renderComponent();
2124
const codeElement = screen.getByTestId(
2225
'query-flow-section-suggested-index'
2326
);
2427
expect(codeElement).to.be.visible;
2528
});
2629

2730
it('renders the link to the MongoDB documentation', () => {
28-
render(<QueryFlowSection />);
31+
renderComponent();
2932
const linkElement = screen.getByText('here');
3033
expect(linkElement).to.be.visible;
3134
});

packages/compass-indexes/src/components/create-index-form/query-flow-section.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
} from '@mongodb-js/compass-components';
88
import React from 'react';
99
import { css, spacing } from '@mongodb-js/compass-components';
10-
import { CodemirrorInlineEditor } from '@mongodb-js/compass-editor';
10+
import {
11+
CodemirrorInlineEditor,
12+
createQueryAutocompleter,
13+
} from '@mongodb-js/compass-editor';
1114

1215
const inputQueryContainerStyles = css({
1316
marginBottom: spacing[600],
@@ -37,7 +40,13 @@ const programmingLanguageLinkStyles = css({
3740
marginTop: spacing[100],
3841
});
3942

40-
const QueryFlowSection = () => {
43+
const QueryFlowSection = ({
44+
schemaFields,
45+
serverVersion,
46+
}: {
47+
schemaFields: { name: string; description?: string }[];
48+
serverVersion: string;
49+
}) => {
4150
// TODO in CLOUDP-311786, replace hardcoded values with actual data
4251
const db_name = 'sample_mflix';
4352
const collection_name = 'comments';
@@ -61,14 +70,18 @@ db.getSiblingDB("${db_name}").getCollection("${collection_name}").createIndex(
6170
<div className={inputQueryContainerStyles}>
6271
<div>
6372
<CodemirrorInlineEditor
64-
data-testid="query-flow-section-json-editor"
65-
language="json"
73+
data-testid="query-flow-section-code-editor"
74+
language="javascript-expression"
6675
text={inputQuery}
6776
onChangeText={(text) => setInputQuery(text)}
68-
initialJSONFoldAll={false}
6977
placeholder="Type a query: { field: 'value' }"
78+
completer={createQueryAutocompleter({
79+
fields: schemaFields,
80+
serverVersion,
81+
})}
7082
/>
7183
</div>
84+
7285
<div>
7386
<Button
7487
onClick={() => {

0 commit comments

Comments
 (0)