Skip to content

Commit

Permalink
another fix to draggableStepItems
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Feb 16, 2024
1 parent 2bd2c09 commit c5861b3
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions protocol-designer/src/components/steplist/DraggableStepItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,19 @@ export const DraggableStepItems = (
const findStepIndex = (stepId: StepIdType): number =>
stepIds.findIndex(id => stepId === id)

Check warning on line 109 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L108-L109

Added lines #L108 - L109 were not covered by tests

const moveStep = React.useCallback(
(stepId: StepIdType, targetIndex: number): void => {
const currentIndex = findStepIndex(stepId)
const currentRemoved = [
...stepIds.slice(0, currentIndex),
...stepIds.slice(currentIndex + 1, stepIds.length),
]
const currentReinserted = [
...currentRemoved.slice(0, targetIndex),
stepId,
...currentRemoved.slice(targetIndex, currentRemoved.length),
]
setStepIds(currentReinserted)
},
[stepIds, findStepIndex]
)
const moveStep = (stepId: StepIdType, targetIndex: number): void => {
const currentIndex = findStepIndex(stepId)

Check warning on line 112 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L111-L112

Added lines #L111 - L112 were not covered by tests
const currentRemoved = [
...stepIds.slice(0, currentIndex),
...stepIds.slice(currentIndex + 1, stepIds.length),
]
const currentReinserted = [
...currentRemoved.slice(0, targetIndex),
stepId,
...currentRemoved.slice(targetIndex, currentRemoved.length),
]
setStepIds(currentReinserted)

Check warning on line 122 in protocol-designer/src/components/steplist/DraggableStepItems.tsx

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/components/steplist/DraggableStepItems.tsx#L122

Added line #L122 was not covered by tests
}

const currentIds = isOver ? stepIds : orderedStepIds

Expand Down

0 comments on commit c5861b3

Please sign in to comment.