Skip to content

Commit a782d73

Browse files
committed
Read query from redux and pass to components
1 parent d303a54 commit a782d73

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { usePreference } from 'compass-preferences-model/provider';
2121
import IndexFlowSection from './index-flow-section';
2222
import QueryFlowSection from './query-flow-section';
2323
import toNS from 'mongodb-ns';
24+
import type { Document } from 'bson';
2425

2526
const createIndexModalFieldsStyles = css({
2627
margin: `${spacing[600]}px 0 ${spacing[800]}px 0`,
@@ -49,6 +50,7 @@ export type CreateIndexFormProps = {
4950
onRemoveFieldClick: (idx: number) => void; // Minus icon.
5051
onTabClick: (tab: Tab) => void;
5152
showIndexesGuidanceVariant?: boolean;
53+
query?: Document;
5254
};
5355

5456
function CreateIndexForm({
@@ -62,6 +64,7 @@ function CreateIndexForm({
6264
onRemoveFieldClick,
6365
onTabClick,
6466
showIndexesGuidanceVariant,
67+
query,
6568
}: CreateIndexFormProps) {
6669
const { id: connectionId } = useConnectionInfo();
6770
const rollingIndexesFeatureEnabled = !!usePreference('enableRollingIndexes');
@@ -163,6 +166,7 @@ function CreateIndexForm({
163166
serverVersion={serverVersion}
164167
dbName={dbName}
165168
collectionName={collectionName}
169+
initialQuery={query}
166170
/>
167171
)}
168172

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
SuggestedIndexFetchedProps,
2121
} from '../../modules/create-index';
2222
import { connect } from 'react-redux';
23+
import type { Document } from 'bson';
2324

2425
const inputQueryContainerStyles = css({
2526
display: 'flex',
@@ -83,6 +84,7 @@ const QueryFlowSection = ({
8384
onSuggestedIndexButtonClick,
8485
indexSuggestions,
8586
fetchingSuggestionsState,
87+
initialQuery,
8688
}: {
8789
schemaFields: { name: string; description?: string }[];
8890
serverVersion: string;
@@ -95,8 +97,11 @@ const QueryFlowSection = ({
9597
}: SuggestedIndexFetchedProps) => Promise<void>;
9698
indexSuggestions: Record<string, number> | null;
9799
fetchingSuggestionsState: IndexSuggestionState;
100+
initialQuery?: Document;
98101
}) => {
99-
const [inputQuery, setInputQuery] = React.useState('');
102+
const [inputQuery, setInputQuery] = React.useState(
103+
JSON.stringify(initialQuery?.filter ?? {}, null, 2)
104+
);
100105
const completer = useMemo(
101106
() =>
102107
createQueryAutocompleter({

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import {
2929
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
3030
import { usePreference } from 'compass-preferences-model/provider';
3131
import CreateIndexModalHeader from './create-index-modal-header';
32+
import type { Document } from 'bson';
3233

3334
type CreateIndexModalProps = React.ComponentProps<typeof CreateIndexForm> & {
3435
isVisible: boolean;
3536
namespace: string;
3637
error: string | null;
3738
currentTab: Tab;
39+
query?: Document;
3840
onErrorBannerCloseClick: () => void;
3941
onCreateIndexClick: () => void;
4042
onCancelCreateIndexClick: () => void;
@@ -49,6 +51,7 @@ function CreateIndexModal({
4951
onErrorBannerCloseClick,
5052
onCreateIndexClick,
5153
onCancelCreateIndexClick,
54+
query,
5255
...props
5356
}: CreateIndexModalProps) {
5457
const connectionInfoRef = useConnectionInfoRef();
@@ -108,6 +111,7 @@ function CreateIndexModal({
108111
namespace={namespace}
109112
showIndexesGuidanceVariant={showIndexesGuidanceVariant}
110113
currentTab={currentTab}
114+
query={query}
111115
/>
112116
</ModalBody>
113117

@@ -124,14 +128,15 @@ function CreateIndexModal({
124128
}
125129

126130
const mapState = ({ namespace, serverVersion, createIndex }: RootState) => {
127-
const { fields, error, isVisible, currentTab } = createIndex;
131+
const { fields, error, isVisible, currentTab, query } = createIndex;
128132
return {
129133
fields,
130134
error,
131135
isVisible,
132136
namespace,
133137
serverVersion,
134138
currentTab,
139+
query,
135140
};
136141
};
137142

packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const mapState = ({
303303
});
304304

305305
const mapDispatch = {
306-
onCreateRegularIndexClick: createIndexOpened,
306+
onCreateRegularIndexClick: () => createIndexOpened(),
307307
onCreateSearchIndexClick: createSearchIndexOpened,
308308
onIndexViewChanged: indexViewChanged,
309309
};

0 commit comments

Comments
 (0)