fix(dashboard): chart doesn't resize when tab switch (#22009)

This commit is contained in:
Stephen Liu 2022-12-01 21:38:23 +08:00 committed by GitHub
parent ead2834a77
commit 309c064cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import {
getChartAliasBySpec, getChartAliasBySpec,
} from 'cypress/utils'; } from 'cypress/utils';
import { TABBED_DASHBOARD } from 'cypress/utils/urls'; import { TABBED_DASHBOARD } from 'cypress/utils/urls';
import { expandFilterOnLeftPanel } from './utils';
const TREEMAP = { name: 'Treemap', viz: 'treemap' }; const TREEMAP = { name: 'Treemap', viz: 'treemap' };
const FILTER_BOX = { name: 'Region Filter', viz: 'filter_box' }; const FILTER_BOX = { name: 'Region Filter', viz: 'filter_box' };
@ -91,6 +92,7 @@ describe('Dashboard tabs', () => {
cy.get('@row-level-tabs').last().click(); cy.get('@row-level-tabs').last().click();
waitForChartLoad(LINE_CHART); waitForChartLoad(LINE_CHART);
cy.getBySel('grid-container').find('.line').should('be.visible'); cy.getBySel('grid-container').find('.line').should('be.visible');
cy.get('@row-level-tabs').first().click();
}); });
it.skip('should send new queries when tab becomes visible', () => { it.skip('should send new queries when tab becomes visible', () => {
@ -166,4 +168,30 @@ describe('Dashboard tabs', () => {
}); });
}); });
}); });
it('should update size when switch tab', () => {
cy.get('@top-level-tabs')
.last()
.click()
.should('have.class', 'ant-tabs-tab-active');
expandFilterOnLeftPanel();
cy.wait(1000);
cy.get('@top-level-tabs')
.first()
.click()
.should('have.class', 'ant-tabs-tab-active');
cy.wait(1000);
cy.get("[data-test-viz-type='treemap'] .chart-container").then(
$chartContainer => {
expect($chartContainer.get(0).scrollWidth).eq(
$chartContainer.get(0).offsetWidth,
);
},
);
});
}); });

View File

@ -190,7 +190,9 @@ class Chart extends React.Component {
if ( if (
nextProps.width !== this.props.width || nextProps.width !== this.props.width ||
nextProps.height !== this.props.height nextProps.height !== this.props.height ||
nextProps.width !== this.state.width ||
nextProps.height !== this.state.height
) { ) {
clearTimeout(this.resizeTimeout); clearTimeout(this.resizeTimeout);
this.resizeTimeout = setTimeout(this.resize, RESIZE_TIMEOUT); this.resizeTimeout = setTimeout(this.resize, RESIZE_TIMEOUT);