Skip to content

Commit

Permalink
Adds useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Aug 25, 2022
1 parent d5ebf31 commit 66335dd
Showing 1 changed file with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,45 +362,48 @@ export default function PivotTableChart(props: PivotTableProps) {
[colSubtotalPosition, rowSubtotalPosition],
);

const handleContextMenu = (
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) {
const handleContextMenu = useCallback(
(
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,
});
}
});
}
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);
}
onContextMenu(filters, e.clientX, e.clientY);
}
};
},
[cols, dateFormatters, onContextMenu, rows],
);

return (
<Styles height={height} width={width} margin={theme.gridUnit * 4}>
Expand Down

0 comments on commit 66335dd

Please sign in to comment.