You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2023/01/13 16:42:46 UTC
[superset] branch master updated: fix(explore): Restore missing dataset states (#22693)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f5c404fc51 fix(explore): Restore missing dataset states (#22693)
f5c404fc51 is described below
commit f5c404fc51e9bcdee23fd4ec269f6083b283f74b
Author: Cody Leff <co...@preset.io>
AuthorDate: Fri Jan 13 17:42:38 2023 +0100
fix(explore): Restore missing dataset states (#22693)
---
.../DatasourceControl/DatasourceControl.test.tsx | 32 ++++++++++++++++++++--
.../controls/DatasourceControl/index.jsx | 12 +++++---
2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
index 27b7bc5684..2c094e72af 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
@@ -18,10 +18,11 @@
*/
import React from 'react';
-import { render, screen, act, waitFor } from 'spec/helpers/testing-library';
+import fetchMock from 'fetch-mock';
import userEvent from '@testing-library/user-event';
import { DatasourceType, JsonObject, SupersetClient } from '@superset-ui/core';
-import fetchMock from 'fetch-mock';
+import { render, screen, act, waitFor } from 'spec/helpers/testing-library';
+import { fallbackExploreInitialData } from 'src/explore/fixtures';
import DatasourceControl from '.';
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
@@ -395,3 +396,30 @@ test('should not set the temporal column', async () => {
);
});
});
+
+test('should show missing params state', () => {
+ const props = createProps({ datasource: fallbackExploreInitialData.dataset });
+ render(<DatasourceControl {...props} />, { useRedux: true });
+ expect(screen.getByText(/missing dataset/i)).toBeVisible();
+ expect(screen.getByText(/missing url parameters/i)).toBeVisible();
+ expect(
+ screen.getByText(
+ /the url is missing the dataset_id or slice_id parameters\./i,
+ ),
+ ).toBeVisible();
+});
+
+test('should show missing dataset state', () => {
+ // @ts-ignore
+ delete window.location;
+ // @ts-ignore
+ window.location = { search: '?slice_id=152' };
+ const props = createProps({ datasource: fallbackExploreInitialData.dataset });
+ render(<DatasourceControl {...props} />, { useRedux: true });
+ expect(screen.getAllByText(/missing dataset/i)).toHaveLength(2);
+ expect(
+ screen.getByText(
+ /the dataset linked to this chart may have been deleted\./i,
+ ),
+ ).toBeVisible();
+});
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
index b6adbd9cee..c99193dd42 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx
@@ -267,11 +267,12 @@ class DatasourceControl extends React.PureComponent {
showSaveDatasetModal,
} = this.state;
const { datasource, onChange, theme } = this.props;
- const isMissingDatasource = datasource?.id == null;
+ const isMissingDatasource = !datasource?.id;
let isMissingParams = false;
if (isMissingDatasource) {
const datasourceId = getUrlParam(URL_PARAMS.datasourceId);
const sliceId = getUrlParam(URL_PARAMS.sliceId);
+
if (!datasourceId && !sliceId) {
isMissingParams = true;
}
@@ -288,7 +289,7 @@ class DatasourceControl extends React.PureComponent {
const defaultDatasourceMenu = (
<Menu onClick={this.handleMenuItemClick}>
- {this.props.isEditable && (
+ {this.props.isEditable && !isMissingDatasource && (
<Menu.Item
key={EDIT_DATASET}
data-test="edit-dataset"
@@ -308,7 +309,7 @@ class DatasourceControl extends React.PureComponent {
</Menu.Item>
)}
<Menu.Item key={CHANGE_DATASET}>{t('Swap dataset')}</Menu.Item>
- {datasource && canAccessSqlLab && (
+ {!isMissingDatasource && canAccessSqlLab && (
<Menu.Item key={VIEW_IN_SQL_LAB}>{t('View in SQL Lab')}</Menu.Item>
)}
</Menu>
@@ -358,7 +359,10 @@ class DatasourceControl extends React.PureComponent {
}
}
- const titleText = getDatasourceTitle(datasource);
+ const titleText = isMissingDatasource
+ ? t('Missing dataset')
+ : getDatasourceTitle(datasource);
+
const tooltip = titleText;
return (