Skip to content

Commit

Permalink
Add support for linking directly to Create Dataset modal via URL hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
codyml committed Jun 17, 2022
1 parent 0857a5f commit 679c171
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions superset-frontend/src/views/CRUD/data/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,34 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
});
}

const CREATE_HASH = '#create';
const location = useLocation();
const history = useHistory();

// Sync Dataset Add modal with #create hash
useEffect(() => {
const modalOpen = location.hash === CREATE_HASH && canCreate;
setDatasetAddModalOpen(modalOpen);
}, [canCreate, location.hash]);

// Add #create hash
const openDatasetAddModal = useCallback(() => {
history.replace(`${location.pathname}${location.search}${CREATE_HASH}`);
}, [history, location.pathname, location.search]);

// Remove #create hash
const closeDatasetAddModal = useCallback(() => {
history.replace(`${location.pathname}${location.search}`);
}, [history, location.pathname, location.search]);

if (canCreate) {
buttonArr.push({
name: (
<>
<i className="fa fa-plus" /> {t('Dataset')}{' '}
</>
),
onClick: () => setDatasetAddModalOpen(true),
onClick: openDatasetAddModal,
buttonStyle: 'primary',
});

Expand Down Expand Up @@ -628,21 +648,12 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
);
};

const location = useLocation();
const history = useHistory();
useEffect(() => {
if (location.hash === '#create' && canCreate) {
history.replace(`${location.pathname}${location.search}`);
setDatasetAddModalOpen(true);
}
}, [canCreate, history, location]);

return (
<>
<SubMenu {...menuData} />
<AddDatasetModal
show={datasetAddModalOpen}
onHide={() => setDatasetAddModalOpen(false)}
onHide={closeDatasetAddModal}
onDatasetAdd={refreshData}
/>
{datasetCurrentlyDeleting && (
Expand Down

0 comments on commit 679c171

Please sign in to comment.