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

feat: Adds drill to detail context menu to Pivot Table #21198

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -118,7 +118,7 @@ function WorldMap(element, props) {
formattedVal,
},
];
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
};

const map = new Datamap({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type BigNumberVisProps = {
echartOptions: EChartsCoreOption;
onContextMenu?: (
filters: QueryObjectFilterClause[],
offsetX: number,
offsetY: number,
clientX: number,
clientY: number,
) => void;
xValueFormatter?: TimeFormatter;
formData?: BigNumberWithTrendlineFormData;
Expand Down Expand Up @@ -173,8 +173,8 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
e.preventDefault();
this.props.onContextMenu(
[],
e.nativeEvent.offsetX,
e.nativeEvent.offsetY,
e.nativeEvent.clientX,
e.nativeEvent.clientY,
);
}
};
Expand Down Expand Up @@ -234,7 +234,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
return null;
}

renderTrendline(maxHeight: number, chartHeight: number) {
renderTrendline(maxHeight: number) {
const { width, trendLineData, echartOptions } = this.props;

// if can't find any non-null values, no point rendering the trendline
Expand All @@ -259,8 +259,8 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
});
this.props.onContextMenu(
filters,
pointerEvent.offsetX,
chartHeight - 100,
pointerEvent.clientX,
pointerEvent.clientY,
);
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ class BigNumberVis extends React.PureComponent<BigNumberVisProps> {
),
)}
</div>
{this.renderTrendline(chartHeight, height)}
{this.renderTrendline(chartHeight)}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function EchartsGraph({
formattedVal: targetValue,
},
];
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type GraphChartTransformedProps = EchartsProps & {
formData: PlainObject;
onContextMenu?: (
filters: QueryObjectFilterClause[],
offsetX: number,
offsetY: number,
clientX: number,
clientY: number,
) => void;
};
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default function EchartsMixedTimeseries({
formattedVal: String(values[i]),
}),
);
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default function EchartsTimeseries({
formattedVal: String(values[i]),
}),
);
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { QueryObjectFilterClause } from '@superset-ui/core';
import { DataRecordValue, QueryObjectFilterClause } from '@superset-ui/core';
import React, { useCallback } from 'react';
import Echart from '../components/Echart';
import { EventHandlers } from '../types';
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function EchartsTreemap({
values.length === 0
? []
: groupby.map((col, idx) => {
const val = groupbyValues.map(v => v[idx]);
const val: DataRecordValue[] = groupbyValues.map(v => v[idx]);
if (val === null || val === undefined)
return {
col,
Expand Down Expand Up @@ -101,7 +101,7 @@ export default function EchartsTreemap({
formattedVal: path,
}),
);
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/plugins/plugin-chart-echarts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export interface EChartTransformedProps<F> {
legendData?: OptionName[];
onContextMenu?: (
filters: QueryObjectFilterClause[],
offsetX: number,
offsetY: number,
clientX: number,
clientY: number,
) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const contextMenuEventHandler =
}),
);
}
onContextMenu(filters, pointerEvent.offsetX, pointerEvent.offsetY);
onContextMenu(filters, pointerEvent.clientX, pointerEvent.clientY);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
styled,
useTheme,
isAdhocColumn,
QueryObjectFilterClause,
} from '@superset-ui/core';
import { PivotTable, sortAs, aggregatorTemplates } from './react-pivottable';
import {
Expand Down Expand Up @@ -142,6 +143,7 @@ export default function PivotTableChart(props: PivotTableProps) {
metricsLayout,
metricColorFormatters,
dateFormatters,
onContextMenu,
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -360,6 +362,46 @@ export default function PivotTableChart(props: PivotTableProps) {
[colSubtotalPosition, rowSubtotalPosition],
);

const handleContextMenu = (
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
e: MouseEvent,
colKey: DataRecordValue[] | undefined,
rowKey: DataRecordValue[] | undefined,
) => {
if (onContextMenu) {
e.preventDefault();
const filters: QueryObjectFilterClause[] = [];
if (colKey && colKey.length > 1) {
colKey.forEach((val, i) => {
const col = cols[i];
const formattedVal =
dateFormatters[col]?.(val as number) || String(val);
if (i > 0) {
filters.push({
col,
op: '==',
val,
formattedVal,
});
}
});
}
if (rowKey) {
rowKey.forEach((val, i) => {
const col = rows[i];
const formattedVal =
dateFormatters[col]?.(val as number) || String(val);
filters.push({
col,
op: '==',
val,
formattedVal,
});
});
}
onContextMenu(filters, e.clientX, e.clientY);
}
};

return (
<Styles height={height} width={width} margin={theme.gridUnit * 4}>
<PivotTableWrapper>
Expand All @@ -378,6 +420,7 @@ export default function PivotTableChart(props: PivotTableProps) {
tableOptions={tableOptions}
subtotalOptions={subtotalOptions}
namesMapping={verboseMap}
onContextMenu={handleContextMenu}
/>
</PivotTableWrapper>
</Styles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
queriesData,
formData,
rawFormData,
hooks: { setDataMask = () => {} },
hooks: { setDataMask = () => {}, onContextMenu },
filterState,
datasource: { verboseMap = {}, columnFormats = {} },
} = chartProps;
Expand Down Expand Up @@ -164,5 +164,6 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
metricsLayout,
metricColorFormatters,
dateFormatters,
onContextMenu,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import React from 'react';
import { PivotData } from './utilities';
import { TableRenderer } from './TableRenderers';

class PivotTable extends React.PureComponent {
Expand All @@ -27,7 +26,7 @@ class PivotTable extends React.PureComponent {
}
}

PivotTable.propTypes = PivotData.propTypes;
PivotTable.defaultProps = PivotData.defaultProps;
PivotTable.propTypes = TableRenderer.propTypes;
PivotTable.defaultProps = TableRenderer.defaultProps;

export default PivotTable;
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ export class TableRenderer extends React.Component {
className="pvtVal"
key={`pvtVal-${flatColKey}`}
onClick={rowClickHandlers[flatColKey]}
onContextMenu={e => this.props.onContextMenu(e, colKey, rowKey)}
style={style}
>
{agg.format(aggValue)}
Expand All @@ -717,6 +718,7 @@ export class TableRenderer extends React.Component {
key="total"
className="pvtTotal"
onClick={rowTotalCallbacks[flatRowKey]}
onContextMenu={e => this.props.onContextMenu(e, undefined, rowKey)}
>
{agg.format(aggValue)}
</td>
Expand Down Expand Up @@ -776,6 +778,7 @@ export class TableRenderer extends React.Component {
className="pvtTotal pvtRowTotal"
key={`total-${flatColKey}`}
onClick={colTotalCallbacks[flatColKey]}
onContextMenu={e => this.props.onContextMenu(e, colKey, undefined)}
style={{ padding: '5px' }}
>
{agg.format(aggValue)}
Expand All @@ -793,6 +796,7 @@ export class TableRenderer extends React.Component {
key="total"
className="pvtGrandTotal pvtRowTotal"
onClick={grandTotalCallback}
onContextMenu={e => this.props.onContextMenu(e, undefined, undefined)}
>
{agg.format(aggValue)}
</td>
Expand Down Expand Up @@ -886,5 +890,6 @@ export class TableRenderer extends React.Component {
TableRenderer.propTypes = {
...PivotData.propTypes,
tableOptions: PropTypes.object,
onContextMenu: PropTypes.func,
};
TableRenderer.defaultProps = { ...PivotData.defaultProps, tableOptions: {} };
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NumberFormatter,
QueryFormMetric,
QueryFormColumn,
QueryObjectFilterClause,
} from '@superset-ui/core';
import { ColorFormatters } from '@superset-ui/chart-controls';

Expand Down Expand Up @@ -72,6 +73,11 @@ interface PivotTableCustomizeProps {
dateFormatters: Record<string, DateFormatter | undefined>;
legacy_order_by: QueryFormMetric[] | QueryFormMetric | null;
order_desc: boolean;
onContextMenu?: (
filters: QueryObjectFilterClause[],
clientX: number,
clientY: number,
) => void;
}

export type PivotTableQueryFormData = QueryFormData &
Expand Down
22 changes: 12 additions & 10 deletions superset-frontend/src/components/Chart/ChartContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface ChartContextMenuProps {
export interface Ref {
open: (
filters: QueryObjectFilterClause[],
offsetX: number,
offsetY: number,
clientX: number,
clientY: number,
) => void;
}

Expand All @@ -54,9 +54,9 @@ const ChartContextMenu = (
) => {
const [state, setState] = useState<{
filters: QueryObjectFilterClause[];
offsetX: number;
offsetY: number;
}>({ filters: [], offsetX: 0, offsetY: 0 });
clientX: number;
clientY: number;
}>({ filters: [], clientX: 0, clientY: 0 });

const menu = (
<Menu>
Expand All @@ -81,8 +81,8 @@ const ChartContextMenu = (
);

const open = useCallback(
(filters: QueryObjectFilterClause[], offsetX: number, offsetY: number) => {
setState({ filters, offsetX, offsetY });
(filters: QueryObjectFilterClause[], clientX: number, clientY: number) => {
setState({ filters, clientX, clientY });

// Since Ant Design's Dropdown does not offer an imperative API
// and we can't attach event triggers to charts SVG elements, we
Expand Down Expand Up @@ -111,9 +111,11 @@ const ChartContextMenu = (
id={`hidden-span-${id}`}
css={{
visibility: 'hidden',
position: 'absolute',
top: state.offsetY,
left: state.offsetX,
position: 'fixed',
top: state.clientY,
left: state.clientX,
width: 1,
height: 1,
}}
/>
</Dropdown>
Expand Down