Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing items in drag and drop container #5054

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@mattseddon mattseddon Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] rowsOrder can contain paths that no longer exist because it is updated by setRowsOrder from useState.

.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[]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] The filter is the only change.


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
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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] This is another just in case (the resulting array was already filtered).

return
}
const id = draggable.props.id
const isDraggedOver =
id === draggedOverId && (hoveringSomething || !parentDraggedOver)
Expand Down
Loading