Skip to content

Commit

Permalink
Handle missing items in drag and drop container (#5054)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephanie Roy <sroy3@users.noreply.github.com>
  • Loading branch information
mattseddon and sroy3 authored Dec 1, 2023
1 parent 30e3653 commit 1d4d856
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,25 @@ describe('ComparisonTable', () => {
expect(aHeader.style.top).not.toBe('')
})

it('should not throw an error when an image is removed from the data', () => {
const { rerender } = renderTable()

const plotsWithMissingImage = comparisonTableFixture.plots.slice(1)
expect(plotsWithMissingImage.length).toStrictEqual(
comparisonTableFixture.plots.length - 1
)

expect(() =>
renderTable(
{
...comparisonTableFixture,
plots: plotsWithMissingImage
},
rerender
)
).not.toThrow()
})

describe('Columns drag and drop', () => {
const pinSecondColumn = () => {
const secondColumn = getPin(screen.getByText(revisions[1]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,33 @@ export const ComparisonTableRows: React.FC<ComparisonTableRowsProps> = ({
dispatch(changeRowHeight(firstRowHeight))
}

const rows = rowsOrder.map((path, i) => {
const plot = plots.find(p => p.path === path)
if (!plot) {
return
}
const revs = plot.revisions
return (
<tbody
data-testid="comparison-table-body"
key={path}
id={path}
ref={i === 0 ? firstRowRef : undefined}
>
<ComparisonTableRow
path={path}
plots={columns.map(column => ({
id: column.id,
imgs: revs[column.id]?.imgs
}))}
nbColumns={columns.length}
pinnedColumn={pinnedColumn}
/>
</tbody>
)
})
const rows = rowsOrder
.map((path, i) => {
const plot = plots.find(p => p.path === path)
if (!plot) {
return
}
const revs = plot.revisions
return (
<tbody
data-testid="comparison-table-body"
key={path}
id={path}
ref={i === 0 ? firstRowRef : undefined}
>
<ComparisonTableRow
path={path}
plots={columns.map(column => ({
id: column.id,
imgs: revs[column.id]?.imgs
}))}
nbColumns={columns.length}
pinnedColumn={pinnedColumn}
/>
</tbody>
)
})
.filter(Boolean) as JSX.Element[]

const changeRowsOrder = (order: string[]) => {
setRowsOrder(order)
Expand All @@ -70,7 +72,7 @@ export const ComparisonTableRows: React.FC<ComparisonTableRowsProps> = ({

return (
<DragDropContainer
items={rows as JSX.Element[]}
items={rows}
order={rowsOrder}
setOrder={changeRowsOrder}
group="comparison-table"
Expand Down
3 changes: 3 additions & 0 deletions webview/src/shared/components/dragDrop/DragDropContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ export const DragDropContainer: React.FC<DragDropContainerProps> = ({

const wrappedItems = items
.map(draggable => {
if (!draggable) {
return
}
const id = draggable.props.id
const isDraggedOver =
id === draggedOverId && (hoveringSomething || !parentDraggedOver)
Expand Down

0 comments on commit 1d4d856

Please sign in to comment.