mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix: Adds time grain to Pivot Table v2 (#22170)
This commit is contained in:
parent
7e54b88a51
commit
9a2cb431ce
@ -144,6 +144,7 @@ export default function PivotTableChart(props: PivotTableProps) {
|
|||||||
metricColorFormatters,
|
metricColorFormatters,
|
||||||
dateFormatters,
|
dateFormatters,
|
||||||
onContextMenu,
|
onContextMenu,
|
||||||
|
timeGrainSqla,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -375,14 +376,15 @@ export default function PivotTableChart(props: PivotTableProps) {
|
|||||||
if (colKey && colKey.length > 1) {
|
if (colKey && colKey.length > 1) {
|
||||||
colKey.forEach((val, i) => {
|
colKey.forEach((val, i) => {
|
||||||
const col = cols[i];
|
const col = cols[i];
|
||||||
const formattedVal =
|
const formatter = dateFormatters[col];
|
||||||
dateFormatters[col]?.(val as number) || String(val);
|
const formattedVal = formatter?.(val as number) || String(val);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
filters.push({
|
filters.push({
|
||||||
col,
|
col,
|
||||||
op: '==',
|
op: '==',
|
||||||
val,
|
val,
|
||||||
formattedVal,
|
formattedVal,
|
||||||
|
grain: formatter ? timeGrainSqla : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -390,20 +392,21 @@ export default function PivotTableChart(props: PivotTableProps) {
|
|||||||
if (rowKey) {
|
if (rowKey) {
|
||||||
rowKey.forEach((val, i) => {
|
rowKey.forEach((val, i) => {
|
||||||
const col = rows[i];
|
const col = rows[i];
|
||||||
const formattedVal =
|
const formatter = dateFormatters[col];
|
||||||
dateFormatters[col]?.(val as number) || String(val);
|
const formattedVal = formatter?.(val as number) || String(val);
|
||||||
filters.push({
|
filters.push({
|
||||||
col,
|
col,
|
||||||
op: '==',
|
op: '==',
|
||||||
val,
|
val,
|
||||||
formattedVal,
|
formattedVal,
|
||||||
|
grain: formatter ? timeGrainSqla : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onContextMenu(e.clientX, e.clientY, filters);
|
onContextMenu(e.clientX, e.clientY, filters);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[cols, dateFormatters, onContextMenu, rows],
|
[cols, dateFormatters, onContextMenu, rows, timeGrainSqla],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -101,6 +101,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
|
|||||||
emitFilter,
|
emitFilter,
|
||||||
metricsLayout,
|
metricsLayout,
|
||||||
conditionalFormatting,
|
conditionalFormatting,
|
||||||
|
timeGrainSqla,
|
||||||
} = formData;
|
} = formData;
|
||||||
const { selectedFilters } = filterState;
|
const { selectedFilters } = filterState;
|
||||||
const granularity = extractTimegrain(rawFormData);
|
const granularity = extractTimegrain(rawFormData);
|
||||||
@ -165,5 +166,6 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
|
|||||||
metricColorFormatters,
|
metricColorFormatters,
|
||||||
dateFormatters,
|
dateFormatters,
|
||||||
onContextMenu,
|
onContextMenu,
|
||||||
|
timeGrainSqla,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
QueryFormMetric,
|
QueryFormMetric,
|
||||||
QueryFormColumn,
|
QueryFormColumn,
|
||||||
BinaryQueryObjectFilterClause,
|
BinaryQueryObjectFilterClause,
|
||||||
|
TimeGranularity,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { ColorFormatters } from '@superset-ui/chart-controls';
|
import { ColorFormatters } from '@superset-ui/chart-controls';
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ interface PivotTableCustomizeProps {
|
|||||||
clientY: number,
|
clientY: number,
|
||||||
filters?: BinaryQueryObjectFilterClause[],
|
filters?: BinaryQueryObjectFilterClause[],
|
||||||
) => void;
|
) => void;
|
||||||
|
timeGrainSqla?: TimeGranularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PivotTableQueryFormData = QueryFormData &
|
export type PivotTableQueryFormData = QueryFormData &
|
||||||
|
Loading…
Reference in New Issue
Block a user