Table: Ensure sparkline renders on refresh (#127206)

* Table: Ensure sparkline renders on refresh

* Add test coverage

* Fix linter issue
This commit is contained in:
Drew Slobodnjak 2026-07-01 10:36:00 -07:00 committed by GitHub
parent 3a112e6762
commit 0c2163d391
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -110,6 +110,23 @@ describe('UPlotChart', () => {
expect(setDataMock).toBeCalledTimes(1);
});
it('updates uPlot data when dimensions also change', () => {
const { data, config } = mockData();
const { rerender } = render(
<UPlotChart data={preparePlotData2(data, getStackingGroups(data))} config={config} width={100} height={100} />
);
data.fields[1].values[0] = 1;
rerender(
<UPlotChart data={preparePlotData2(data, getStackingGroups(data))} config={config} width={200} height={200} />
);
expect(setDataMock).toBeCalledTimes(1);
expect(setSizeMock).toBeCalledTimes(1);
});
});
describe('config update', () => {

View file

@ -78,14 +78,17 @@ export class UPlotChart extends Component<PlotProps, UPlotChartState> {
}
componentDidUpdate(prevProps: PlotProps) {
if (!sameConfig(prevProps, this.props)) {
this.reinitPlot();
return;
}
if (!sameDims(prevProps, this.props)) {
this.plotInstance?.setSize({
width: Math.floor(this.props.width),
height: Math.floor(this.props.height),
});
} else if (!sameConfig(prevProps, this.props)) {
this.reinitPlot();
} else if (!sameData(prevProps, this.props)) {
}
if (!sameData(prevProps, this.props)) {
this.plotInstance?.setData(this.props.data as AlignedData);
}
}