bito-code-review[bot] commented on PR #42563:
URL: https://github.com/apache/superset/pull/42563#issuecomment-5117019345
<!-- Bito Reply -->
The flagged issue is correct. Because `chartId` is included in the
`useEffect` dependency array, the logging effect will re-run whenever `chartId`
changes, even if the modal remains open, leading to duplicate analytics events.
To resolve this, you should track the previous `showModal` state using a
`useRef` hook and only trigger the log event when `showModal` transitions from
`false` to `true`.
Here is the corrected implementation for
`superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.tsx`:
```tsx
const prevShowModal = useRef(showModal);
useEffect(() => {
if (showModal && !prevShowModal.current) {
dispatch(
logEvent(LOG_ACTIONS_DRILL_TO_DETAIL_MODAL_OPENED, {
slice_id: chartId,
}),
);
}
prevShowModal.current = showModal;
}, [dispatch, showModal, chartId]);
```
Would you like me to fetch all other comments on this PR to validate and
implement fixes for them as well?
**superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.tsx**
```
const prevShowModal = useRef(showModal);
useEffect(() => {
if (showModal && !prevShowModal.current) {
dispatch(
logEvent(LOG_ACTIONS_DRILL_TO_DETAIL_MODAL_OPENED, {
slice_id: chartId,
}),
);
}
prevShowModal.current = showModal;
}, [dispatch, showModal, chartId]);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]