-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(wren-ui): Fix SQL flow in reasoning #1451
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 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
65ee123
revert(wren-ui): add fix it button
andreashimin a90e0f6
chore(wren-ui): adjust select none on tab
andreashimin a620797
chore(wren-ui): adjust stream condition with loading when retrieving
andreashimin 9b658ce
feat(wren-ui): add fix sql modal
andreashimin 0684fb1
feat(wren-ui): separate fixed sql step, provide fix sql modal. managi…
andreashimin 05d5b82
feat(wren-ui): add error handler
andreashimin 1d13e2b
fix(wren-ui): add thread response check in update method
andreashimin b2e5fea
fix(wren-ui): separate preview loading for mutation API
andreashimin 67b64b2
update wren-ui version to fix-sql-v1
82f4da3
Revert "update wren-ui version to fix-sql-v1"
andreashimin e79d797
feat(wren-ui): display AI service error message to users
andreashimin ad5f5e6
fix(wren-ui): casing & loading exception handling
andreashimin ed41e34
feat(wren-ui): show AI error message if no relevant sql error
andreashimin 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
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 |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
| import { Button, Form, Modal, Typography, Alert } from 'antd'; | ||
| import { ERROR_TEXTS } from '@/utils/error'; | ||
| import { ModalAction } from '@/hooks/useModalAction'; | ||
| import { attachLoading } from '@/utils/helper'; | ||
| import { parseGraphQLError } from '@/utils/errorHandler'; | ||
| import SQLEditor from '@/components/editor/SQLEditor'; | ||
| import ErrorCollapse from '@/components/ErrorCollapse'; | ||
| import PreviewData from '@/components/dataPreview/PreviewData'; | ||
| import { usePreviewSqlMutation } from '@/apollo/client/graphql/sql.generated'; | ||
|
|
||
| type Props = ModalAction<{ sql: string; responseId: number }> & { | ||
| loading?: boolean; | ||
| }; | ||
|
|
||
| export function FixSQLModal(props: Props) { | ||
| const { visible, defaultValue, loading, onSubmit, onClose } = props; | ||
| const [previewLoading, setPreviewLoading] = useState(false); | ||
| const [form] = Form.useForm(); | ||
|
|
||
| const [previewSqlMutation, previewSqlResult] = usePreviewSqlMutation(); | ||
| const error = useMemo(() => { | ||
| if (!previewSqlResult.error) return null; | ||
| const graphQLError = parseGraphQLError(previewSqlResult.error); | ||
| return { ...graphQLError, shortMessage: 'Invalid SQL syntax' }; | ||
| }, [previewSqlResult.error]); | ||
|
|
||
| useEffect(() => { | ||
| if (!visible) return; | ||
| form.setFieldsValue(defaultValue || {}); | ||
| }, [form, defaultValue, visible]); | ||
|
|
||
| const validateSql = async () => { | ||
| const sql = form.getFieldValue('sql'); | ||
| await previewSqlMutation({ | ||
| variables: { data: { sql, limit: 1, dryRun: true } }, | ||
| }); | ||
| }; | ||
|
|
||
| const previewData = async () => { | ||
| form | ||
| .validateFields() | ||
| .then(async (values) => { | ||
| await attachLoading( | ||
| previewSqlMutation, | ||
| setPreviewLoading, | ||
| )({ | ||
| variables: { data: { sql: values.sql, limit: 50 } }, | ||
| }); | ||
| }) | ||
| .catch(console.error); | ||
| }; | ||
|
andreashimin marked this conversation as resolved.
|
||
|
|
||
| const reset = () => { | ||
| form.resetFields(); | ||
| previewSqlResult.reset(); | ||
| }; | ||
|
|
||
| const submit = async () => { | ||
| form | ||
| .validateFields() | ||
| .then(async (values) => { | ||
| await validateSql(); | ||
| await onSubmit(values.sql); | ||
| onClose(); | ||
| }) | ||
| .catch(console.error); | ||
| }; | ||
|
andreashimin marked this conversation as resolved.
|
||
|
|
||
| const showPreview = previewSqlResult.data || previewSqlResult.loading; | ||
|
|
||
| return ( | ||
| <Modal | ||
| title="Fix SQL" | ||
| width={640} | ||
| visible={visible} | ||
| okText="Submit" | ||
| onOk={submit} | ||
| onCancel={onClose} | ||
| confirmLoading={loading} | ||
| maskClosable={false} | ||
| destroyOnClose | ||
| centered | ||
| afterClose={reset} | ||
| > | ||
| <Typography.Text className="d-block gray-7 mb-3"> | ||
| The following SQL statement needs to be fixed: | ||
| </Typography.Text> | ||
| <Form form={form} preserve={false} layout="vertical"> | ||
| <Form.Item | ||
| label="SQL statement" | ||
| name="sql" | ||
| required | ||
| rules={[ | ||
| { | ||
| required: true, | ||
| message: ERROR_TEXTS.FIX_SQL.SQL.REQUIRED, | ||
| }, | ||
| ]} | ||
| > | ||
| <SQLEditor autoFocus /> | ||
| </Form.Item> | ||
| </Form> | ||
| <div className="my-3"> | ||
| <Typography.Text className="d-block gray-7 mb-2"> | ||
| Data preview (50 rows) | ||
| </Typography.Text> | ||
| <Button | ||
| onClick={previewData} | ||
| loading={previewLoading} | ||
| disabled={previewLoading} | ||
| > | ||
| Preview data | ||
| </Button> | ||
| {showPreview && ( | ||
| <div className="my-3"> | ||
| <PreviewData | ||
| loading={previewLoading} | ||
| previewData={previewSqlResult?.data?.previewSql} | ||
| copyable={false} | ||
| /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| {!!error && ( | ||
| <Alert | ||
| showIcon | ||
| type="error" | ||
| message={error.shortMessage} | ||
| description={<ErrorCollapse message={error.message} />} | ||
| /> | ||
| )} | ||
| </Modal> | ||
| ); | ||
| } | ||
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.
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.