Skip to content

Commit

Permalink
feat: Add loading state to sqllab save/overwrite dataset modal (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrag1 authored and sebastianliebscher committed Apr 28, 2023
1 parent 9283478 commit 49f3adf
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const SaveDatasetModal = ({
const [selectedDatasetToOverwrite, setSelectedDatasetToOverwrite] = useState<
SelectValue | undefined
>(undefined);
const [loading, setLoading] = useState<boolean>(false);

const user = useSelector<SqlLabExploreRootState, User>(user =>
getInitialState(user),
Expand All @@ -197,6 +198,7 @@ export const SaveDatasetModal = ({
setShouldOverwriteDataset(true);
return;
}
setLoading(true);
const [, key] = await Promise.all([
updateDataset(
datasource?.dbId,
Expand All @@ -220,6 +222,7 @@ export const SaveDatasetModal = ({
}),
}),
]);
setLoading(false);

const url = mountExploreUrl(null, {
[URL_PARAMS.formDataKey.name]: key,
Expand Down Expand Up @@ -269,6 +272,7 @@ export const SaveDatasetModal = ({
);

const handleSaveInDataset = () => {
setLoading(true);
const selectedColumns = datasource?.columns ?? [];

// The filters param is only used to test jinja templates.
Expand Down Expand Up @@ -306,6 +310,7 @@ export const SaveDatasetModal = ({
}),
)
.then((key: string) => {
setLoading(false);
const url = mountExploreUrl(null, {
[URL_PARAMS.formDataKey.name]: key,
});
Expand All @@ -314,6 +319,7 @@ export const SaveDatasetModal = ({
onHide();
})
.catch(() => {
setLoading(false);
addDangerToast(t('An error occurred saving dataset'));
});
};
Expand Down Expand Up @@ -356,6 +362,7 @@ export const SaveDatasetModal = ({
disabled={disableSaveAndExploreBtn}
buttonStyle="primary"
onClick={handleSaveInDataset}
loading={loading}
>
{buttonTextOnSave}
</Button>
Expand All @@ -370,6 +377,7 @@ export const SaveDatasetModal = ({
buttonStyle="primary"
onClick={handleOverwriteDataset}
disabled={disableSaveAndExploreBtn}
loading={loading}
>
{buttonTextOnOverwrite}
</Button>
Expand Down

0 comments on commit 49f3adf

Please sign in to comment.