Skip to content

Commit 260ac40

Browse files
feat: Enable new dataset creation flow II (#22835)
1 parent ebed50f commit 260ac40

File tree

23 files changed

+236
-375
lines changed

23 files changed

+236
-375
lines changed

superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanel.test.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,6 @@ test('should render a create dataset infobox', async () => {
186186
expect(infoboxText).toBeVisible();
187187
});
188188

189-
test('should render a save dataset modal when "Create a dataset" is clicked', async () => {
190-
const newProps = {
191-
...props,
192-
datasource: {
193-
...datasource,
194-
type: DatasourceType.Query,
195-
},
196-
};
197-
render(<DatasourcePanel {...newProps} />, { useRedux: true, useDnd: true });
198-
199-
const createButton = await screen.findByRole('button', {
200-
name: /create a dataset/i,
201-
});
202-
203-
userEvent.click(createButton);
204-
205-
const saveDatasetModalTitle = screen.getByText(/save or overwrite dataset/i);
206-
207-
expect(saveDatasetModalTitle).toBeVisible();
208-
});
209-
210189
test('should not render a save dataset modal when datasource is not query or dataset', async () => {
211190
const newProps = {
212191
...props,

superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ const ColumnSelectPopover = ({
231231
}, []);
232232

233233
const setDatasetAndClose = () => {
234-
if (setDatasetModal) setDatasetModal(true);
234+
if (setDatasetModal) {
235+
setDatasetModal(true);
236+
}
235237
onClose();
236238
};
237239

superset-frontend/src/pages/ChartCreation/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,7 @@ export class ChartCreation extends React.PureComponent<
337337
const isButtonDisabled = this.isBtnDisabled();
338338
const datasetHelpText = this.state.canCreateDataset ? (
339339
<span data-test="dataset-write">
340-
<Link
341-
to="/tablemodelview/list/#create"
342-
data-test="add-chart-new-dataset"
343-
>
340+
<Link to="/dataset/add/" data-test="add-chart-new-dataset">
344341
{t('Add a dataset')}
345342
</Link>
346343
{` ${t('or')} `}

superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import React, { useState, useMemo, useEffect } from 'react';
2121
import rison from 'rison';
2222
import { useSelector } from 'react-redux';
2323
import { useQueryParams, BooleanParam } from 'use-query-params';
24+
import { LocalStorageKeys, setItem } from 'src/utils/localStorageHelpers';
2425

2526
import Loading from 'src/components/Loading';
2627
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
@@ -157,6 +158,9 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
157158
refreshData();
158159
addSuccessToast(t('Deleted: %s', dbName));
159160

161+
// Delete user-selected db from local storage
162+
setItem(LocalStorageKeys.db, null);
163+
160164
// Close delete modal
161165
setDatabaseCurrentlyDeleting(null);
162166
},

superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ jest.mock('src/components/Icons/Icon', () => ({
6262
StyledIcon: () => <span />,
6363
}));
6464

65+
const mockHistoryPush = jest.fn();
66+
jest.mock('react-router-dom', () => ({
67+
...jest.requireActual('react-router-dom'),
68+
useHistory: () => ({
69+
push: mockHistoryPush,
70+
}),
71+
}));
72+
6573
const dbProps = {
6674
show: true,
6775
database_name: 'my database',

superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ interface DatabaseModalProps {
137137
show: boolean;
138138
databaseId: number | undefined; // If included, will go into edit mode
139139
dbEngine: string | undefined; // if included goto step 2 with engine already set
140+
history?: any;
140141
}
141142

142143
export enum ActionType {
@@ -521,6 +522,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
521522
show,
522523
databaseId,
523524
dbEngine,
525+
history,
524526
}) => {
525527
const [db, setDB] = useReducer<
526528
Reducer<Partial<DatabaseObject> | null, DBReducerActionType>
@@ -653,6 +655,16 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
653655
onHide();
654656
};
655657

658+
const redirectURL = (url: string) => {
659+
/* TODO (lyndsiWilliams): This check and passing history
660+
as a prop can be removed once SQL Lab is in the SPA */
661+
if (!isEmpty(history)) {
662+
history?.push(url);
663+
} else {
664+
window.location.href = url;
665+
}
666+
};
667+
656668
// Database import logic
657669
const {
658670
state: {
@@ -1345,23 +1357,21 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
13451357
const renderCTABtns = () => (
13461358
<StyledBtns>
13471359
<Button
1348-
// eslint-disable-next-line no-return-assign
13491360
buttonStyle="secondary"
13501361
onClick={() => {
13511362
setLoading(true);
13521363
fetchAndSetDB();
1353-
window.location.href = '/tablemodelview/list#create';
1364+
redirectURL('/dataset/add/');
13541365
}}
13551366
>
13561367
{t('CREATE DATASET')}
13571368
</Button>
13581369
<Button
13591370
buttonStyle="secondary"
1360-
// eslint-disable-next-line no-return-assign
13611371
onClick={() => {
13621372
setLoading(true);
13631373
fetchAndSetDB();
1364-
window.location.href = `/superset/sqllab/?db=true`;
1374+
redirectURL(`/superset/sqllab/?db=true`);
13651375
}}
13661376
>
13671377
{t('QUERY DATA IN SQL LAB')}

superset-frontend/src/views/CRUD/data/dataset/AddDataset/AddDataset.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import React from 'react';
2020
import { render, screen } from 'spec/helpers/testing-library';
2121
import AddDataset from 'src/views/CRUD/data/dataset/AddDataset';
2222

23+
const mockHistoryPush = jest.fn();
24+
jest.mock('react-router-dom', () => ({
25+
...jest.requireActual('react-router-dom'),
26+
useHistory: () => ({
27+
push: mockHistoryPush,
28+
}),
29+
}));
30+
2331
describe('AddDataset', () => {
2432
it('renders a blank state AddDataset', async () => {
2533
render(<AddDataset />, { useRedux: true });

superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const exampleDataset: DatasetObject[] = [
4040
id: 1,
4141
database_name: 'test_database',
4242
owners: [1],
43+
backend: 'test_backend',
4344
},
4445
schema: 'test_schema',
4546
dataset_name: 'example_dataset',

superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* under the License.
1818
*/
1919
import React, { useEffect, useState, useRef } from 'react';
20-
import { SupersetClient } from '@superset-ui/core';
20+
import { SupersetClient, logging, t } from '@superset-ui/core';
2121
import { DatasetObject } from 'src/views/CRUD/data/dataset/AddDataset/types';
22+
import { addDangerToast } from 'src/components/MessageToasts/actions';
2223
import DatasetPanel from './DatasetPanel';
2324
import { ITableColumn, IDatabaseTable, isIDatabaseTable } from './types';
2425

@@ -94,9 +95,17 @@ const DatasetPanelWrapper = ({
9495
setColumnList([]);
9596
setHasColumns?.(false);
9697
setHasError(true);
97-
// eslint-disable-next-line no-console
98-
console.error(
99-
`The API response from ${path} does not match the IDatabaseTable interface.`,
98+
addDangerToast(
99+
t(
100+
'The API response from %s does not match the IDatabaseTable interface.',
101+
path,
102+
),
103+
);
104+
logging.error(
105+
t(
106+
'The API response from %s does not match the IDatabaseTable interface.',
107+
path,
108+
),
100109
);
101110
}
102111
} catch (error) {

superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/Footer.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import React from 'react';
2020
import { render, screen } from 'spec/helpers/testing-library';
2121
import Footer from 'src/views/CRUD/data/dataset/AddDataset/Footer';
2222

23+
const mockHistoryPush = jest.fn();
24+
jest.mock('react-router-dom', () => ({
25+
...jest.requireActual('react-router-dom'),
26+
useHistory: () => ({
27+
push: mockHistoryPush,
28+
}),
29+
}));
30+
2331
const mockedProps = {
2432
url: 'realwebsite.com',
2533
};

0 commit comments

Comments
 (0)