mirror of
https://github.com/grafana/grafana.git
synced 2026-07-03 03:37:53 +00:00
Table: Ensure sparkline renders on refresh (#127206)
* Table: Ensure sparkline renders on refresh * Add test coverage * Fix linter issue
This commit is contained in:
parent
3a112e6762
commit
0c2163d391
2 changed files with 23 additions and 3 deletions
|
|
@ -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', () => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue