Fixed sort bug when two select values were null (#6493)

Fixes https://github.com/twentyhq/twenty/issues/5762

The problem was only happening with a sort on a select type field, also
appears with currency type and maybe other types.

This was because NULL values were sorted in a random order because the
sort function was comparing two NULL values as not equal, so I just
added a case for when A === B === NULL.
This commit is contained in:
Lucas Bordeau
2024-08-02 10:48:36 +02:00
committed by GitHub
parent 0dcdda3928
commit f0ca3439a8
2 changed files with 10 additions and 1 deletions

View File

@ -3,7 +3,14 @@ import { Maybe } from '~/generated/graphql';
export const sortNullsFirst = (
fieldValueA: Maybe<unknown>,
fieldValueB: Maybe<unknown>,
) => (fieldValueA === null ? -1 : fieldValueB === null ? 1 : 0);
) =>
fieldValueA === null && fieldValueB === null
? 0
: fieldValueA === null
? -1
: fieldValueB === null
? 1
: 0;
export const sortNullsLast = (
fieldValueA: Maybe<unknown>,