From 577ac81686a9bf2074320e2eeb84bfa4d5562822 Mon Sep 17 00:00:00 2001
From: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Date: Thu, 19 Jan 2023 14:53:48 +0200
Subject: [PATCH] chore(ci): fix numpy type errors and revert #22610 (#22782)
---
setup.cfg | 4 +-
.../DatasourcePanel/DatasourcePanel.test.tsx | 21 +++
.../ColumnSelectPopover.tsx | 4 +-
.../src/pages/ChartCreation/index.tsx | 5 +-
.../views/CRUD/data/database/DatabaseList.tsx | 4 -
.../database/DatabaseModal/index.test.tsx | 8 -
.../data/database/DatabaseModal/index.tsx | 6 +-
.../dataset/AddDataset/AddDataset.test.tsx | 8 -
.../AddDataset/DatasetPanel/fixtures.ts | 1 -
.../dataset/AddDataset/DatasetPanel/index.tsx | 17 +-
.../dataset/AddDataset/Footer/Footer.test.tsx | 8 -
.../data/dataset/AddDataset/Footer/index.tsx | 14 +-
.../AddDataset/LeftPanel/LeftPanel.test.tsx | 20 +-
.../dataset/AddDataset/LeftPanel/index.tsx | 106 ++++-------
.../CRUD/data/dataset/AddDataset/index.tsx | 30 ++-
.../CRUD/data/dataset/AddDataset/types.tsx | 8 +-
.../CRUD/data/dataset/AddDatasetModal.tsx | 172 ++++++++++++++++++
.../DatasetLayout/DatasetLayout.test.tsx | 8 -
.../views/CRUD/data/dataset/DatasetList.tsx | 45 ++++-
.../src/views/CRUD/data/hooks.ts | 10 +-
.../src/views/components/RightMenu.test.tsx | 3 +
.../src/views/components/RightMenu.tsx | 17 +-
superset/db_engine_specs/hive.py | 4 +-
superset/reports/commands/alert.py | 10 +-
superset/result_set.py | 15 +-
.../utils/pandas_postprocessing/boxplot.py | 10 +-
.../utils/pandas_postprocessing/flatten.py | 2 +-
superset/utils/pandas_postprocessing/utils.py | 2 +-
superset/views/datasource/views.py | 5 +-
29 files changed, 372 insertions(+), 195 deletions(-)
create mode 100644 superset-frontend/src/views/CRUD/data/dataset/AddDatasetModal.tsx
diff --git a/setup.cfg b/setup.cfg
index c4cd568c5116..a9470d51bd8b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -17,9 +17,9 @@
[metadata]
name = Superset
summary = a data exploration platform
-description-file = README.md
+description_file = README.md
author = Apache Superset Dev
-author-email = dev@superset.apache.org
+author_email = dev@superset.apache.org
license = Apache License, Version 2.0
[files]
diff --git a/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanel.test.tsx b/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanel.test.tsx
index 95258f443ec4..eedc2fb10117 100644
--- a/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanel.test.tsx
+++ b/superset-frontend/src/explore/components/DatasourcePanel/DatasourcePanel.test.tsx
@@ -186,6 +186,27 @@ test('should render a create dataset infobox', async () => {
expect(infoboxText).toBeVisible();
});
+test('should render a save dataset modal when "Create a dataset" is clicked', async () => {
+ const newProps = {
+ ...props,
+ datasource: {
+ ...datasource,
+ type: DatasourceType.Query,
+ },
+ };
+ render(, { useRedux: true, useDnd: true });
+
+ const createButton = await screen.findByRole('button', {
+ name: /create a dataset/i,
+ });
+
+ userEvent.click(createButton);
+
+ const saveDatasetModalTitle = screen.getByText(/save or overwrite dataset/i);
+
+ expect(saveDatasetModalTitle).toBeVisible();
+});
+
test('should not render a save dataset modal when datasource is not query or dataset', async () => {
const newProps = {
...props,
diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx
index dbbc8fe94843..fee2eb941ff6 100644
--- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx
+++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/ColumnSelectPopover.tsx
@@ -231,9 +231,7 @@ const ColumnSelectPopover = ({
}, []);
const setDatasetAndClose = () => {
- if (setDatasetModal) {
- setDatasetModal(true);
- }
+ if (setDatasetModal) setDatasetModal(true);
onClose();
};
diff --git a/superset-frontend/src/pages/ChartCreation/index.tsx b/superset-frontend/src/pages/ChartCreation/index.tsx
index bea530fd3ad5..4aeb7aeed4df 100644
--- a/superset-frontend/src/pages/ChartCreation/index.tsx
+++ b/superset-frontend/src/pages/ChartCreation/index.tsx
@@ -337,7 +337,10 @@ export class ChartCreation extends React.PureComponent<
const isButtonDisabled = this.isBtnDisabled();
const datasetHelpText = this.state.canCreateDataset ? (
-
+
{t('Add a dataset')}
{` ${t('or')} `}
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
index 0e3642493ad0..744edb51b18e 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx
@@ -21,7 +21,6 @@ import React, { useState, useMemo, useEffect } from 'react';
import rison from 'rison';
import { useSelector } from 'react-redux';
import { useQueryParams, BooleanParam } from 'use-query-params';
-import { LocalStorageKeys, setItem } from 'src/utils/localStorageHelpers';
import Loading from 'src/components/Loading';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
@@ -158,9 +157,6 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
refreshData();
addSuccessToast(t('Deleted: %s', dbName));
- // Delete user-selected db from local storage
- setItem(LocalStorageKeys.db, null);
-
// Close delete modal
setDatabaseCurrentlyDeleting(null);
},
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.test.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.test.tsx
index 9542450f4486..ebc20eb38896 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.test.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.test.tsx
@@ -43,14 +43,6 @@ jest.mock('@superset-ui/core', () => ({
isFeatureEnabled: () => true,
}));
-const mockHistoryPush = jest.fn();
-jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockHistoryPush,
- }),
-}));
-
const dbProps = {
show: true,
database_name: 'my database',
diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
index 5f85ae098502..603f449fec71 100644
--- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
@@ -31,7 +31,6 @@ import React, {
useReducer,
Reducer,
} from 'react';
-import { useHistory } from 'react-router-dom';
import { setItem, LocalStorageKeys } from 'src/utils/localStorageHelpers';
import { UploadChangeParam, UploadFile } from 'antd/lib/upload/interface';
import Tabs from 'src/components/Tabs';
@@ -519,7 +518,6 @@ const DatabaseModal: FunctionComponent = ({
t('database'),
addDangerToast,
);
- const history = useHistory();
const [tabKey, setTabKey] = useState(DEFAULT_TAB_KEY);
const [availableDbs, getAvailableDbs] = useAvailableDatabases();
@@ -1297,7 +1295,7 @@ const DatabaseModal: FunctionComponent = ({
onClick={() => {
setLoading(true);
fetchAndSetDB();
- history.push('/dataset/add/');
+ window.location.href = '/tablemodelview/list#create';
}}
>
{t('CREATE DATASET')}
@@ -1308,7 +1306,7 @@ const DatabaseModal: FunctionComponent = ({
onClick={() => {
setLoading(true);
fetchAndSetDB();
- history.push(`/superset/sqllab/?db=true`);
+ window.location.href = `/superset/sqllab/?db=true`;
}}
>
{t('QUERY DATA IN SQL LAB')}
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/AddDataset.test.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/AddDataset.test.tsx
index 7e5a7de12ab3..39fb2b295b30 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/AddDataset.test.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/AddDataset.test.tsx
@@ -20,14 +20,6 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import AddDataset from 'src/views/CRUD/data/dataset/AddDataset';
-const mockHistoryPush = jest.fn();
-jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockHistoryPush,
- }),
-}));
-
describe('AddDataset', () => {
it('renders a blank state AddDataset', async () => {
render(, { useRedux: true });
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures.ts b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures.ts
index 5c09188c61a8..d3ee58da14b9 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures.ts
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures.ts
@@ -40,7 +40,6 @@ export const exampleDataset: DatasetObject[] = [
id: 1,
database_name: 'test_database',
owners: [1],
- backend: 'test_backend',
},
schema: 'test_schema',
dataset_name: 'example_dataset',
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/index.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/index.tsx
index 73bea70b41f2..15e6225e5612 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/index.tsx
@@ -17,9 +17,8 @@
* under the License.
*/
import React, { useEffect, useState, useRef } from 'react';
-import { SupersetClient, logging, t } from '@superset-ui/core';
+import { SupersetClient } from '@superset-ui/core';
import { DatasetObject } from 'src/views/CRUD/data/dataset/AddDataset/types';
-import { addDangerToast } from 'src/components/MessageToasts/actions';
import DatasetPanel from './DatasetPanel';
import { ITableColumn, IDatabaseTable, isIDatabaseTable } from './types';
@@ -95,17 +94,9 @@ const DatasetPanelWrapper = ({
setColumnList([]);
setHasColumns?.(false);
setHasError(true);
- addDangerToast(
- t(
- 'The API response from %s does not match the IDatabaseTable interface.',
- path,
- ),
- );
- logging.error(
- t(
- 'The API response from %s does not match the IDatabaseTable interface.',
- path,
- ),
+ // eslint-disable-next-line no-console
+ console.error(
+ `The API response from ${path} does not match the IDatabaseTable interface.`,
);
}
} catch (error) {
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/Footer.test.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/Footer.test.tsx
index a1818cdf2291..8fcbd83b15cc 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/Footer.test.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/Footer.test.tsx
@@ -20,14 +20,6 @@ import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import Footer from 'src/views/CRUD/data/dataset/AddDataset/Footer';
-const mockHistoryPush = jest.fn();
-jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockHistoryPush,
- }),
-}));
-
const mockedProps = {
url: 'realwebsite.com',
};
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/index.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/index.tsx
index 7f6717857f56..5aecec0bb892 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/Footer/index.tsx
@@ -17,7 +17,6 @@
* under the License.
*/
import React from 'react';
-import { useHistory } from 'react-router-dom';
import Button from 'src/components/Button';
import { t } from '@superset-ui/core';
import { useSingleViewResource } from 'src/views/CRUD/hooks';
@@ -50,12 +49,12 @@ const LOG_ACTIONS = [
];
function Footer({
+ url,
datasetObject,
addDangerToast,
hasColumns = false,
datasets,
}: FooterProps) {
- const history = useHistory();
const { createResource } = useSingleViewResource>(
'dataset',
t('dataset'),
@@ -73,6 +72,11 @@ function Footer({
return LOG_ACTIONS[value];
};
+ const goToPreviousUrl = () => {
+ // this is a placeholder url until the final feature gets implemented
+ // at that point we will be passing in the url of the previous location.
+ window.location.href = url;
+ };
const cancelButtonOnClick = () => {
if (!datasetObject) {
@@ -81,7 +85,7 @@ function Footer({
const logAction = createLogAction(datasetObject);
logEvent(logAction, datasetObject);
}
- history.goBack();
+ goToPreviousUrl();
};
const tooltipText = t('Select a database table.');
@@ -100,13 +104,13 @@ function Footer({
if (typeof response === 'number') {
logEvent(LOG_ACTIONS_DATASET_CREATION_SUCCESS, datasetObject);
// When a dataset is created the response we get is its ID number
- history.push(`/chart/add/?dataset=${datasetObject.table_name}`);
+ goToPreviousUrl();
}
});
}
};
- const CREATE_DATASET_TEXT = t('Create Dataset and Create Chart');
+ const CREATE_DATASET_TEXT = t('Create Dataset');
const disabledCheck =
!datasetObject?.table_name ||
!hasColumns ||
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/LeftPanel.test.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/LeftPanel.test.tsx
index bc8c1d03debe..7457f0c25095 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/LeftPanel.test.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/LeftPanel.test.tsx
@@ -21,7 +21,6 @@ import fetchMock from 'fetch-mock';
import userEvent from '@testing-library/user-event';
import { render, screen, waitFor } from 'spec/helpers/testing-library';
import LeftPanel from 'src/views/CRUD/data/dataset/AddDataset/LeftPanel';
-import { exampleDataset } from 'src/views/CRUD/data/dataset/AddDataset/DatasetPanel/fixtures';
const databasesEndpoint = 'glob:*/api/v1/database/?q*';
const schemasEndpoint = 'glob:*/api/v1/database/*/schemas*';
@@ -182,7 +181,7 @@ test('does not render blank state if there is nothing selected', async () => {
});
test('renders list of options when user clicks on schema', async () => {
- render(, {
+ render(, {
useRedux: true,
});
@@ -190,21 +189,23 @@ test('renders list of options when user clicks on schema', async () => {
const databaseSelect = screen.getByRole('combobox', {
name: 'Select database or type database name',
});
+ // Schema select should be disabled until database is selected
+ const schemaSelect = screen.getByRole('combobox', {
+ name: /select schema or type schema name/i,
+ });
userEvent.click(databaseSelect);
expect(await screen.findByText('test-postgres')).toBeInTheDocument();
+ expect(schemaSelect).toBeDisabled();
userEvent.click(screen.getByText('test-postgres'));
- // Schema select will be automatically populated if there is only one schema
- const schemaSelect = screen.getByRole('combobox', {
- name: /select schema or type schema name/i,
- });
+ // Wait for schema field to be enabled
await waitFor(() => {
expect(schemaSelect).toBeEnabled();
});
});
test('searches for a table name', async () => {
- render(, {
+ render(, {
useRedux: true,
});
@@ -244,8 +245,9 @@ test('renders a warning icon when a table name has a pre-existing dataset', asyn
render(
,
{
useRedux: true,
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx
index 14dd7dca4b84..4f7dfca196f4 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx
@@ -16,13 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-import React, {
- useEffect,
- useState,
- SetStateAction,
- Dispatch,
- useCallback,
-} from 'react';
+import React, { useEffect, useState, SetStateAction, Dispatch } from 'react';
import {
SupersetClient,
t,
@@ -46,16 +40,13 @@ import {
emptyStateComponent,
} from 'src/components/EmptyState';
import { useToasts } from 'src/components/MessageToasts/withToasts';
-import { LocalStorageKeys, getItem } from 'src/utils/localStorageHelpers';
-import {
- DatasetActionType,
- DatasetObject,
-} from 'src/views/CRUD/data/dataset/AddDataset/types';
+import { DatasetActionType } from '../types';
interface LeftPanelProps {
setDataset: Dispatch>;
- dataset?: Partial | null;
- datasetNames?: (string | null | undefined)[] | undefined;
+ schema?: string | null | undefined;
+ dbId?: number;
+ datasets?: (string | null | undefined)[] | undefined;
}
const SearchIcon = styled(Icons.Search)`
@@ -154,8 +145,9 @@ const LeftPanelStyle = styled.div`
export default function LeftPanel({
setDataset,
- dataset,
- datasetNames,
+ schema,
+ dbId,
+ datasets,
}: LeftPanelProps) {
const theme = useTheme();
@@ -168,14 +160,11 @@ export default function LeftPanel({
const { addDangerToast } = useToasts();
- const setDatabase = useCallback(
- (db: Partial) => {
- setDataset({ type: DatasetActionType.selectDatabase, payload: { db } });
- setSelectedTable(null);
- setResetTables(true);
- },
- [setDataset],
- );
+ const setDatabase = (db: Partial) => {
+ setDataset({ type: DatasetActionType.selectDatabase, payload: { db } });
+ setSelectedTable(null);
+ setResetTables(true);
+ };
const setTable = (tableName: string, index: number) => {
setSelectedTable(index);
@@ -185,32 +174,28 @@ export default function LeftPanel({
});
};
- const getTablesList = useCallback(
- (url: string) => {
- SupersetClient.get({ url })
- .then(({ json }) => {
- const options: TableOption[] = json.options.map((table: Table) => {
- const option: TableOption = {
- value: table.value,
- label: ,
- text: table.label,
- };
-
- return option;
- });
+ const getTablesList = (url: string) => {
+ SupersetClient.get({ url })
+ .then(({ json }) => {
+ const options: TableOption[] = json.options.map((table: Table) => {
+ const option: TableOption = {
+ value: table.value,
+ label: ,
+ text: table.label,
+ };
- setTableOptions(options);
- setLoadTables(false);
- setResetTables(false);
- setRefresh(false);
- })
- .catch(error => {
- addDangerToast(t('There was an error fetching tables'));
- logging.error(t('There was an error fetching tables'), error);
+ return option;
});
- },
- [addDangerToast],
- );
+
+ setTableOptions(options);
+ setLoadTables(false);
+ setResetTables(false);
+ setRefresh(false);
+ })
+ .catch(error =>
+ logging.error('There was an error fetching tables', error),
+ );
+ };
const setSchema = (schema: string) => {
if (schema) {
@@ -224,28 +209,16 @@ export default function LeftPanel({
setResetTables(true);
};
- const encodedSchema = dataset?.schema
- ? encodeURIComponent(dataset?.schema)
- : undefined;
-
- useEffect(() => {
- const currentUserSelectedDb = getItem(
- LocalStorageKeys.db,
- null,
- ) as DatabaseObject;
- if (currentUserSelectedDb) {
- setDatabase(currentUserSelectedDb);
- }
- }, [setDatabase]);
+ const encodedSchema = schema ? encodeURIComponent(schema) : undefined;
useEffect(() => {
if (loadTables) {
const endpoint = encodeURI(
- `/superset/tables/${dataset?.db?.id}/${encodedSchema}/${refresh}/`,
+ `/superset/tables/${dbId}/${encodedSchema}/${refresh}/`,
);
getTablesList(endpoint);
}
- }, [loadTables, dataset?.db?.id, encodedSchema, getTablesList, refresh]);
+ }, [loadTables]);
useEffect(() => {
if (resetTables) {
@@ -289,7 +262,6 @@ export default function LeftPanel({
{SELECT_DATABASE_AND_SCHEMA_TEXT}
{loadTables && !refresh && Loader(TABLE_LOADING_TEXT)}
- {dataset?.schema && !loadTables && !tableOptions.length && !searchVal && (
+ {schema && !loadTables && !tableOptions.length && !searchVal && (
)}
- {dataset?.schema && (tableOptions.length > 0 || searchVal.length > 0) && (
+ {schema && (tableOptions.length > 0 || searchVal.length > 0) && (
<>