Skip to content

Commit

Permalink
fix: sort columns using non case sensitive sort
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Dec 16, 2024
1 parent 20affe3 commit 4afac53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions src/components/sectionList/ColumnHeaderSortable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { DataTableColumnHeader, DataTableColumnHeaderProps } from '@dhis2/ui'
import {
DataTableColumnHeader,
DataTableColumnHeaderProps,
DataTableSortDirection,
} from '@dhis2/ui'
import React, { useCallback } from 'react'
import {
SchemaSection,
Expand Down Expand Up @@ -37,11 +41,11 @@ export const HeaderColumnsSortable = ({
[setSortOrder]
)

const getDataTableSortDirection = (column: SelectedColumn) => {
const allowSort =
column && isValidSortPathForSchema(schema, column.path)
const isSortAllowed = (column: SelectedColumn) =>
column && isValidSortPathForSchema(schema, column.path)

if (!allowSort) {
const getDataTableSortDirection = (column: SelectedColumn) => {
if (!isSortAllowed(column)) {
return undefined
}
if (!sortOrder) {
Expand All @@ -57,7 +61,11 @@ export const HeaderColumnsSortable = ({
{headerColumns.map((headerColumn) => (
<DataTableColumnHeader
sortDirection={getDataTableSortDirection(headerColumn)}
onSortIconClick={handleSortOrderChange}
onSortIconClick={
isSortAllowed(headerColumn)
? handleSortOrderChange
: undefined
}
key={headerColumn.path}
name={headerColumn.path}
>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sectionList/useSectionListSortOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ export const useSectionListSortOrder = () => {
export const useSortOrderQueryParams = () => {
const [sortOrder] = useSectionListSortOrder()

return sortOrder ? formatSortOrderToString(sortOrder) : undefined
return sortOrder ? `${sortOrder[0]}:i${sortOrder[1]}` : undefined
}
1 change: 1 addition & 0 deletions src/pages/DefaultSectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const DefaultSectionList = ({ filters }: DefaultSectionListProps) => {
},
},
}

const { error, data, refetch } = useQuery({
queryKey: [query],
queryFn: ({ queryKey: [query], signal }) => {
Expand Down

0 comments on commit 4afac53

Please sign in to comment.