Skip to content

Commit

Permalink
chore(explore): Migrate BigNumber to v1 api [ID-28][ID-55] (apache#17587
Browse files Browse the repository at this point in the history
)

* chore(explore): Migrate BigNumber to v1 api

* Move to echarts

* Use Echarts trendline

* Fix imports

* Fix parsing dates as strings

* Add from_dttm and to_dttm to v1 chart response

* Fix post processing

* Fix timeRangeFixed

* Fix tests

* Remove from and to dttm from cache

* Cleanup date formatting

* Fix storybook

* Fix missing types

* Fix timestamp with timezone

* Add types to demo's tsconfig

* bug fix

* fix import

* Fix cypress tests

* add sort

* add resample to handle missing values properly

* Sync ChartDataResponseResult schema with ts interface

* Lint fix

* Add migration

* Fix migration

* Remove pass

* Re-raise the exception in migration

* Typo fix

* Update revision

Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
  • Loading branch information
2 people authored and bwang221 committed Feb 10, 2022
1 parent cf1df95 commit a1c40f8
Show file tree
Hide file tree
Showing 45 changed files with 763 additions and 581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import { interceptChart } from 'cypress/utils';

describe('Visualization > Big Number with Trendline', () => {
const BIG_NUMBER_FORM_DATA = {
datasource: '2__table',
Expand All @@ -42,21 +44,21 @@ describe('Visualization > Big Number with Trendline', () => {
function verify(formData) {
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({
waitAlias: '@getJson',
waitAlias: '@chartData',
chartSelector: '.superset-legacy-chart-big-number',
});
}

beforeEach(() => {
cy.login();
cy.intercept('POST', '/superset/explore_json/**').as('getJson');
interceptChart({ legacy: false }).as('chartData');
});

it('should work', () => {
verify(BIG_NUMBER_FORM_DATA);
cy.get('.chart-container .header-line');
cy.get('.chart-container .subheader-line');
cy.get('.chart-container svg path.vx-linepath');
cy.get('.chart-container canvas');
});

it('should work without subheader', () => {
Expand All @@ -66,7 +68,7 @@ describe('Visualization > Big Number with Trendline', () => {
});
cy.get('.chart-container .header-line');
cy.get('.chart-container .subheader-line').should('not.exist');
cy.get('.chart-container svg path.vx-linepath');
cy.get('.chart-container canvas');
});

it('should not render trendline when hidden', () => {
Expand All @@ -76,6 +78,6 @@ describe('Visualization > Big Number with Trendline', () => {
});
cy.get('[data-test="chart-container"] .header-line');
cy.get('[data-test="chart-container"] .subheader-line');
cy.get('[data-test="chart-container"] svg').should('not.exist');
cy.get('[data-test="chart-container"] canvas').should('not.exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { interceptChart } from 'cypress/utils';
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';

describe('Visualization > Big Number Total', () => {
Expand All @@ -26,15 +27,15 @@ describe('Visualization > Big Number Total', () => {

beforeEach(() => {
cy.login();
cy.intercept('POST', '/superset/explore_json/**').as('getJson');
interceptChart({ legacy: false }).as('chartData');
});

it('Test big number chart with adhoc metric', () => {
const formData = { ...BIG_NUMBER_DEFAULTS, metric: NUM_METRIC };

cy.visitChartByParams(JSON.stringify(formData));
cy.visitChartByParams(formData);
cy.verifySliceSuccess({
waitAlias: '@getJson',
waitAlias: '@chartData',
querySubstring: NUM_METRIC.label,
});
});
Expand All @@ -58,8 +59,8 @@ describe('Visualization > Big Number Total', () => {
adhoc_filters: filters,
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson' });
cy.visitChartByParams(formData);
cy.verifySliceSuccess({ waitAlias: '@chartData' });
});

it('Test big number chart ignores groupby', () => {
Expand All @@ -69,11 +70,11 @@ describe('Visualization > Big Number Total', () => {
groupby: ['state'],
};

cy.visitChartByParams(JSON.stringify(formData));
cy.wait(['@getJson']).then(async ({ response }) => {
cy.visitChartByParams(formData);
cy.wait(['@chartData']).then(async ({ response }) => {
cy.verifySliceContainer();
const responseBody = response?.body;
expect(responseBody.query).not.contains(formData.groupby[0]);
expect(responseBody.result[0].query).not.contains(formData.groupby[0]);
});
});
});
2 changes: 2 additions & 0 deletions superset-frontend/cypress-base/cypress/utils/vizPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const V1_PLUGINS = [
'word_cloud',
'pie',
'table',
'big_number',
'big_number_total',
];
export const DASHBOARD_CHART_ALIAS_PREFIX = 'getChartData_';

Expand Down
27 changes: 6 additions & 21 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"@superset-ui/legacy-plugin-chart-sunburst": "^0.18.25",
"@superset-ui/legacy-plugin-chart-treemap": "^0.18.25",
"@superset-ui/legacy-plugin-chart-world-map": "^0.18.25",
"@superset-ui/legacy-preset-chart-big-number": "^0.18.25",
"@superset-ui/legacy-preset-chart-deckgl": "^0.4.13",
"@superset-ui/legacy-preset-chart-nvd3": "^0.18.25",
"@superset-ui/plugin-chart-echarts": "^0.18.25",
Expand Down Expand Up @@ -258,6 +257,7 @@
"@types/redux-localstorage": "^1.0.8",
"@types/redux-mock-store": "^1.0.2",
"@types/rison": "0.0.6",
"@types/shortid": "^0.0.29",
"@types/sinon": "^9.0.5",
"@types/yargs": "12 - 15",
"@typescript-eslint/eslint-plugin": "^5.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface ChartDataResponseResult {
annotation_data: AnnotationData[] | null;
cache_key: string | null;
cache_timeout: number | null;
cache_dttm: string | null;
cached_dttm: string | null;
/**
* Array of data records as dictionary
*/
Expand All @@ -76,6 +76,8 @@ export interface ChartDataResponseResult {
| 'scheduled'
| 'success'
| 'timed_out';
from_dttm: number | null;
to_dttm: number | null;
}

export interface TimeseriesChartDataResponseResult
Expand Down
1 change: 0 additions & 1 deletion superset-frontend/packages/superset-ui-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@superset-ui/legacy-plugin-chart-time-table": "0.18.25",
"@superset-ui/legacy-plugin-chart-treemap": "0.18.25",
"@superset-ui/legacy-plugin-chart-world-map": "0.18.25",
"@superset-ui/legacy-preset-chart-big-number": "0.18.25",
"@superset-ui/legacy-preset-chart-deckgl": "^0.4.13",
"@superset-ui/legacy-preset-chart-nvd3": "0.18.25",
"@superset-ui/plugin-chart-echarts": "0.18.25",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import React from 'react';
import { SuperChart } from '@superset-ui/core';
import { BigNumberChartPlugin } from '@superset-ui/legacy-preset-chart-big-number';
import { BigNumberChartPlugin } from '@superset-ui/plugin-chart-echarts';
import testData from './data';

new BigNumberChartPlugin().configure({ key: 'big-number' }).register();
Expand Down Expand Up @@ -56,7 +56,7 @@ function withNulls(origData: object[], nullPosition = 3) {
}

export default {
title: 'Legacy Chart Plugins/legacy-preset-big-number/BigNumber',
title: 'Legacy Chart Plugins/legacy-preset-big-number/BigNumberWithTrendline',
};

export const basicWithTrendline = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import React from 'react';
import { SuperChart } from '@superset-ui/core';
import { BigNumberTotalChartPlugin } from '@superset-ui/legacy-preset-chart-big-number';
import { BigNumberTotalChartPlugin } from '@superset-ui/plugin-chart-echarts';
import data from './data';

new BigNumberTotalChartPlugin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ChartDataProvider,
SupersetClient,
} from '@superset-ui/core';
import { BigNumberChartPlugin as LegacyBigNumberPlugin } from '@superset-ui/legacy-preset-chart-big-number';
import { BigNumberChartPlugin } from '@superset-ui/plugin-chart-echarts';
import LegacySankeyPlugin from '@superset-ui/legacy-plugin-chart-sankey';
import LegacySunburstPlugin from '@superset-ui/legacy-plugin-chart-sunburst';
import { WordCloudChartPlugin } from '@superset-ui/plugin-chart-word-cloud';
Expand All @@ -46,7 +46,7 @@ const SUNBURST = sunburstFormData.viz_type;
const WORD_CLOUD_LEGACY = wordCloudFormData.viz_type;
const WORD_CLOUD = 'new_word_cloud';

new LegacyBigNumberPlugin().configure({ key: BIG_NUMBER }).register();
new BigNumberChartPlugin().configure({ key: BIG_NUMBER }).register();
// eslint-disable-next-line
new LegacySankeyPlugin().configure({ key: SANKEY }).register();
// eslint-disable-next-line
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/packages/superset-ui-demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"storybook",
"../**/src",
"../../plugins/**/src",
"../../plugins/**/types",
]
}
67 changes: 0 additions & 67 deletions superset-frontend/plugins/legacy-preset-chart-big-number/README.md

This file was deleted.

Loading

0 comments on commit a1c40f8

Please sign in to comment.