-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
feat: Added error alert for DB connection Modal #15242
Changes from 17 commits
dbbf58c
e5b66dc
03d3326
5cfe664
7a7f39b
54965a1
9a2a58e
be0408b
be5ea73
a7425e4
8a8998e
fc31ea2
8a4ff62
34e8de1
cd6744f
4a0eefa
4a9f641
0cee43f
6a88a41
ed10ef3
a8bc0f5
b7254f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ import ExtraOptions from './ExtraOptions'; | |
import SqlAlchemyForm from './SqlAlchemyForm'; | ||
import DatabaseConnectionForm from './DatabaseConnectionForm'; | ||
import { | ||
antDErrorAlertStyles, | ||
antDAlertStyles, | ||
antDModalNoPaddingStyles, | ||
antDModalStyles, | ||
|
@@ -285,6 +286,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
const [tabKey, setTabKey] = useState<string>(DEFAULT_TAB_KEY); | ||
const [availableDbs, getAvailableDbs] = useAvailableDatabases(); | ||
const [validationErrors, getValidation] = useDatabaseValidation(); | ||
const [hasErrors, setHasErrors] = useState<boolean>(false); | ||
const [hasConnectedDb, setHasConnectedDb] = useState<boolean>(false); | ||
const [dbName, setDbName] = useState(''); | ||
const [isLoading, setLoading] = useState<boolean>(false); | ||
|
@@ -596,10 +598,32 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
} | ||
}, [availableDbs]); | ||
|
||
useEffect(() => { | ||
if (validationErrors) { | ||
setHasErrors(true); | ||
} else { | ||
setHasErrors(false); | ||
} | ||
}, [validationErrors]); | ||
// Used as componentDidMount | ||
|
||
const tabChange = (key: string) => { | ||
setTabKey(key); | ||
}; | ||
|
||
const errorAlert = () => { | ||
const errors = validationErrors; | ||
return ( | ||
<Alert | ||
type="error" | ||
css={(theme: SupersetTheme) => antDErrorAlertStyles(theme)} | ||
message="Missing Required Fields" | ||
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. Not sure if you plan to put this into the v2, but I think that we're going to have to create a map between the server side error and the language that we want to show in these alerts. These are more descriptive and instructional and I don't think they will be or should be the same as what we are returning from the API. 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. I hadn't thought about a map, though I really like that. No, I figured that language was prone to change, I wanted this in there to make sure that it looked ok, and so that I could style it. |
||
description={errors ? errors.port : ''} | ||
showIcon | ||
/> | ||
); | ||
}; | ||
|
||
const isDynamic = (engine: string | undefined) => | ||
availableDbs?.databases.filter( | ||
(DB: DatabaseObject) => DB.engine === engine, | ||
|
@@ -763,6 +787,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
onChange(ActionType.extraEditorChange, payload); | ||
}} | ||
/> | ||
{hasErrors && errorAlert} | ||
</Tabs.TabPane> | ||
</Tabs> | ||
</Modal> | ||
|
@@ -910,6 +935,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
Connect this database with a SQLAlchemy URI string instead | ||
</Button> | ||
{/* Step 2 */} | ||
{hasErrors && errorAlert()} | ||
</> | ||
))} | ||
</> | ||
|
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.
We don't need this useEffect, we can just key on
validationErrors
to show the alert{
validationErrors &&
}
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.
true good point.