You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/06/24 16:38:58 UTC
[incubator-superset] branch master updated: fix: refine
shouldUseLegacyApi and add tests (#10148)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 38667b7 fix: refine shouldUseLegacyApi and add tests (#10148)
38667b7 is described below
commit 38667b72b1123f1075b9fdff80c38383317886ba
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Wed Jun 24 19:38:36 2020 +0300
fix: refine shouldUseLegacyApi and add tests (#10148)
* fix: refine shouldUseLegacyApi and add tests
* address review comments
---
.../spec/javascripts/explore/utils_spec.jsx | 43 ++++++++++++++++++++++
superset-frontend/src/explore/exploreUtils.js | 4 +-
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/spec/javascripts/explore/utils_spec.jsx b/superset-frontend/spec/javascripts/explore/utils_spec.jsx
index c08f1d0..b482193 100644
--- a/superset-frontend/spec/javascripts/explore/utils_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/utils_spec.jsx
@@ -23,8 +23,10 @@ import {
buildV1ChartDataPayload,
getExploreUrl,
getExploreLongUrl,
+ shouldUseLegacyApi,
} from 'src/explore/exploreUtils';
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
+import { getChartMetadataRegistry } from '@superset-ui/chart';
describe('exploreUtils', () => {
const location = window.location;
@@ -202,4 +204,45 @@ describe('exploreUtils', () => {
expect(v1RequestPayload).hasOwnProperty('queries');
});
});
+
+ describe('shouldUseLegacyApi', () => {
+ beforeAll(() => {
+ getChartMetadataRegistry()
+ .registerValue('my_legacy_viz', { useLegacyApi: true })
+ .registerValue('my_v1_viz', { useLegacyApi: false });
+ });
+
+ afterAll(() => {
+ getChartMetadataRegistry().remove('my_legacy_viz').remove('my_v1_viz');
+ });
+
+ it('returns true for legacy viz', () => {
+ const useLegacyApi = shouldUseLegacyApi({
+ ...formData,
+ viz_type: 'my_legacy_viz',
+ });
+ expect(useLegacyApi).toBe(true);
+ });
+
+ it('returns false for v1 viz', () => {
+ const useLegacyApi = shouldUseLegacyApi({
+ ...formData,
+ viz_type: 'my_v1_viz',
+ });
+ expect(useLegacyApi).toBe(false);
+ });
+
+ it('returns false for formData with unregistered viz_type', () => {
+ const useLegacyApi = shouldUseLegacyApi({
+ ...formData,
+ viz_type: 'undefined_viz',
+ });
+ expect(useLegacyApi).toBe(false);
+ });
+
+ it('returns false for formData without viz_type', () => {
+ const useLegacyApi = shouldUseLegacyApi(formData);
+ expect(useLegacyApi).toBe(false);
+ });
+ });
});
diff --git a/superset-frontend/src/explore/exploreUtils.js b/superset-frontend/src/explore/exploreUtils.js
index 5d7e206..22dc534 100644
--- a/superset-frontend/src/explore/exploreUtils.js
+++ b/superset-frontend/src/explore/exploreUtils.js
@@ -194,8 +194,8 @@ export function getExploreUrl({
}
export const shouldUseLegacyApi = formData => {
- const { useLegacyApi } = getChartMetadataRegistry().get(formData.viz_type);
- return useLegacyApi || false;
+ const vizMetadata = getChartMetadataRegistry().get(formData.viz_type);
+ return vizMetadata ? vizMetadata.useLegacyApi : false;
};
export const buildV1ChartDataPayload = ({