Skip to content

Commit

Permalink
Fix issue with sorting of currency fields #1369
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi749 committed Apr 15, 2024
1 parent 5b87d45 commit f4def82
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Sjekk ut [release notes](./releasenotes/1.9.0.md) for høydepunkter og mer detal
- Rettet et problem hvor noen Idémodul listekommandoer ikke ble vist dersom andre Idé-lister var definert i `Idékonfigurasjon` [#1430](https://github.com/Puzzlepart/prosjektportalen365/issues/1430)
- Rettet et problem hvor avviklede termer ble vist i nedtrekksmenyer for taksonomi felter [#1499](https://github.com/Puzzlepart/prosjektportalen365/issues/1499)
- Rettet et problem hvor antall linjer angitt for et 'multi-linje' felt ikke ble reflektert i det nye redigeringspanelet [#1500](https://github.com/Puzzlepart/prosjektportalen365/issues/1500)
- Rettet et problem hvor valuta ikke ble riktig sortert på porteføljeoversikt og andre aggregerte oversikter [#1369](https://github.com/Puzzlepart/prosjektportalen365/issues/1369)

### Forbedringer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,23 @@ export const createPortfolioAggregationReducer = (
state.groupBy = null
state.groups = null
}
state.items = sortArray([...state.items], [payload.column.fieldName], {
reverse: !isSortedDescending
})
if (payload.column.dataType === 'currency') {
state.items = state.items.sort((a, b) => {
const aValue = parseFloat(a[payload.column.fieldName]?.replace(/[^0-9.-]+/g, '')) || null
const bValue = parseFloat(b[payload.column.fieldName]?.replace(/[^0-9.-]+/g, '')) || null
if (aValue === bValue)
return 0
if (aValue === null)
return isSortedDescending ? 1 : -1
if (bValue === null)
return isSortedDescending ? -1 : 1
return isSortedDescending ? aValue - bValue : aValue - bValue
})
} else {
state.items = sortArray([...state.items], [payload.column.fieldName], {
reverse: !isSortedDescending
})
}
state.columns = [...state.columns].map((col) => {
col.isSorted = col.key === payload.column.key
col.isSortedDescending = col.isSorted ? isSortedDescending : false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,23 @@ const $createReducer = (params: IPortfolioOverviewReducerParams) =>
return isSortedDescending ? $a - $b : $b - $a
})
} else {
state.items = sortArray(state.items, [payload.column.fieldName], {
reverse: !isSortedDescending
})
if (payload.column.dataType === 'currency') {
state.items = state.items.sort((a, b) => {
const aValue = parseFloat(a[payload.column.fieldName]?.replace(/[^0-9.-]+/g, '')) || null
const bValue = parseFloat(b[payload.column.fieldName]?.replace(/[^0-9.-]+/g, '')) || null
if (aValue === bValue)
return 0
if (aValue === null)
return isSortedDescending ? 1 : -1
if (bValue === null)
return isSortedDescending ? -1 : 1
return isSortedDescending ? aValue - bValue : aValue - bValue
})
} else {
state.items = sortArray(state.items, [payload.column.fieldName], {
reverse: !isSortedDescending
})
}
}
state.sortBy = _.pick(payload, ['column', 'customSort'])
state.columns = state.columns.map((col) => {
Expand Down

0 comments on commit f4def82

Please sign in to comment.