-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add naturalSort utility function for list view sorting * added source for sorting as well * use naturalSort * Refactor sorting logic in FlexboxTable component * new sor in paper useColumns.tsx * not sort by source * remove unused method
- Loading branch information
Showing
5 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/editor/src/features/content/list-view/utils/naturalSort.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IContentSearchResult } from 'store/slices'; | ||
|
||
function getPageSectionValue(row: IContentSearchResult) { | ||
// gnerate page:section string, keep it in the lowercase | ||
const value = `${row.original.page ? row.original.page : ''}:${ | ||
row.original.section ? row.original.section : '' | ||
}`.toLowerCase(); | ||
return value; | ||
} | ||
|
||
export function naturalSortValue(row: IContentSearchResult) { | ||
const pageSectionValue = getPageSectionValue(row); | ||
// Replace each segment of digits and non-digits with formatted strings | ||
// Digits are padded with zeros to the left to ensure correct natural sorting | ||
// Non-digits are left as is | ||
// eq. 'A2:sport' -> 'A0000000002:sport' | ||
// eq. 'A02:sport' -> 'A0000000002:sport' | ||
const formattedPageSectionValue = pageSectionValue.replace(/(\d+)|(\D+)/g, (_, $1, $2) => | ||
$1 ? Number($1).toString().padStart(10, '0') : $2, | ||
); | ||
// we do consider source as the primary key for sorting | ||
return formattedPageSectionValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ITableInternalHeaderColumn } from '../interfaces/ITableInternalHeaderColumn'; | ||
|
||
export const determineSortValue = <T extends object>(col: ITableInternalHeaderColumn<T>) => { | ||
// If 'col.sort' is defined and not null, use it directly for sorting | ||
if (col.sort !== undefined && col.sort !== null) { | ||
return col.sort; | ||
} | ||
// If 'col.sort' is undefined or null and 'accessor' is a function, | ||
// it indicates that 'accessor' cannot be used for sorting directly (e.g., dynamic values) | ||
if (typeof col.accessor === 'function') { | ||
return undefined; | ||
} | ||
// If 'col.sort' is undefined or null, and 'accessor' is not a function, | ||
// use 'accessor' as the field name for sorting | ||
return col.accessor; | ||
}; |