Skip to content

Commit

Permalink
fix(FE selection sorting): fix emoji and selection id = 0 handling (#539
Browse files Browse the repository at this point in the history
)

- remove emojis to sort by the real value
- correct handling of selection-id = 0
- code cleanup

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian authored Sep 12, 2023
1 parent 32d1f4f commit ef49b5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/shared/components/ncTable/mixins/columnsTypes/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ export default class SelectionColumn extends AbstractSelectionColumn {
sort(mode) {
const factor = mode === 'DESC' ? -1 : 1
return (rowA, rowB) => {
const selectionIdA = rowA.data.find(item => item.columnId === this.id)?.value || null
const valueA = selectionIdA !== null ? this.selectionOptions.find(item => item.id === selectionIdA)?.label : ''
const selectionIdB = rowB.data.find(item => item.columnId === this.id)?.value || null
const valueB = selectionIdB !== null ? this.selectionOptions.find(item => item.id === selectionIdB)?.label : ''
const selectionIdA = rowA.data.find(item => item.columnId === this.id)?.value ?? null
const vA = selectionIdA !== null ? this.selectionOptions.find(item => item.id === selectionIdA)?.label : ''
const valueA = this.removeEmoji(vA).trim()
const selectionIdB = rowB.data.find(item => item.columnId === this.id)?.value ?? null
const vB = selectionIdB !== null ? this.selectionOptions.find(item => item.id === selectionIdB)?.label : ''
const valueB = this.removeEmoji(vB).trim()
return ((valueA < valueB) ? -1 : (valueA > valueB) ? 1 : 0) * factor
}
}

removeEmoji(str) {
return str.replace(/([#0-9]\u20E3)|[\xA9\xAE\u203C\u2047-\u2049\u2122\u2139\u3030\u303D\u3297\u3299][\uFE00-\uFEFF]?|[\u2190-\u21FF][\uFE00-\uFEFF]?|[\u2300-\u23FF][\uFE00-\uFEFF]?|[\u2460-\u24FF][\uFE00-\uFEFF]?|[\u25A0-\u25FF][\uFE00-\uFEFF]?|[\u2600-\u27BF][\uFE00-\uFEFF]?|[\u2900-\u297F][\uFE00-\uFEFF]?|[\u2B00-\u2BF0][\uFE00-\uFEFF]?|(?:\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDEFF])[\uFE00-\uFEFF]?/g, '')
}

isSearchStringFound(cell, searchString) {
return super.isSearchStringFound(this.getLabel(cell.value), cell, searchString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ export default {
this.sortMode = null
this.localViewSetting.sorting = null
} else {
this.sortMode = mode
if (mode !== 'ASC' && mode !== 'DESC') {
return
}
this.sortMode = mode
this.localViewSetting.sorting = [{
columnId: this.column.id,
mode,
Expand Down

0 comments on commit ef49b5e

Please sign in to comment.