feat: disable save button when saving datasource (#11493)

This commit is contained in:
Jesse Yang 2020-10-29 16:13:47 -07:00 committed by GitHub
parent 074f8c2e8c
commit 93693690a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,6 +82,7 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
}) => {
const [currentDatasource, setCurrentDatasource] = useState(datasource);
const [errors, setErrors] = useState<any[]>([]);
const [isSaving, setIsSaving] = useState(false);
const dialog = useRef<any>(null);
const onConfirmSave = () => {
@ -90,6 +91,9 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
currentDatasource.schema ||
currentDatasource.databaseSelector?.schema ||
currentDatasource.tableSelector?.schema;
setIsSaving(true);
SupersetClient.post({
endpoint: '/datasource/save/',
postPayload: {
@ -111,7 +115,8 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
onDatasourceSave(json);
onHide();
})
.catch(response =>
.catch(response => {
setIsSaving(false);
getClientErrorObject(response).then(({ error }) => {
dialog.current.show({
title: 'Error',
@ -120,8 +125,8 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
actions: [Dialog.DefaultAction('Ok', () => {}, 'btn-danger')],
body: error || t('An error has occurred'),
});
}),
);
});
});
};
const onDatasourceChange = (data: Record<string, any>, err: Array<any>) => {
@ -196,7 +201,7 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
className="m-r-5"
data-test="datasource-modal-save"
onClick={onClickSave}
disabled={errors.length > 0}
disabled={isSaving || errors.length > 0}
>
{t('Save')}
</Button>