Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor ResultSet to functional component #21186

Merged
merged 18 commits into from
Sep 6, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,35 @@
* under the License.
*/
import React from 'react';
import { useSelector } from 'react-redux';
import { t } from '@superset-ui/core';
import { useSelector, useDispatch } from 'react-redux';
import { t, JsonObject } from '@superset-ui/core';
import {
createCtasDatasource,
addInfoToast,
addDangerToast,
} from 'src/SqlLab/actions/sqlLab';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import Button from 'src/components/Button';
import { exploreChart } from 'src/explore/exploreUtils';
import { SqlLabRootState } from 'src/SqlLab/types';

interface ExploreCtasResultsButtonProps {
actions: {
createCtasDatasource: Function;
addInfoToast: Function;
addDangerToast: Function;
};
table: string;
schema?: string | null;
dbId: number;
templateParams?: string;
}

const ExploreCtasResultsButton = ({
actions,
table,
schema,
dbId,
templateParams,
}: ExploreCtasResultsButtonProps) => {
const { createCtasDatasource, addInfoToast, addDangerToast } = actions;
const errorMessage = useSelector(
(state: SqlLabRootState) => state.sqlLab.errorMessage,
);
const dispatch = useDispatch<(dispatch: any) => Promise<JsonObject>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently any is ok because actions/sqlLab.js is not typed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to type useDispatch though - in most places we just do const dispatch = useDispatch()


const buildVizOptions = {
datasourceName: table,
Expand All @@ -56,7 +55,7 @@ const ExploreCtasResultsButton = ({
};

const visualize = () => {
createCtasDatasource(buildVizOptions)
dispatch(createCtasDatasource(buildVizOptions))
.then((data: { table_id: number }) => {
const formData = {
datasource: `${data.table_id}__table`,
Expand All @@ -67,12 +66,14 @@ const ExploreCtasResultsButton = ({
all_columns: [],
row_limit: 1000,
};
addInfoToast(t('Creating a data source and creating a new tab'));
dispatch(
addInfoToast(t('Creating a data source and creating a new tab')),
);
// open new window for data visualization
exploreChart(formData);
})
.catch(() => {
addDangerToast(errorMessage || t('An error occurred'));
dispatch(addDangerToast(errorMessage || t('An error occurred')));
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const ExploreResultsButton = ({
onClick={onClick}
disabled={!allowsSubquery}
tooltip={t('Explore the result set in the data exploration view')}
data-test="explore-results-button"
>
<InfoTooltipWithTrigger
icon="line-chart"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ const QueryTable = ({
showSql
user={user}
query={query}
actions={actions}
height={400}
displayLimit={displayLimit}
defaultQueryLimit={1000}
Expand Down
219 changes: 0 additions & 219 deletions superset-frontend/src/SqlLab/components/ResultSet/ResultSet.test.jsx

This file was deleted.

Loading