-
Notifications
You must be signed in to change notification settings - Fork 247
feat: Create actual indexes and fix up state + error logic CLOUDP-317945 #6933
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1ee91d1
add index from index suggestions
rubydong 3dea357
disable the create index button when data is not complete
rubydong 8d08482
add disable show suggested index button logic
rubydong f9bf9ea
disable covered queries button if there's no changes to fields
rubydong cdbc49b
adjusting error message and added analytics for error parsing
rubydong 2e08874
resolve merge conflicts
rubydong b0f3436
finished adding error and segment event for covered queries
rubydong 45cf375
fix lint issues for opening from nudge
rubydong 9ee4bda
fix more typing and clear error when there's new changes
rubydong cfe7f9c
more linting + error handling
rubydong a0f5f19
fixed initialQuery typing, wrapped validation inside useMemo, and add…
rubydong 90317a1
fixed up typing more
rubydong b1b89c7
Merge branch 'main' into cloudp-317945
gribnoysup ac4a296
fixed index flow section test by wrapping it in provider
rubydong a068770
Merge branch 'cloudp-317945' of https://github.com/mongodb-js/compass…
rubydong 0027f2a
changed document to use mongodb one
rubydong e7d6b24
added provider to create-index-form.spec.tsx too
rubydong cab72ad
fix tests for create-index-actions.spec.tsx
rubydong a9e8be3
Merge remote-tracking branch 'origin/main' into cloudp-317945
rubydong 16706e7
add typing for the spys
rubydong 18229ca
merge main
rubydong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import type { | |
| SuggestedIndexFetchedProps, | ||
| } from '../../modules/create-index'; | ||
| import { connect } from 'react-redux'; | ||
| import type { Document } from 'bson'; | ||
| import { parseFilter } from 'mongodb-query-parser'; | ||
|
|
||
| const inputQueryContainerStyles = css({ | ||
| display: 'flex', | ||
|
|
@@ -81,6 +81,8 @@ const insightStyles = css({ | |
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: spacing[100], | ||
| marginBottom: spacing[200], | ||
| height: spacing[500], | ||
| }); | ||
|
|
||
| const QueryFlowSection = ({ | ||
|
|
@@ -104,10 +106,13 @@ const QueryFlowSection = ({ | |
| }: SuggestedIndexFetchedProps) => Promise<void>; | ||
| indexSuggestions: Record<string, number> | null; | ||
| fetchingSuggestionsState: IndexSuggestionState; | ||
| initialQuery: Document | null; | ||
| initialQuery: string | null; | ||
| }) => { | ||
| const [inputQuery, setInputQuery] = React.useState( | ||
| JSON.stringify(initialQuery?.filter ?? {}, null, 2) | ||
| initialQuery ? JSON.stringify(initialQuery, null, 2) : '' | ||
| ); | ||
| const [hasNewChanges, setHasNewChanges] = React.useState( | ||
| initialQuery !== null | ||
| ); | ||
| const completer = useMemo( | ||
| () => | ||
|
|
@@ -133,9 +138,28 @@ const QueryFlowSection = ({ | |
| collectionName, | ||
| inputQuery: sanitizedInputQuery, | ||
| }); | ||
|
|
||
| setHasNewChanges(false); | ||
| }, [inputQuery, dbName, collectionName, onSuggestedIndexButtonClick]); | ||
|
|
||
| const handleQueryInputChange = useCallback((text: string) => { | ||
| setInputQuery(text); | ||
| setHasNewChanges(true); | ||
| }, []); | ||
|
|
||
| const isFetchingIndexSuggestions = fetchingSuggestionsState === 'fetching'; | ||
| let isShowSuggestionsButtonDisabled = !hasNewChanges; | ||
|
|
||
| // Validate query upon typing | ||
| try { | ||
| parseFilter(inputQuery); | ||
|
|
||
| if (!inputQuery.startsWith('{') || !inputQuery.endsWith('}')) { | ||
| isShowSuggestionsButtonDisabled = true; | ||
| } | ||
| } catch (e) { | ||
| isShowSuggestionsButtonDisabled = true; | ||
| } | ||
|
||
|
|
||
| return ( | ||
| <> | ||
|
|
@@ -164,7 +188,7 @@ const QueryFlowSection = ({ | |
| copyable={false} | ||
| formattable={false} | ||
| text={inputQuery} | ||
| onChangeText={(text) => setInputQuery(text)} | ||
| onChangeText={(text) => handleQueryInputChange(text)} | ||
| placeholder="Type a query: { field: 'value' }" | ||
| completer={completer} | ||
| className={codeEditorStyles} | ||
|
|
@@ -176,6 +200,7 @@ const QueryFlowSection = ({ | |
| onClick={handleSuggestedIndexButtonClick} | ||
| className={suggestedIndexButtonStyles} | ||
| size="small" | ||
| disabled={isShowSuggestionsButtonDisabled} | ||
| > | ||
| Show suggested index | ||
| </Button> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 type is incorrect (as the JSON.stringify that you still keep below indicates), you're still getting a document here, not a string, why the change?
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.
you're right -- i was trying to fix the type but messed it up along the way. i fixed it!