Skip to content

Commit

Permalink
fix(tag): update state to clear form on success (#25934)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored Nov 15, 2023
1 parent 63b8172 commit aee94b3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions superset-frontend/src/features/tags/TagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ const TagModal: React.FC<TagModalProps> = ({
setSavedQueriesToTag([]);
};

const clearTagForm = () => {
setTagName('');
setDescription('');
setDashboardsToTag([]);
setChartsToTag([]);
setSavedQueriesToTag([]);
};

useEffect(() => {
const resourceMap: { [key: string]: TaggableResourceOption[] } = {
[TaggableResources.Dashboard]: [],
Expand Down Expand Up @@ -225,7 +233,9 @@ const TagModal: React.FC<TagModalProps> = ({
})
.then(({ json = {} }) => {
refreshData();
clearTagForm();
addSuccessToast(t('Tag updated'));
onHide();
})
.catch(err => {
addDangerToast(err.message || 'Error Updating Tag');
Expand All @@ -241,24 +251,19 @@ const TagModal: React.FC<TagModalProps> = ({
})
.then(({ json = {} }) => {
refreshData();
clearTagForm();
addSuccessToast(t('Tag created'));
onHide();
})
.catch(err => addDangerToast(err.message || 'Error Creating Tag'));
}
onHide();
};

return (
<Modal
title={modalTitle}
onHide={() => {
if (clearOnHide) {
setTagName('');
setDescription('');
setDashboardsToTag([]);
setChartsToTag([]);
setSavedQueriesToTag([]);
}
if (clearOnHide) clearTagForm();
onHide();
}}
show={show}
Expand Down

0 comments on commit aee94b3

Please sign in to comment.