Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Bugfix - Owners table sorting is not working correctly #2364

Merged
merged 5 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ class GnoTable extends React.Component<any, any> {
const orderParam = order || defaultOrder
const displayRows = rowsPerPage || defaultRowsPerPage
const fixedParam = typeof fixed !== 'undefined' ? fixed : !!defaultFixed

const paginationClasses = {
selectRoot: classes.selectRoot,
root: !noBorder && classes.paginationRoot,
input: classes.white,
}

let sortedData = stableSort(data, getSorting(orderParam, orderByParam, orderProp), fixedParam)
const columnSort = columns.find((column) => column.id === orderByParam)
let sortedData = stableSort(
data,
getSorting(orderParam, orderByParam, orderProp, columnSort['formatTypeSort']),
fixedParam,
)

if (!disablePagination) {
sortedData = sortedData.slice(page * displayRows, page * displayRows + displayRows)
Expand Down
11 changes: 7 additions & 4 deletions src/components/Table/sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export const FIXED = 'fixed'

export const buildOrderFieldFrom = (attr: string): string => `${attr}Order`

const desc = (a: string, b: string, orderBy: string, orderProp: boolean): number => {
const desc = (a: string, b: string, orderBy: string, orderProp: boolean, format: (value: any) => any): number => {
matextrem marked this conversation as resolved.
Show resolved Hide resolved
const order = orderProp ? buildOrderFieldFrom(orderBy) : orderBy

if (b[order] < a[order]) {
if (format(b[order]) < format(a[order])) {
return -1
}
if (b[order] > a[order]) {
if (format(b[order]) > format(a[order])) {
return 1
}

Expand Down Expand Up @@ -42,5 +42,8 @@ export const getSorting = (
order: 'desc' | 'asc',
orderBy: string,
orderProp: boolean,
format: (value: any) => any = (value) => value,
matextrem marked this conversation as resolved.
Show resolved Hide resolved
): ((a: string, b: string) => number) =>
order === 'desc' ? (a, b) => desc(a, b, orderBy, orderProp) : (a, b) => -desc(a, b, orderBy, orderProp)
order === 'desc'
? (a, b) => desc(a, b, orderBy, orderProp, format)
: (a, b) => -desc(a, b, orderBy, orderProp, format)
1 change: 1 addition & 0 deletions src/components/Table/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export interface TableColumn {
order: boolean
static?: boolean
style?: any
formatTypeSort?: (value: any) => any
matextrem marked this conversation as resolved.
Show resolved Hide resolved
width?: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const generateColumns = (): List<TableColumn> => {
const nameColumn: TableColumn = {
id: OWNERS_TABLE_NAME_ID,
order: false,
formatTypeSort: (value: string) => value.toLowerCase(),
disablePadding: false,
label: 'Name',
width: 150,
Expand Down