Skip to content

Commit

Permalink
♻️ refact sort function to reverse sortingIndices.
Browse files Browse the repository at this point in the history
  • Loading branch information
jindonyy committed Nov 29, 2022
1 parent 8dfd8ba commit 5734bd9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/primitives/src/components/Table/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ const HeadCell = ({
...restProps
}: HeadCellProps) => {
const { sortingValues = {}, sortingState, setSortingState } = sortingConfig;
const isClicked = sortingState.name === name;
const direction =
sortingState.name === name &&
sortingState.direction === DIRECTION.DESCENDING
isClicked && sortingState.direction === DIRECTION.DESCENDING
? DIRECTION.ASCENDING
: DIRECTION.DESCENDING;

const getSortingIndices = () => {
if (isClicked && sortingState.sortingIndices)
return sortingState.sortingIndices.reverse();

const sortingValuesByName = sortingValues[name].map((value, index) => ({
value,
index,
Expand Down Expand Up @@ -79,9 +82,7 @@ const HeadCell = ({
return (
<th
scope={scope}
data-sort={
sortingState.name === name ? sortingState.direction : undefined
}
data-sort={isClicked ? sortingState.direction : undefined}
{...restProps}
>
{name ? (
Expand Down

0 comments on commit 5734bd9

Please sign in to comment.