Skip to content

Commit

Permalink
remove viz error code and addressed more concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored Jul 14, 2022
1 parent 432aee7 commit 15d530c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export enum SupersetApiErrorType {
VIZ_GET_DF_ERROR = 'VIZ_GET_DF_ERROR',
UNKNOWN_DATASOURCE_TYPE_ERROR = 'UNKNOWN_DATASOURCE_TYPE_ERROR',
FAILED_FETCHING_DATASOURCE_INFO_ERROR = 'FAILED_FETCHING_DATASOURCE_INFO_ERROR',
VIZ_TYPE_REQUIRES_DATASET_ERROR = 'VIZ_TYPE_REQUIRES_DATASET_ERROR',

// Security access errors,
TABLE_SECURITY_ACCESS_ERROR = 'TABLE_SECURITY_ACCESS_ERROR',
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/SqlLab/components/ResultSet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import shortid from 'shortid';
import { styled, t, QueryResponse } from '@superset-ui/core';
import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';
import {
ISaveableDataset,
ISaveableDatasource,
ISimpleColumn,
SaveDatasetModal,
} from 'src/SqlLab/components/SaveDatasetModal';
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class ResultSet extends React.PureComponent<
const { showSaveDatasetModal } = this.state;
const { query } = this.props;

const dataset: ISaveableDataset = {
const dataset: ISaveableDatasource = {
columns: query.columns as ISimpleColumn[],
name: query?.tab || 'Untitled',
dbId: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/
import React from 'react';
import {
ISaveableDataset,
ISaveableDatasource,
SaveDatasetModal,
} from 'src/SqlLab/components/SaveDatasetModal';
import { render, screen } from 'spec/helpers/testing-library';
import { DatasourceType } from '@superset-ui/core';

const testQuery: ISaveableDataset = {
const testQuery: ISaveableDatasource = {
name: 'unimportant',
dbId: 1,
sql: 'SELECT *',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface ISimpleColumn {
is_dttm?: boolean | null;
}

export interface ISaveableDataset {
export interface ISaveableDatasource {
columns: ISimpleColumn[];
name: string;
dbId: number;
Expand All @@ -80,7 +80,7 @@ interface SaveDatasetModalProps {
buttonTextOnSave: string;
buttonTextOnOverwrite: string;
modalDescription?: string;
datasource: ISaveableDataset;
datasource: ISaveableDatasource;
}

const Styles = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import React from 'react';
import { t } from '@superset-ui/core';
import getErrorMessageComponentRegistry from './getErrorMessageComponentRegistry';
import { SupersetError, ErrorSource, CUSTOM_ERROR_ALERT_MAP } from './types';
import { SupersetError, ErrorSource } from './types';
import ErrorAlert from './ErrorAlert';

const DEFAULT_TITLE = t('Unexpected error');
Expand All @@ -43,7 +43,6 @@ export default function ErrorMessageWithStackTrace({
link,
stackTrace,
source,
errorMitigationFunction,
}: Props) {
// Check if a custom error message component was registered for this message
if (error) {
Expand All @@ -60,12 +59,6 @@ export default function ErrorMessageWithStackTrace({
);
}
}
// this is in case an error needs a specific error alert
if (error && CUSTOM_ERROR_ALERT_MAP[error.error_type]) {
return CUSTOM_ERROR_ALERT_MAP[error.error_type]({
onClickFunction: errorMitigationFunction,
});
}

return (
<ErrorAlert
Expand Down
9 changes: 0 additions & 9 deletions superset-frontend/src/components/ErrorMessage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import vizTypeErrorAlert from './vizTypeErrorAlert';

// Keep in sync with superset/views/errors.py
export const ErrorTypeEnum = {
// Frontend errors
Expand Down Expand Up @@ -50,7 +48,6 @@ export const ErrorTypeEnum = {
UNKNOWN_DATASOURCE_TYPE_ERROR: 'UNKNOWN_DATASOURCE_TYPE_ERROR',
FAILED_FETCHING_DATASOURCE_INFO_ERROR:
'FAILED_FETCHING_DATASOURCE_INFO_ERROR',
VIZ_TYPE_REQUIRES_DATASET_ERROR: 'VIZ_TYPE_REQUIRES_DATASET_ERROR',

// Security access errors
TABLE_SECURITY_ACCESS_ERROR: 'TABLE_SECURITY_ACCESS_ERROR',
Expand Down Expand Up @@ -108,9 +105,3 @@ export type ErrorMessageComponentProps<ExtraType = Record<string, any> | null> =

export type ErrorMessageComponent =
React.ComponentType<ErrorMessageComponentProps>;

// created in case a component needs a specific error. This maps to
// the specific error component.
export const CUSTOM_ERROR_ALERT_MAP = {
VIZ_TYPE_REQUIRES_DATASET_ERROR: vizTypeErrorAlert,
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { matchSorter, rankings } from 'match-sorter';
import Collapse from 'src/components/Collapse';
import Alert from 'src/components/Alert';
import {
ISaveableDataset,
ISaveableDatasource,
ISimpleColumn,
SaveDatasetModal,
} from 'src/SqlLab/components/SaveDatasetModal';
Expand Down Expand Up @@ -231,7 +231,7 @@ export default function DataSourcePanel({
);

const getDatasourceAsSaveableDataset = (source: IDatasource) => {
const dataset: ISaveableDataset = {
const dataset: ISaveableDatasource = {
columns: (source?.columns as ISimpleColumn[]) || [],
name: source?.datasource_name || source?.name || t('Untitled'),
dbId: source?.database.id,
Expand Down Expand Up @@ -346,9 +346,13 @@ export default function DataSourcePanel({
return true;
};

const datasourceIsSaveable = !(
datasource?.type in [DatasourceType.Query, DatasourceType.SavedQuery]
);
const saveableDatasets = {
query: DatasourceType.Query,
saved_query: DatasourceType.SavedQuery,
};

const datasourceIsSaveable =
datasource.type && saveableDatasets[datasource.type];

const mainBody = useMemo(
() => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ export const renderDatasourceTitle = (displayString, tooltip) =>
);

// Different data source types use different attributes for the display title
export const getDatasourceTitle = datasource =>
datasource?.name ?? datasource?.sql ?? '';
export const getDatasourceTitle = datasource => {
if (datasource.type === 'query') return datasource?.sql;
return datasource?.name;
};

class DatasourceControl extends React.PureComponent {
constructor(props) {
Expand All @@ -166,16 +168,13 @@ class DatasourceControl extends React.PureComponent {
};
}

getDatasourceAsSaveableDataset = source => {
const dataset = {
columns: source?.columns || [],
name: source?.datasource_name || source?.name || t('Untitled'),
dbId: source?.database.id,
sql: source?.sql || '',
schema: source?.schema,
};
return dataset;
};
getDatasourceAsSaveableDataset = source => ({
columns: source?.columns || [],
name: source?.datasource_name || source?.name || t('Untitled'),
dbId: source?.database.id,
sql: source?.sql || '',
schema: source?.schema,
});

onDatasourceSave = datasource => {
this.props.actions.setDatasource(datasource);
Expand Down Expand Up @@ -340,7 +339,7 @@ class DatasourceControl extends React.PureComponent {
if (datasource?.extra) {
if (isString(datasource.extra)) {
try {
extra = JSON.parse(datasource?.extra);
extra = JSON.parse(datasource.extra);
} catch {} // eslint-disable-line no-empty
} else {
extra = datasource.extra; // eslint-disable-line prefer-destructuring
Expand Down

0 comments on commit 15d530c

Please sign in to comment.