fix(dashboard): ensure charts re-render when visibility state changes (#36011)

This commit is contained in:
Richard Fogaca Nienkotter
2025-11-19 10:26:34 -03:00
committed by GitHub
parent 21f85a4145
commit 4582f0e8d2
2 changed files with 33 additions and 2 deletions

View File

@@ -621,8 +621,9 @@ export default memo(Chart, (prevProps, nextProps) => {
}
return (
!nextProps.isComponentVisible ||
(prevProps.isInView === nextProps.isInView &&
prevProps.componentId === nextProps.componentId &&
(prevProps.componentId === nextProps.componentId &&
prevProps.isComponentVisible &&
prevProps.isInView === nextProps.isInView &&
prevProps.id === nextProps.id &&
prevProps.dashboardId === nextProps.dashboardId &&
prevProps.extraControls === nextProps.extraControls &&

View File

@@ -267,3 +267,33 @@ test('should call exportChart with row_limit props.maxRows when exportFullXLSX i
stubbedExportXLSX.mockRestore();
});
test('should re-render when chart becomes visible', () => {
const { rerender, getByTestId } = setup({ isComponentVisible: false });
expect(getByTestId('chart-container')).toBeInTheDocument();
rerender(<Chart {...props} isComponentVisible />);
expect(getByTestId('chart-container')).toBeInTheDocument();
});
test('should re-render when componentId changes', () => {
const { rerender, getByTestId } = setup({
isComponentVisible: true,
componentId: 'test-1',
});
expect(getByTestId('chart-container')).toBeInTheDocument();
rerender(<Chart {...props} isComponentVisible componentId="test-2" />);
expect(getByTestId('chart-container')).toBeInTheDocument();
});
test('should re-render when cacheBusterProp changes', () => {
const { rerender, getByTestId } = setup({
isComponentVisible: true,
cacheBusterProp: 'v1',
});
expect(getByTestId('chart-container')).toBeInTheDocument();
rerender(<Chart {...props} isComponentVisible cacheBusterProp="v2" />);
expect(getByTestId('chart-container')).toBeInTheDocument();
});