Skip to content

Commit 211e939

Browse files
committed
fix: in case isSortable is false, do not sort the array
1 parent 2007479 commit 211e939

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Shared/Components/KeyValueTable/KeyValueTable.component.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const KeyValueTable = <K extends string>({
7878

7979
// HOOKS
8080
const { sortBy, sortOrder, handleSorting } = useStateFilters({
81-
initialSortKey: firstHeaderKey,
81+
initialSortKey: isSortable ? firstHeaderKey : null,
8282
})
8383
const inputRowRef = useRef<HTMLTextAreaElement>()
8484
const keyTextAreaRef = useRef<Record<string, React.RefObject<HTMLTextAreaElement>>>()
@@ -212,13 +212,15 @@ export const KeyValueTable = <K extends string>({
212212
}, [])
213213

214214
useEffect(() => {
215-
setUpdatedRows((prevRows) => {
216-
const sortedRows = [...prevRows]
217-
sortedRows.sort((a, b) =>
218-
stringComparatorBySortOrder(a.data[sortBy].value, b.data[sortBy].value, sortOrder),
219-
)
220-
return sortedRows
221-
})
215+
if (isSortable) {
216+
setUpdatedRows((prevRows) => {
217+
const sortedRows = [...prevRows]
218+
sortedRows.sort((a, b) =>
219+
stringComparatorBySortOrder(a.data[sortBy].value, b.data[sortBy].value, sortOrder),
220+
)
221+
return sortedRows
222+
})
223+
}
222224
}, [sortOrder])
223225

224226
useEffect(() => {

0 commit comments

Comments
 (0)