Skip to content

Commit

Permalink
Merge branch 'master' into bump-slackclient-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
ecederstrand authored Sep 26, 2022
2 parents db7688b + 954fc89 commit 3546c50
Show file tree
Hide file tree
Showing 30 changed files with 874 additions and 163 deletions.
13 changes: 13 additions & 0 deletions docs/static/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,9 @@
},
"name": {
"type": "string"
},
"engine_information": {
"type": "object"
}
},
"type": "object"
Expand Down Expand Up @@ -3738,6 +3741,9 @@
"sqlalchemy_uri": {
"maxLength": 1024,
"type": "string"
},
"engine_information": {
"readOnly": true
}
},
"required": [
Expand Down Expand Up @@ -3817,6 +3823,9 @@
"id": {
"format": "int32",
"type": "integer"
},
"engine_information": {
"readOnly": true
}
},
"required": [
Expand Down Expand Up @@ -13634,6 +13643,10 @@
"sqlalchemy_uri_placeholder": {
"description": "Example placeholder for the SQLAlchemy URI",
"type": "string"
},
"engine_information": {
"description": "Object with properties we want to expose from our DB engine",
"type": "object"
}
},
"type": "object"
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ sqlalchemy-utils==0.38.3
# via
# apache-superset
# flask-appbuilder
sqlparse==0.3.0
sqlparse==0.4.3
# via apache-superset
tabulate==0.8.9
# via apache-superset
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_git_sha() -> str:
"slack_sdk>=3.1.1, <4",
"sqlalchemy>=1.4, <2",
"sqlalchemy-utils>=0.38.3, <0.39",
"sqlparse==0.3.0", # PINNED! see https://github.com/andialbrecht/sqlparse/issues/562
"sqlparse>=0.4.3, <0.5",
"tabulate>=0.8.9, <0.9",
# needed to support Literal (3.8) and TypeGuard (3.10)
"typing-extensions>=3.10, <4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export { legacySortBy } from './shared-controls/legacySortBy';
export * from './shared-controls/emitFilterControl';
export * from './shared-controls/components';
export * from './types';
export { xAxisMixin, temporalColumnMixin } from './shared-controls/constants';
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ import {
FeatureFlag,
isFeatureEnabled,
QueryFormData,
QueryResponse,
t,
validateNonEmpty,
} from '@superset-ui/core';
import { ControlPanelState, ControlState } from '../types';
import {
BaseControlConfig,
ControlPanelState,
ControlState,
Dataset,
} from '../types';

