Skip to content

Commit

Permalink
fix(crux-ui): simplify list sorting (#935)
Browse files Browse the repository at this point in the history
Co-authored-by: Levente Orban <levente.orban@dyrector.io>
  • Loading branch information
m8vago and polaroi8d committed Mar 23, 2024
1 parent 8e1026a commit 2b30f74
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions web/crux-ui/src/elements/dyo-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ const DyoTable = <T,>(props: React.PropsWithChildren<DyoTableProps<T>>) => {
const [pagination, setPagination] = useState<PaginationSettings>({ pageNumber: 0, pageSize: 10 })
const [data, setData] = useState(propData)
const [sort, setSort] = useState<SortState>(() => {
if (initialSortColumn != null && initialSortDirection) {
return {
column: initialSortColumn,
direction: initialSortDirection,
}
}

return null
const direction = initialSortDirection ?? 'asc'
const sortColum = initialSortColumn != null ? initialSortColumn : columns.findIndex(it => it.sortable)

return sortColum > -1
? {
column: sortColum,
direction,
}
: null
})

const getField = (obj: any, field: string | ((it: any) => any)) => {
Expand Down Expand Up @@ -192,15 +193,10 @@ const DyoTable = <T,>(props: React.PropsWithChildren<DyoTableProps<T>>) => {
return
}

if (sort.direction === 'asc') {
setSort({
column,
direction: 'desc',
})
return
}

setSort(null)
setSort({
column,
direction: sort.direction === 'asc' ? 'desc' : 'asc',
})
}

const paginate = (it: PaginationSettings) => {
Expand Down

0 comments on commit 2b30f74

Please sign in to comment.