Skip to content

Commit

Permalink
fix(dashboard): chart doesn't resize when tab switch (#22009)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ authored Dec 1, 2022
1 parent ead2834 commit 309c064
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getChartAliasBySpec,
} from 'cypress/utils';
import { TABBED_DASHBOARD } from 'cypress/utils/urls';
import { expandFilterOnLeftPanel } from './utils';

const TREEMAP = { name: 'Treemap', viz: 'treemap' };
const FILTER_BOX = { name: 'Region Filter', viz: 'filter_box' };
Expand Down Expand Up @@ -91,6 +92,7 @@ describe('Dashboard tabs', () => {
cy.get('@row-level-tabs').last().click();
waitForChartLoad(LINE_CHART);
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', () => {
Expand Down Expand Up @@ -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,
);
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class Chart extends React.Component {

if (
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);
this.resizeTimeout = setTimeout(this.resize, RESIZE_TIMEOUT);
Expand Down

0 comments on commit 309c064

Please sign in to comment.