-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special sort for some columns (#251)
- Loading branch information
Showing
2 changed files
with
46 additions
and
7 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
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,42 @@ | ||
type SortFunc = (a: string, b: string) => number; | ||
|
||
export const standardColumnSort: SortFunc = (a, b) => { | ||
return a.localeCompare(b); | ||
}; | ||
|
||
const customSort = (a: string, b: string, priorityOrder: string[]): number => { | ||
const priValueA = priorityOrder.indexOf(a); | ||
const priValueB = priorityOrder.indexOf(b); | ||
|
||
// If for some reason both values are not in the priority order list, lets use standard-sort | ||
if (priValueA < 0 && priValueB < 0) { | ||
return standardColumnSort(a, b); | ||
} | ||
|
||
return priValueA - priValueB; | ||
}; | ||
|
||
export const prirorityColumnSort: SortFunc = (a, b) => { | ||
const priorityOrder = ['kan', 'bør', '(må)', 'må']; | ||
return customSort(a, b, priorityOrder); | ||
}; | ||
|
||
export const ledetidColumnSort: SortFunc = (a, b) => { | ||
const priorityOrder = [ | ||
'kort (< 1 mnd)', | ||
'middels (1-3 mnd)', | ||
'lang (> 3 mnd)', | ||
]; | ||
return customSort(a, b, priorityOrder); | ||
}; | ||
|
||
export const getSortFuncForColumn = (columnId: string): SortFunc => { | ||
switch (columnId.toLowerCase()) { | ||
case 'pri': | ||
return prirorityColumnSort; | ||
case 'ledetid': | ||
return ledetidColumnSort; | ||
default: | ||
return standardColumnSort; | ||
} | ||
}; |