From 53740fc57a2c056a6cd2ae19fc5c405337f58f82 Mon Sep 17 00:00:00 2001 From: Satish Gandham Date: Thu, 6 Jun 2024 13:18:35 +0530 Subject: [PATCH] Fix sortable component as the sort order was broken. --- packages/ui/src/sortable/sortable.stories.tsx | 3 +-- packages/ui/src/sortable/sortable.tsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/sortable/sortable.stories.tsx b/packages/ui/src/sortable/sortable.stories.tsx index 6d40ddc2e..2d469b767 100644 --- a/packages/ui/src/sortable/sortable.stories.tsx +++ b/packages/ui/src/sortable/sortable.stories.tsx @@ -1,6 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { Draggable } from "./draggable"; import { Sortable } from "./sortable"; const meta: Meta = { @@ -13,7 +12,7 @@ type Story = StoryObj; const data = [ { id: "1", name: "John Doe" }, - { id: "2", name: "Jane Doe 2" }, + { id: "2", name: "Satish" }, { id: "3", name: "Alice" }, { id: "4", name: "Bob" }, { id: "5", name: "Charlie" }, diff --git a/packages/ui/src/sortable/sortable.tsx b/packages/ui/src/sortable/sortable.tsx index 0b1a27d5f..b495d535e 100644 --- a/packages/ui/src/sortable/sortable.tsx +++ b/packages/ui/src/sortable/sortable.tsx @@ -17,7 +17,7 @@ const moveItem = ( destination: T & Record, keyExtractor: (item: T, index: number) => string ) => { - const sourceIndex = data.indexOf(source); + const sourceIndex = data.findIndex((item, index) => keyExtractor(item, index) === keyExtractor(source, 0)); if (sourceIndex === -1) return data; const destinationIndex = data.findIndex((item, index) => keyExtractor(item, index) === keyExtractor(destination, 0));