Skip to content

Commit 4cd33ca

Browse files
authored
Fix image by step plots breaking on nonexistent steps (#4478)
1 parent 66530c1 commit 4cd33ca

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

webview/src/plots/components/App.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,50 @@ describe('App', () => {
17881788

17891789
expect(multiImgRow.draggable).toBe(true)
17901790
})
1791+
1792+
it('should handle when a revision contains less images than before', () => {
1793+
renderAppWithOptionalData({
1794+
comparison: comparisonTableFixture
1795+
})
1796+
1797+
const mainImgs = comparisonTableFixture.plots[3].revisions.main.imgs
1798+
1799+
const multiImgPlots = screen.getAllByTestId('multi-image-cell')
1800+
const slider = within(multiImgPlots[1]).getByRole('slider')
1801+
1802+
fireEvent.change(slider, { target: { value: 14 } })
1803+
1804+
expect(within(multiImgPlots[1]).getByRole('img')).toHaveAttribute(
1805+
'src',
1806+
mainImgs[14].url
1807+
)
1808+
1809+
const dataWithLessMainImages = {
1810+
comparison: {
1811+
...comparisonTableFixture,
1812+
plots: comparisonTableFixture.plots.map(plot =>
1813+
plot.path.includes('image')
1814+
? {
1815+
...plot,
1816+
revisions: {
1817+
...plot.revisions,
1818+
main: {
1819+
...plot.revisions.main,
1820+
imgs: plot.revisions.main.imgs.slice(0, 7)
1821+
}
1822+
}
1823+
}
1824+
: plot
1825+
)
1826+
}
1827+
}
1828+
1829+
sendSetDataMessage(dataWithLessMainImages)
1830+
1831+
expect(
1832+
within(multiImgPlots[1]).queryByRole('img')
1833+
).not.toBeInTheDocument()
1834+
})
17911835
})
17921836

17931837
describe('Virtualization', () => {

webview/src/plots/components/comparisonTable/cell/ComparisonTableMultiCell.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ export const ComparisonTableMultiCell: React.FC<{
2424
<div data-testid="multi-image-cell" className={styles.multiImageWrapper}>
2525
<ComparisonTableCell
2626
path={path}
27-
plot={{ id: plot.id, imgs: [plot.imgs[currentStep]] }}
27+
plot={{
28+
id: plot.id,
29+
imgs: [
30+
plot.imgs[currentStep] || {
31+
errors: undefined,
32+
loading: false,
33+
url: undefined
34+
}
35+
]
36+
}}
2837
imgAlt={`${currentStep} of ${path} (${plot.id})`}
2938
/>
3039
<div

0 commit comments

Comments
 (0)