Skip to content

Commit

Permalink
fix(plugins): Fix dashboard filter for Table and Big Number with Time…
Browse files Browse the repository at this point in the history
… Comparison (#29517)
  • Loading branch information
Antonio-RiveroMartnez authored and pull[bot] committed Dec 13, 2024
1 parent 36f733c commit db2eb64
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function PopKPI(props: PopKPIProps) {
currentTimeRangeFilter,
startDateOffset,
shift,
dashboardTimeRange,
} = props;

const [comparisonRange, setComparisonRange] = useState<string>('');
Expand All @@ -90,12 +91,16 @@ export default function PopKPI(props: PopKPIProps) {
setComparisonRange('');
} else if (!isEmpty(shift) || startDateOffset) {
const newShift = getTimeOffset({
timeRangeFilter: currentTimeRangeFilter,
timeRangeFilter: {
...currentTimeRangeFilter,
comparator:
dashboardTimeRange ?? (currentTimeRangeFilter as any).comparator,
},
shifts: ensureIsArray(shift),
startDate: startDateOffset || '',
});
const promise: any = fetchTimeRange(
(currentTimeRangeFilter as any).comparator,
dashboardTimeRange ?? (currentTimeRangeFilter as any).comparator,
currentTimeRangeFilter.subject,
newShift || [],
);
Expand All @@ -108,7 +113,7 @@ export default function PopKPI(props: PopKPIProps) {
);
});
}
}, [currentTimeRangeFilter, shift, startDateOffset]);
}, [currentTimeRangeFilter, shift, startDateOffset, dashboardTimeRange]);

const theme = useTheme();
const flexGap = theme.gridUnit * 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export default function buildQuery(formData: QueryFormData) {
const timeOffsets = ensureIsArray(
isTimeComparison(formData, baseQueryObject)
? getTimeOffset({
timeRangeFilter: TimeRangeFilters[0],
timeRangeFilter: {
...TimeRangeFilters[0],
comparator:
baseQueryObject?.time_range ??
(TimeRangeFilters[0] as any)?.comparator,
},
shifts: formData.time_compare,
startDate:
previousCustomStartDate && !formData.start_date_offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ export default function transformProps(chartProps: ChartProps) {
let dataOffset: string[] = [];
if (isCustomOrInherit) {
dataOffset = getTimeOffset({
timeRangeFilter: currentTimeRangeFilter,
timeRangeFilter: {
...currentTimeRangeFilter,
comparator:
formData?.extra_form_data?.time_range ??
(currentTimeRangeFilter as any)?.comparator,
},
shifts: ensureIsArray(timeComparison),
startDate:
previousCustomStartDate && !startDateOffset
Expand Down Expand Up @@ -207,5 +212,6 @@ export default function transformProps(chartProps: ChartProps) {
currentTimeRangeFilter,
startDateOffset,
shift: timeComparison,
dashboardTimeRange: formData?.extraFormData?.time_range,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type PopKPIProps = PopKPIStylesProps &
currentTimeRangeFilter?: SimpleAdhocFilter;
startDateOffset?: string;
shift: string;
dashboardTimeRange?: string;
};

export enum ColorSchemeEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ const buildQuery: BuildQuery<TableChartFormData> = (
const timeOffsets = ensureIsArray(
isTimeComparison(formData, baseQueryObject)
? getTimeOffset({
timeRangeFilter: TimeRangeFilters[0],
timeRangeFilter: {
...TimeRangeFilters[0],
comparator:
baseQueryObject?.time_range ??
(TimeRangeFilters[0] as any)?.comparator,
},
shifts: formData.time_compare,
startDate:
previousCustomStartDate && !formData.start_date_offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,12 @@ const transformProps = (
}

const timeOffsets = getTimeOffset({
timeRangeFilter: TimeRangeFilters[0],
timeRangeFilter: {
...TimeRangeFilters[0],
comparator:
formData?.extra_form_data?.time_range ??
(TimeRangeFilters[0] as any)?.comparator,
},
shifts: formData.time_compare,
startDate:
previousCustomStartDate && !formData.start_date_offset
Expand Down
5 changes: 3 additions & 2 deletions superset/common/query_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,9 @@ def join_offset_dfs(

if time_grain:
# move the temporal column to the first column in df
col = df.pop(join_keys[0])
df.insert(0, col.name, col)
if join_keys:
col = df.pop(join_keys[0])
df.insert(0, col.name, col)

# removes columns created only for join purposes
df.drop(
Expand Down

0 comments on commit db2eb64

Please sign in to comment.