-
Notifications
You must be signed in to change notification settings - Fork 139
Add validation support for connections drivers #11582
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
Open
dfalbel
wants to merge
13
commits into
main
Choose a base branch
from
feature/bigquery-connection-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+133
−57
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
efb5ead
Add validation support for BigQuery connection drivers
dfalbel f409a75
Use box-shadow for error indicator to prevent layout shift
dfalbel 78f6c86
Add animated error message overlay for connection validation
dfalbel 5771146
Simplify generateCode return type to use discriminated union
dfalbel 7356d73
Add text overflow handling to error message overlay
dfalbel 25df4ab
Localize error messages in BigQuery driver
dfalbel 82ea0b8
Apply suggestions from code review
dfalbel 5f2440e
Add error icon to connection validation error banner
dfalbel d6f56ca
Add generateCode API documentation with examples
dfalbel 9f452b9
Apply suggestions from code review
dfalbel 055c6ab
use Icon component
dfalbel 9158ccc
Fix excessive re-renders in connection dialog
dfalbel c450029
Add exit animation for connection error message
dfalbel 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,6 +21,10 @@ import { DropDownListBox } from '../../../../../browser/positronComponents/dropD | |
| import { DropDownListBoxItem } from '../../../../../browser/positronComponents/dropDownListBox/dropDownListBoxItem.js'; | ||
| import { usePositronReactServicesContext } from '../../../../../../base/browser/positronReactRendererContext.js'; | ||
| import { PositronModalReactRenderer } from '../../../../../../base/browser/positronModalReactRenderer.js'; | ||
| import { Icon } from '../../../../../../platform/positronActionBar/browser/components/icon.js'; | ||
| import { positronClassNames } from '../../../../../../base/common/positronUtilities.js'; | ||
| import { Codicon } from '../../../../../../base/common/codicons.js'; | ||
| import { IEditorOptions } from '../../../../../../editor/common/config/editorOptions.js'; | ||
|
|
||
| interface CreateConnectionProps { | ||
| readonly renderer: PositronModalReactRenderer; | ||
|
|
@@ -37,18 +41,27 @@ export const CreateConnection = (props: PropsWithChildren<CreateConnectionProps> | |
| const editorRef = useRef<SimpleCodeEditorWidget>(undefined!); | ||
|
|
||
| const [inputs, setInputs] = useState<Array<Input>>(metadata.inputs); | ||
| const [code, setCode] = useState<string | undefined>(undefined); | ||
| const [codeState, setCodeState] = useState<{ code: string; errorMessage?: string } | undefined>(undefined); | ||
|
|
||
| const editorOptions: IEditorOptions = { | ||
| readOnly: true, | ||
| cursorBlinking: 'solid' as const | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit: I don't think you need the |
||
| }; | ||
|
|
||
| useEffect(() => { | ||
| // Debounce the code generation to avoid unnecessary re-renders | ||
| const timeoutId = setTimeout(async () => { | ||
| if (generateCode) { | ||
| const code = await generateCode(inputs); | ||
| setCode(code); | ||
| const result = await generateCode(inputs); | ||
| if (typeof result === 'string') { | ||
| setCodeState({ code: result }); | ||
| } else { | ||
| setCodeState(result); | ||
| } | ||
| } | ||
| }, 200); | ||
| return () => clearTimeout(timeoutId); | ||
| }, [inputs, generateCode, setCode]); | ||
| }, [inputs, generateCode, setCodeState]); | ||
|
|
||
| const onConnectHandler = async () => { | ||
| // Acquire code before disposing of the renderer | ||
|
|
@@ -118,23 +131,24 @@ export const CreateConnection = (props: PropsWithChildren<CreateConnectionProps> | |
| </h1> | ||
| </div> | ||
|
|
||
| <Form inputs={metadata.inputs} onInputsChange={setInputs}></Form> | ||
| <Form inputs={inputs} onInputsChange={setInputs}></Form> | ||
|
|
||
| <div className='create-connection-code-title'> | ||
| {(() => localize('positron.newConnectionModalDialog.createConnection.code', "Connection Code"))()} | ||
| </div> | ||
|
|
||
| <div className='create-connection-code-editor'> | ||
| <div className={positronClassNames('create-connection-code-editor', { 'has-error': !!codeState?.errorMessage })}> | ||
| <SimpleCodeEditor | ||
| ref={editorRef} | ||
| code={code} | ||
| editorOptions={{ | ||
| readOnly: true, | ||
| cursorBlinking: 'solid' | ||
| }} | ||
| code={codeState?.code || ''} | ||
| editorOptions={editorOptions} | ||
| language={languageId} | ||
| > | ||
| </SimpleCodeEditor> | ||
| <div className='connection-error-message'> | ||
| <Icon icon={Codicon.error} /> | ||
| {codeState?.errorMessage} | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className='create-connection-buttons'> | ||
|
|
@@ -160,7 +174,8 @@ export const CreateConnection = (props: PropsWithChildren<CreateConnectionProps> | |
| {(() => localize('positron.newConnectionModalDialog.createConnection.back', 'Back'))()} | ||
| </PositronButton> | ||
| <PositronButton | ||
| className='button action-bar-button default' | ||
| className={`button action-bar-button`} | ||
| disabled={!codeState || !!codeState.errorMessage} | ||
| onPressed={onConnectHandler} | ||
| > | ||
| {(() => localize('positron.newConnectionModalDialog.createConnection.connect', 'Connect'))()} | ||
|
|
@@ -185,12 +200,9 @@ const Form = (props: PropsWithChildren<{ inputs: Input[], onInputsChange: (input | |
| inputs.map((input) => { | ||
| return <FormElement key={input.id} input={input} onChange={(value) => { | ||
| onInputsChange( | ||
| inputs.map((i) => { | ||
| if (i.id === input.id) { | ||
| i.value = value; | ||
| } | ||
| return i; | ||
| }) | ||
| inputs.map((i) => | ||
| i.id === input.id ? { ...i, value } : i | ||
| ) | ||
| ); | ||
| }}></FormElement>; | ||
| }) | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.