Skip to content

Commit

Permalink
fix: Adds time grain to Pivot Table v2 (#22170)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Nov 20, 2022
1 parent 7e54b88 commit 9a2cb43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export default function PivotTableChart(props: PivotTableProps) {
metricColorFormatters,
dateFormatters,
onContextMenu,
timeGrainSqla,
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -375,35 +376,37 @@ export default function PivotTableChart(props: PivotTableProps) {
if (colKey && colKey.length > 1) {
colKey.forEach((val, i) => {
const col = cols[i];
const formattedVal =
dateFormatters[col]?.(val as number) || String(val);
const formatter = dateFormatters[col];
const formattedVal = formatter?.(val as number) || String(val);
if (i > 0) {
filters.push({
col,
op: '==',
val,
formattedVal,
grain: formatter ? timeGrainSqla : undefined,
});
}
});
}
if (rowKey) {
rowKey.forEach((val, i) => {
const col = rows[i];
const formattedVal =
dateFormatters[col]?.(val as number) || String(val);
const formatter = dateFormatters[col];
const formattedVal = formatter?.(val as number) || String(val);
filters.push({
col,
op: '==',
val,
formattedVal,
grain: formatter ? timeGrainSqla : undefined,
});
});
}
onContextMenu(e.clientX, e.clientY, filters);
}
},
[cols, dateFormatters, onContextMenu, rows],
[cols, dateFormatters, onContextMenu, rows, timeGrainSqla],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
emitFilter,
metricsLayout,
conditionalFormatting,
timeGrainSqla,
} = formData;
const { selectedFilters } = filterState;
const granularity = extractTimegrain(rawFormData);
Expand Down Expand Up @@ -165,5 +166,6 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
metricColorFormatters,
dateFormatters,
onContextMenu,
timeGrainSqla,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
QueryFormMetric,
QueryFormColumn,
BinaryQueryObjectFilterClause,
TimeGranularity,
} from '@superset-ui/core';
import { ColorFormatters } from '@superset-ui/chart-controls';

Expand Down Expand Up @@ -78,6 +79,7 @@ interface PivotTableCustomizeProps {
clientY: number,
filters?: BinaryQueryObjectFilterClause[],
) => void;
timeGrainSqla?: TimeGranularity;
}

export type PivotTableQueryFormData = QueryFormData &
Expand Down

0 comments on commit 9a2cb43

Please sign in to comment.