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 3626c53 commit 0857a5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion superset-frontend/src/addSlice/AddSliceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export default class AddSliceContainer extends React.PureComponent<
/>
<span>
<a
href="/tablemodelview/list"
href="/tablemodelview/list/#create"
rel="noopener noreferrer"
target="_blank"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ describe('DatasetList', () => {
});
});

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => ({}),
useHistory: () => ({}),
}));

describe('RTL', () => {
async function renderAndWait() {
const mounted = act(async () => {
Expand All @@ -191,7 +197,7 @@ describe('RTL', () => {
<QueryParamProvider>
<DatasetList {...mockedProps} user={mockUser} />
</QueryParamProvider>,
{ useRedux: true },
{ useRedux: true, useRouter: true },
);
});

Expand Down
11 changes: 11 additions & 0 deletions superset-frontend/src/views/CRUD/data/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import React, {
useState,
useMemo,
useCallback,
useEffect,
} from 'react';
import rison from 'rison';
import { useHistory, useLocation } from 'react-router-dom';
import {
createFetchRelated,
createFetchDistinct,
Expand Down Expand Up @@ -626,6 +628,15 @@ 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} />
Expand Down

0 comments on commit 0857a5f

Please sign in to comment.