Skip to content

Commit

Permalink
refactor: Creates the VizType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Nov 28, 2024
1 parent dbcb473 commit a9315fc
Show file tree
Hide file tree
Showing 138 changed files with 723 additions and 533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { QueryObject, SqlaFormData } from '@superset-ui/core';
import { QueryObject, SqlaFormData, VizType } from '@superset-ui/core';
import { boxplotOperator } from '@superset-ui/chart-controls';

const formData: SqlaFormData = {
Expand All @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
time_grain_sqla: 'P1Y',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { QueryObject, SqlaFormData } from '@superset-ui/core';
import { QueryObject, SqlaFormData, VizType } from '@superset-ui/core';
import { contributionOperator } from '@superset-ui/chart-controls';

const formData: SqlaFormData = {
Expand All @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { histogramOperator } from '@superset-ui/chart-controls';
import { SqlaFormData } from '@superset-ui/core';
import { SqlaFormData, VizType } from '@superset-ui/core';
import { omit } from 'lodash';

const formData: SqlaFormData = {
Expand All @@ -26,7 +26,7 @@ const formData: SqlaFormData = {
cumulative: true,
normalize: true,
groupby: ['country', 'region'],
viz_type: 'histogram',
viz_type: VizType.LegacyHistogram,
datasource: 'foo',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
show_empty_columns: true,
};
const queryObject: QueryObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
time_grain_sqla: 'P1Y',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
truncate_metric: true,
};
const queryObject: QueryObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
truncate_metric: true,
};
const queryObject: QueryObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const queryObject: QueryObject = {
metrics: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const formData: SqlaFormData = {
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
show_empty_columns: true,
};
const queryObject: QueryObject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { extractExtraMetrics } from '@superset-ui/chart-controls';

const baseFormData: QueryFormData = {
datasource: 'dummy',
viz_type: 'table',
viz_type: VizType.Table,
metrics: ['a', 'b'],
columns: ['foo', 'bar'],
limit: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SqlaFormData, ComparisonType } from '@superset-ui/core';

const formData: SqlaFormData = {
datasource: 'foo',
viz_type: 'table',
viz_type: VizType.Table,
};
const series = {
id: 'metric__1 month ago',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const mockData = {
exportState: {},
form_data: {
datasource: '22__table',
viz_type: 'table',
viz_type: VizType.Table,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getStandardizedControls } from '../../src';

const formData: QueryFormData = {
datasource: '30__table',
viz_type: 'table',
viz_type: VizType.Table,
standardizedFormData: {
controls: {
metrics: ['count(*)', 'sum(sales)'],
Expand All @@ -34,7 +34,7 @@ const formData: QueryFormData = {
test('without standardizedFormData', () => {
getStandardizedControls().setStandardizedControls({
datasource: '30__table',
viz_type: 'table',
viz_type: VizType.Table,
});
expect(getStandardizedControls().controls).toEqual({
metrics: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export { default as ChartDataProvider } from './components/ChartDataProvider';
export * from './types/Base';
export * from './types/TransformFunction';
export * from './types/QueryResponse';
export * from './types/VizType';

export { default as __hack_reexport_chart_Base } from './types/Base';
export { default as __hack_reexport_chart_TransformFunction } from './types/TransformFunction';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export enum VizType {
Area = 'echarts_area',
Bar = 'echarts_timeseries_bar',
BigNumber = 'big_number',
BigNumberTotal = 'big_number_total',
BigNumberPeriodOverPeriod = 'pop_kpi',
BoxPlot = 'box_plot',
Bubble = 'bubble_v2',
Bullet = 'bullet',
Calendar = 'cal_heatmap',
Chord = 'chord',
Compare = 'compare',
CountryMap = 'country_map',
DistBar = 'dist_bar',
EventFlow = 'event_flow',
Funnel = 'funnel',
Gauge = 'gauge_chart',
Graph = 'graph_chart',
Handlebars = 'handlebars',
Heatmap = 'heatmap_v2',
Histogram = 'histogram_v2',
Horizon = 'horizon',
LegacyArea = 'area',
LegacyBar = 'bar',
LegacyBubble = 'bubble',
LegacyHeatmap = 'heatmap',
LegacyHistogram = 'histogram',
LegacyLine = 'line',
LegacySankey = 'sankey',
Line = 'echarts_timeseries_line',
MapBox = 'mapbox',
MixedTimeseries = 'mixed_timeseries',
PairedTTest = 'paired_ttest',
ParallelCoordinates = 'para',
Partition = 'partition',
Pie = 'pie',
PivotTable = 'pivot_table_v2',
Radar = 'radar',
Rose = 'rose',
Sankey = 'sankey_v2',
Scatter = 'echarts_timeseries_scatter',
SmoothLine = 'echarts_timeseries_smooth',
Step = 'echarts_timeseries_step',
Sunburst = 'sunburst_v2',
Table = 'table',
TimePivot = 'time_pivot',
TimeTable = 'time_table',
Timeseries = 'echarts_timeseries',
Tree = 'tree_chart',
Treemap = 'treemap_v2',
Waterfall = 'waterfall',
WordCloud = 'word_cloud',
WorldMap = 'world_map',
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getChartBuildQueryRegistry,
getChartMetadataRegistry,
ChartMetadata,
VizType,
} from '@superset-ui/core';

import { LOGIN_GLOB } from '../fixtures/constants';
Expand Down Expand Up @@ -86,13 +87,13 @@ describe('ChartClient', () => {
sliceId,
formData: {
granularity: 'second',
viz_type: 'bar',
viz_type: VizType.LegacyBar,
},
}),
).resolves.toEqual({
...sankeyFormData,
granularity: 'second',
viz_type: 'bar',
viz_type: VizType.LegacyBar,
});
});
it('returns promise of formData if only formData was given', () =>
Expand All @@ -101,13 +102,13 @@ describe('ChartClient', () => {
formData: {
datasource: '1__table',
granularity: 'minute',
viz_type: 'line',
viz_type: VizType.LegacyLine,
},
}),
).resolves.toEqual({
datasource: '1__table',
granularity: 'minute',
viz_type: 'line',
viz_type: VizType.LegacyLine,
}));
it('rejects if none of sliceId or formData is specified', () =>
expect(
Expand All @@ -120,12 +121,12 @@ describe('ChartClient', () => {
describe('.loadQueryData(formData, options)', () => {
it('returns a promise of query data for known chart type', () => {
getChartMetadataRegistry().registerValue(
'word_cloud',
VizType.WordCloud,
new ChartMetadata({ name: 'Word Cloud', thumbnail: '' }),
);

getChartBuildQueryRegistry().registerValue(
'word_cloud',
VizType.WordCloud,
(formData: QueryFormData) => buildQueryContext(formData),
);
fetchMock.post('glob:*/api/v1/chart/data', [
Expand All @@ -138,7 +139,7 @@ describe('ChartClient', () => {
return expect(
chartClient.loadQueryData({
granularity: 'minute',
viz_type: 'word_cloud',
viz_type: VizType.WordCloud,
datasource: '1__table',
}),
).resolves.toEqual([
Expand Down Expand Up @@ -255,7 +256,7 @@ describe('ChartClient', () => {
it('loadAllDataNecessaryForAChart', () => {
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=${sliceId}`, {
granularity: 'minute',
viz_type: 'line',
viz_type: VizType.LegacyLine,
datasource: '1__table',
color: 'living-coral',
});
Expand All @@ -275,12 +276,12 @@ describe('ChartClient', () => {
});

getChartMetadataRegistry().registerValue(
'line',
VizType.LegacyLine,
new ChartMetadata({ name: 'Line', thumbnail: '.gif' }),
);

getChartBuildQueryRegistry().registerValue(
'line',
VizType.LegacyLine,
(formData: QueryFormData) => buildQueryContext(formData),
);

Expand All @@ -296,7 +297,7 @@ describe('ChartClient', () => {
},
formData: {
granularity: 'minute',
viz_type: 'line',
viz_type: VizType.LegacyLine,
datasource: '1__table',
color: 'living-coral',
},
Expand Down
Loading

0 comments on commit a9315fc

Please sign in to comment.