mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(table): Table with Time Comparison (#28057)
Co-authored-by: Lily Kuang <lily@preset.io> Co-authored-by: lilykuang <jialikuang@gmail.com> Co-authored-by: Kamil Gabryjelski <kamil.gabryjelski@gmail.com>
This commit is contained in:
@@ -89,11 +89,11 @@ export default function PopKPI(props: PopKPIProps) {
|
||||
if (!currentTimeRangeFilter || (!shift && !startDateOffset)) {
|
||||
setComparisonRange('');
|
||||
} else if (!isEmpty(shift) || startDateOffset) {
|
||||
const newShift = getTimeOffset(
|
||||
currentTimeRangeFilter,
|
||||
ensureIsArray(shift),
|
||||
startDateOffset || '',
|
||||
);
|
||||
const newShift = getTimeOffset({
|
||||
timeRangeFilter: currentTimeRangeFilter,
|
||||
shifts: ensureIsArray(shift),
|
||||
startDate: startDateOffset || '',
|
||||
});
|
||||
const promise: any = fetchTimeRange(
|
||||
(currentTimeRangeFilter as any).comparator,
|
||||
currentTimeRangeFilter.subject,
|
||||
|
||||
@@ -23,11 +23,13 @@ import {
|
||||
ensureIsArray,
|
||||
SimpleAdhocFilter,
|
||||
getTimeOffset,
|
||||
parseDttmToDate,
|
||||
} from '@superset-ui/core';
|
||||
import {
|
||||
isTimeComparison,
|
||||
timeCompareOperator,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
export default function buildQuery(formData: QueryFormData) {
|
||||
const { cols: groupby } = formData;
|
||||
@@ -40,13 +42,31 @@ export default function buildQuery(formData: QueryFormData) {
|
||||
(filter: SimpleAdhocFilter) => filter.operator === 'TEMPORAL_RANGE',
|
||||
) || [];
|
||||
|
||||
// In case the viz is using all version of controls, we try to load them
|
||||
const previousCustomTimeRangeFilters: any =
|
||||
formData.adhoc_custom?.filter(
|
||||
(filter: SimpleAdhocFilter) => filter.operator === 'TEMPORAL_RANGE',
|
||||
) || [];
|
||||
|
||||
let previousCustomStartDate = '';
|
||||
if (
|
||||
!isEmpty(previousCustomTimeRangeFilters) &&
|
||||
previousCustomTimeRangeFilters[0]?.comparator !== 'No Filter'
|
||||
) {
|
||||
previousCustomStartDate =
|
||||
previousCustomTimeRangeFilters[0]?.comparator.split(' : ')[0];
|
||||
}
|
||||
|
||||
const timeOffsets = ensureIsArray(
|
||||
isTimeComparison(formData, baseQueryObject)
|
||||
? getTimeOffset(
|
||||
TimeRangeFilters[0],
|
||||
formData.time_compare,
|
||||
formData.start_date_offset,
|
||||
)
|
||||
? getTimeOffset({
|
||||
timeRangeFilter: TimeRangeFilters[0],
|
||||
shifts: formData.time_compare,
|
||||
startDate:
|
||||
previousCustomStartDate && !formData.start_date_offset
|
||||
? parseDttmToDate(previousCustomStartDate)?.toUTCString()
|
||||
: formData.start_date_offset,
|
||||
})
|
||||
: [],
|
||||
);
|
||||
return [
|
||||
|
||||
@@ -25,7 +25,9 @@ import {
|
||||
SimpleAdhocFilter,
|
||||
ensureIsArray,
|
||||
getTimeOffset,
|
||||
parseDttmToDate,
|
||||
} from '@superset-ui/core';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { getComparisonFontSize, getHeaderFontSize } from './utils';
|
||||
|
||||
export const parseMetricValue = (metricValue: number | string | null) => {
|
||||
@@ -90,22 +92,39 @@ export default function transformProps(chartProps: ChartProps) {
|
||||
} = formData;
|
||||
const { data: dataA = [] } = queriesData[0];
|
||||
const data = dataA;
|
||||
const metricName = getMetricLabel(metric);
|
||||
const metricName = metric ? getMetricLabel(metric) : '';
|
||||
const timeComparison = ensureIsArray(chartProps.rawFormData?.time_compare)[0];
|
||||
const startDateOffset = chartProps.rawFormData?.start_date_offset;
|
||||
const currentTimeRangeFilter = chartProps.rawFormData?.adhoc_filters?.filter(
|
||||
(adhoc_filter: SimpleAdhocFilter) =>
|
||||
adhoc_filter.operator === 'TEMPORAL_RANGE',
|
||||
)?.[0];
|
||||
// In case the viz is using all version of controls, we try to load them
|
||||
const previousCustomTimeRangeFilters: any =
|
||||
chartProps.rawFormData?.adhoc_custom?.filter(
|
||||
(filter: SimpleAdhocFilter) => filter.operator === 'TEMPORAL_RANGE',
|
||||
) || [];
|
||||
|
||||
let previousCustomStartDate = '';
|
||||
if (
|
||||
!isEmpty(previousCustomTimeRangeFilters) &&
|
||||
previousCustomTimeRangeFilters[0]?.comparator !== 'No Filter'
|
||||
) {
|
||||
previousCustomStartDate =
|
||||
previousCustomTimeRangeFilters[0]?.comparator.split(' : ')[0];
|
||||
}
|
||||
const isCustomOrInherit =
|
||||
timeComparison === 'custom' || timeComparison === 'inherit';
|
||||
let dataOffset: string[] = [];
|
||||
if (isCustomOrInherit) {
|
||||
dataOffset = getTimeOffset(
|
||||
currentTimeRangeFilter,
|
||||
ensureIsArray(timeComparison),
|
||||
startDateOffset || '',
|
||||
);
|
||||
dataOffset = getTimeOffset({
|
||||
timeRangeFilter: currentTimeRangeFilter,
|
||||
shifts: ensureIsArray(timeComparison),
|
||||
startDate:
|
||||
previousCustomStartDate && !startDateOffset
|
||||
? parseDttmToDate(previousCustomStartDate)?.toUTCString()
|
||||
: startDateOffset,
|
||||
});
|
||||
}
|
||||
|
||||
const { value1, value2 } = data.reduce(
|
||||
|
||||
Reference in New Issue
Block a user