Skip to content

Commit

Permalink
Handle missing items in drag and drop container
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Nov 30, 2023
1 parent 935a4c2 commit ac060c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
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 ac060c7

Please sign in to comment.