Skip to content

Commit

Permalink
feat(rightmenu): Add Datasets to + Menu and Hide Databases when one h…
Browse files Browse the repository at this point in the history
…as been connected (#21530)
  • Loading branch information
Antonio-RiveroMartnez committed Oct 24, 2022
1 parent 175ec85 commit c19708b
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 200 deletions.
17 changes: 13 additions & 4 deletions superset-frontend/src/views/CRUD/data/dataset/AddDatasetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/
import React, { FunctionComponent, useState, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { styled, t } from '@superset-ui/core';
import { useSingleViewResource } from 'src/views/CRUD/hooks';
import Modal from 'src/components/Modal';
Expand All @@ -29,6 +28,7 @@ import {
LocalStorageKeys,
setItem,
} from 'src/utils/localStorageHelpers';
import { isEmpty } from 'lodash';

type DatasetAddObject = {
id: number;
Expand All @@ -42,6 +42,7 @@ interface DatasetModalProps {
onDatasetAdd?: (dataset: DatasetAddObject) => void;
onHide: () => void;
show: boolean;
history?: any; // So we can render the modal when not using SPA
}

const TableSelectorContainer = styled.div`
Expand All @@ -54,8 +55,8 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({
onDatasetAdd,
onHide,
show,
history,
}) => {
const history = useHistory();
const [currentDatabase, setCurrentDatabase] = useState<
DatabaseObject | undefined
>();
Expand Down Expand Up @@ -128,8 +129,16 @@ const DatasetModal: FunctionComponent<DatasetModalProps> = ({
if (onDatasetAdd) {
onDatasetAdd({ id: response.id, ...response });
}
history.push(`/chart/add?dataset=${currentTableName}`);
cleanup();
// We need to be able to work with no SPA routes opening the modal
// So useHistory wont be available always thus we check for it
if (!isEmpty(history)) {
history?.push(`/chart/add?dataset=${currentTableName}`);
cleanup();
} else {
window.location.href = `/chart/add?dataset=${currentTableName}`;
cleanup();
onHide();
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
show={datasetAddModalOpen}
onHide={closeDatasetAddModal}
onDatasetAdd={refreshData}
history={history}
/>
{datasetCurrentlyDeleting && (
<DeleteModal
Expand Down

0 comments on commit c19708b

Please sign in to comment.