Skip to content

Commit

Permalink
fix modal legend issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkikapadia committed Sep 27, 2024
1 parent c552716 commit 0afb7e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
29 changes: 7 additions & 22 deletions static/app/components/modals/widgetViewerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ const shouldWidgetCardChartMemo = (prevProps, props) => {
);
const isNotTopNWidget =
props.widget.displayType !== DisplayType.TOP_N && !defined(props.widget.limit);
return selectionMatches && chartZoomOptionsMatches && (sortMatches || isNotTopNWidget);
const legendMatches = isEqual(props.legendOptions, prevProps.legendOptions);
return (
selectionMatches &&
chartZoomOptionsMatches &&
(sortMatches || isNotTopNWidget) &&
legendMatches
);
};

// WidgetCardChartContainer and WidgetCardChart rerenders if selection was changed.
Expand Down Expand Up @@ -221,27 +227,6 @@ function WidgetViewerModal(props: Props) {
useState<PageFilters>(locationPageFilter);
const modalChartSelection = useRef(modalTableSelection);

useEffect(() => {
// have the query legend values update
const legendData = seriesData?.reduce((prevSeries, series) => {
prevSeries[series.seriesName] = series.seriesName === 'Releases' ? false : true;
return prevSeries;
}, {});

const definedLegendData = legendData ? legendData : {};

router.replace({
pathname: location.pathname,
query: {
...location.query,
[WidgetViewerQueryField.LEGEND]: Object.keys(definedLegendData).filter(
key => definedLegendData[key]
),
},
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

// Detect when a user clicks back and set the PageFilter state to match the location
// We need to use useEffect to prevent infinite looping rerenders due to the setModalTableSelection call
useEffect(() => {
Expand Down
3 changes: 1 addition & 2 deletions static/app/views/dashboards/widgetCard/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ class WidgetCardChart extends Component<WidgetCardChartProps> {
memoized
>
{({releaseSeries}) => {
location.query.unselectedSeries = 'Releases';
legend.selected = getSeriesSelection(location);
legend.selected = {Releases: false, ...legend.selected};

return (
<TransitionChart loading={loading} reloading={loading}>
Expand Down

0 comments on commit 0afb7e1

Please sign in to comment.