const getAxisLabel = (
formData: QueryFormData,
Expand All @@ -32,7 +38,7 @@ const getAxisLabel = (
? { label: t('Y-axis'), description: t('Dimension to use on y-axis.') }
: { label: t('X-axis'), description: t('Dimension to use on x-axis.') };

export const xAxisControlConfig = {
export const xAxisMixin = {
label: (state: ControlPanelState) => getAxisLabel(state?.form_data).label,
multi: false,
description: (state: ControlPanelState) =>
Expand All @@ -51,3 +57,28 @@ export const xAxisControlConfig = {
},
default: undefined,
};

export const temporalColumnMixin: Pick<BaseControlConfig, 'mapStateToProps'> = {
mapStateToProps: ({ datasource }) => {
if (datasource?.columns[0]?.hasOwnProperty('column_name')) {
const temporalColumns =
(datasource as Dataset)?.columns?.filter(c => c.is_dttm) ?? [];
return {
options: temporalColumns,
default:
(datasource as Dataset)?.main_dttm_col ||
temporalColumns[0]?.column_name ||
null,
isTemporal: true,
};
}
const sortedQueryColumns = (datasource as QueryResponse)?.columns?.sort(
query => (query?.is_dttm ? -1 : 1),
);
return {
options: sortedQueryColumns,
default: sortedQueryColumns[0]?.name || null,
isTemporal: true,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
FeatureFlag,
isFeatureEnabled,
QueryColumn,
QueryResponse,
t,
validateNonEmpty,
} from '@superset-ui/core';
Expand All @@ -39,8 +38,9 @@ import {
ColumnOption,
ColumnMeta,
FilterOption,
temporalColumnMixin,
} from '..';
import { xAxisControlConfig } from './constants';
import { xAxisMixin } from './constants';

type Control = {
savedMetrics?: Metric[] | null;
Expand Down Expand Up @@ -231,6 +231,7 @@ export const dndSecondaryMetricControl: typeof dndAdhocMetricControl = {

export const dndGranularitySqlaControl: typeof dndSeriesControl = {
...dndSeriesControl,
...temporalColumnMixin,
label: TIME_FILTER_LABELS.granularity_sqla,
description: t(
'The time column for the visualization. Note that you ' +
Expand All @@ -247,33 +248,11 @@ export const dndGranularitySqlaControl: typeof dndSeriesControl = {
optionRenderer: (c: ColumnMeta) => <ColumnOption showType column={c} />,
valueRenderer: (c: ColumnMeta) => <ColumnOption column={c} />,
valueKey: 'column_name',
mapStateToProps: ({ datasource }) => {
if (datasource?.columns[0]?.hasOwnProperty('column_name')) {
const temporalColumns =
(datasource as Dataset)?.columns?.filter(c => c.is_dttm) ?? [];
return {
options: temporalColumns,
default:
(datasource as Dataset)?.main_dttm_col ||
temporalColumns[0]?.column_name ||
null,
isTemporal: true,
};
}
const sortedQueryColumns = (datasource as QueryResponse)?.columns?.sort(
query => (query?.is_dttm ? -1 : 1),
);
return {
options: sortedQueryColumns,
default: sortedQueryColumns[0]?.name || null,
isTemporal: true,
};
},
};

export const dndXAxisControl: typeof dndGroupByControl = {
...dndGroupByControl,
...xAxisControlConfig,
...xAxisMixin,
};

export function withDndFallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
import {
buildQueryContext,
DTTM_ALIAS,
ensureIsArray,
getXAxis,
isXAxisSet,
QueryFormData,
} from '@superset-ui/core';
import {
Expand All @@ -29,25 +31,19 @@ import {
} from '@superset-ui/chart-controls';

export default function buildQuery(formData: QueryFormData) {
return buildQueryContext(formData, baseQueryObject => {
const { x_axis } = formData;
const is_timeseries = x_axis === DTTM_ALIAS || !x_axis;

return [
{
...baseQueryObject,
is_timeseries: true,
post_processing: [
pivotOperator(formData, {
...baseQueryObject,
index: x_axis,
is_timeseries,
}),
rollingWindowOperator(formData, baseQueryObject),
resampleOperator(formData, baseQueryObject),
flattenOperator(formData, baseQueryObject),
],
},
];
});
return buildQueryContext(formData, baseQueryObject => [
{
...baseQueryObject,
columns: [
...(isXAxisSet(formData) ? ensureIsArray(getXAxis(formData)) : []),
],
...(isXAxisSet(formData) ? {} : { is_timeseries: true }),
post_processing: [
pivotOperator(formData, baseQueryObject),
rollingWindowOperator(formData, baseQueryObject),
resampleOperator(formData, baseQueryObject),
flattenOperator(formData, baseQueryObject),
],
},
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,40 @@
* specific language governing permissions and limitations
* under the License.
*/
import { smartDateFormatter, t } from '@superset-ui/core';
import {
FeatureFlag,
isFeatureEnabled,
smartDateFormatter,
t,
} from '@superset-ui/core';
import {
ControlPanelConfig,
D3_FORMAT_DOCS,
D3_TIME_FORMAT_OPTIONS,
formatSelectOptions,
getStandardizedControls,
sections,
temporalColumnMixin,
} from '@superset-ui/chart-controls';
import React from 'react';
import { headerFontSize, subheaderFontSize } from '../sharedControls';

const config: ControlPanelConfig = {
controlPanelSections: [
sections.legacyTimeseriesTime,
sections.genericTime,
{
label: t('Query'),
expanded: true,
controlSetRows: [['metric'], ['adhoc_filters']],
controlSetRows: [
[isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) ? 'x_axis' : null],
[
isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)
? 'time_grain_sqla'
: null,
],
['metric'],
['adhoc_filters'],
],
},
{
label: t('Options'),
Expand Down Expand Up @@ -270,6 +285,10 @@ const config: ControlPanelConfig = {
y_axis_format: {
label: t('Number format'),
},
x_axis: {
label: t('TEMPORAL X-AXIS'),
...temporalColumnMixin,
},
},
formDataOverrides: formData => ({
...formData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
* under the License.
*/
import {
DTTM_ALIAS,
extractTimegrain,
getNumberFormatter,
NumberFormats,
QueryFormData,
GenericDataType,
getMetricLabel,
t,
smartDateVerboseFormatter,
NumberFormatter,
TimeFormatter,
getXAxis,
} from '@superset-ui/core';
import { EChartsCoreOption, graphic } from 'echarts';
import {
Expand Down Expand Up @@ -88,7 +87,7 @@ export default function transformProps(
yAxisFormat,
timeRangeFixed,
} = formData;
const granularity = extractTimegrain(rawFormData as QueryFormData);
const granularity = extractTimegrain(rawFormData);
const {
data = [],
colnames = [],
Expand All @@ -103,10 +102,11 @@ export default function transformProps(
const { r, g, b } = colorPicker;
const mainColor = `rgb(${r}, ${g}, ${b})`;

const timeColumn = getXAxis(rawFormData) as string;
let trendLineData;
let percentChange = 0;
let bigNumber = data.length === 0 ? null : data[0][metricName];
let timestamp = data.length === 0 ? null : data[0][DTTM_ALIAS];
let timestamp = data.length === 0 ? null : data[0][timeColumn];
let bigNumberFallback;

const metricColtypeIndex = colnames.findIndex(name => name === metricName);
Expand All @@ -115,7 +115,7 @@ export default function transformProps(

if (data.length > 0) {
const sortedData = (data as BigNumberDatum[])
.map(d => [d[DTTM_ALIAS], parseMetricValue(d[metricName])])
.map(d => [d[timeColumn], parseMetricValue(d[metricName])])
// sort in time descending order
.sort((a, b) => (a[0] !== null && b[0] !== null ? b[0] - a[0] : 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type BigNumberWithTrendlineFormData = BigNumberTotalFormData & {
compareLag?: string | number;
};

export type BigNumberTotalChartProps = ChartProps & {
export type BigNumberTotalChartProps = ChartProps<QueryFormData> & {
formData: BigNumberTotalFormData;
queriesData: (ChartDataResponseResult & {
data?: BigNumberDatum[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ const formData = {
a: 1,
},
compareLag: 1,
timeGrainSqla: 'P3M' as TimeGranularity,
timeGrainSqla: TimeGranularity.QUARTER,
granularitySqla: 'ds',
compareSuffix: 'over last quarter',
viz_type: 'big_number',
yAxisFormat: '.3s',
datasource: 'test_datasource',
};

const rawFormData = {
datasource: '1__table',
metric: 'value',
color_picker: {
r: 0,
Expand All @@ -52,7 +54,8 @@ const rawFormData = {
a: 1,
},
compare_lag: 1,
time_grain_sqla: 'P3M' as TimeGranularity,
time_grain_sqla: TimeGranularity.QUARTER,
granularity_sqla: 'ds',
compare_suffix: 'over last quarter',
viz_type: 'big_number',
y_axis_format: '.3s',
Expand Down
Loading

0 comments on commit 3546c50

Please sign in to comment.