Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adds time grain to Pivot Table v2 #22170

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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