-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compass-editor): add autocompleter for aggregation, use autocomp…
…leter in import pipeline modal COMPASS-6175 (#3594) * feat(compass-editor): add autocompleter for aggregation, use autocompleter in import pipeline modal * fix(compass-editor): exclude test files from the build * chore(compass-editor): wrap snippets in blocks when autocompleter is triggered outside of one * fix(compass-editor): fix test types
- Loading branch information
1 parent
83ad27e
commit e6bbb93
Showing
18 changed files
with
1,789 additions
and
2,116 deletions.
There are no files selected for viewing
This file contains 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
80 changes: 0 additions & 80 deletions
80
packages/compass-aggregations/src/components/pipeline/modals/import-pipeline.jsx
This file was deleted.
Oops, something went wrong.
This file contains 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
107 changes: 107 additions & 0 deletions
107
packages/compass-aggregations/src/components/pipeline/modals/import-pipeline.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { ConfirmationModal } from '@mongodb-js/compass-components'; | ||
import type { CompletionWithServerInfo } from '@mongodb-js/compass-editor'; | ||
import { | ||
Editor, | ||
EditorVariant, | ||
EditorTextCompleter, | ||
AggregationAutoCompleter | ||
} from '@mongodb-js/compass-editor'; | ||
import { | ||
changeText, | ||
closeImport, | ||
createNew | ||
} from '../../../modules/import-pipeline'; | ||
import type { RootState } from '../../../modules'; | ||
import styles from './import-pipeline.module.less'; | ||
import { connect } from 'react-redux'; | ||
|
||
function useAggregationCompleter( | ||
...args: ConstructorParameters<typeof AggregationAutoCompleter> | ||
): AggregationAutoCompleter { | ||
const [version, textCompleter, fields] = args; | ||
const completer = useRef<AggregationAutoCompleter>(); | ||
if (!completer.current) { | ||
completer.current = new AggregationAutoCompleter( | ||
version, | ||
textCompleter, | ||
fields | ||
); | ||
} | ||
useEffect(() => { | ||
completer.current?.updateFields(fields); | ||
}, [fields]); | ||
return completer.current; | ||
} | ||
|
||
export const ImportPipeline: React.FunctionComponent<{ | ||
isOpen?: boolean; | ||
closeImport(): void; | ||
changeText(newText: string): void; | ||
createNew(): void; | ||
text: string; | ||
error?: string | null; | ||
fields: CompletionWithServerInfo[]; | ||
serverVersion: string; | ||
}> = ({ | ||
isOpen, | ||
createNew, | ||
closeImport, | ||
text, | ||
changeText, | ||
error, | ||
fields, | ||
serverVersion | ||
}) => { | ||
const completer = useAggregationCompleter( | ||
serverVersion, | ||
EditorTextCompleter, | ||
fields | ||
); | ||
|
||
return ( | ||
<ConfirmationModal | ||
title="New Pipeline From Plain Text" | ||
open={isOpen} | ||
onConfirm={createNew} | ||
onCancel={closeImport} | ||
buttonText="Create New" | ||
submitDisabled={text === ''} | ||
trackingId="import_pipeline_modal" | ||
> | ||
<div className={styles['import-pipeline-note']}> | ||
Supports MongoDB Shell syntax. Pasting a pipeline will create a new | ||
pipeline. | ||
</div> | ||
<div className={styles['import-pipeline-editor']}> | ||
<Editor | ||
variant={EditorVariant.Shell} | ||
text={text} | ||
onChangeText={changeText} | ||
options={{ minLines: 10 }} | ||
completer={completer} | ||
name="import-pipeline-editor" | ||
/> | ||
</div> | ||
{error && <div className={styles['import-pipeline-error']}>{error}</div>} | ||
</ConfirmationModal> | ||
); | ||
}; | ||
|
||
const mapState = (state: RootState) => { | ||
return { | ||
isOpen: state.importPipeline.isOpen, | ||
text: state.importPipeline.text, | ||
error: state.importPipeline.syntaxError, | ||
fields: state.fields, | ||
serverVersion: state.serverVersion | ||
}; | ||
}; | ||
|
||
const mapDispatch = { | ||
closeImport, | ||
changeText, | ||
createNew | ||
}; | ||
|
||
export default connect(mapState, mapDispatch)(ImportPipeline); |
This file contains 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 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.