From 89ae70c45dffc8616e81a015b7ef9b39984baebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:04:43 +0200 Subject: [PATCH] Make sure value stored in integer is always a number --- packages/dataviews/src/field-types/integer.tsx | 2 +- packages/dataviews/src/normalize-fields.ts | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/dataviews/src/field-types/integer.tsx b/packages/dataviews/src/field-types/integer.tsx index 1233c3ab55556..bd4956493232d 100644 --- a/packages/dataviews/src/field-types/integer.tsx +++ b/packages/dataviews/src/field-types/integer.tsx @@ -53,7 +53,7 @@ function Edit< Item >( { ( newValue: string | undefined ) => onChange( ( prevItem: Item ) => ( { ...prevItem, - [ id ]: newValue, + [ id ]: Number( newValue ), } ) ), [ id, onChange ] ); diff --git a/packages/dataviews/src/normalize-fields.ts b/packages/dataviews/src/normalize-fields.ts index 680749df5344a..4468c228322e2 100644 --- a/packages/dataviews/src/normalize-fields.ts +++ b/packages/dataviews/src/normalize-fields.ts @@ -42,13 +42,10 @@ export function normalizeFields< Item >( const renderFromElements = ( { item }: { item: Item } ) => { const value = getValue( { item } ); - const label = field?.elements?.find( ( element ) => { - // Intentionally using == here to allow for type coercion. - // eslint-disable-next-line eqeqeq - return element.value == value; - } )?.label; - - return label || value; + return ( + field?.elements?.find( ( element ) => element.value === value ) + ?.label || getValue( { item } ) + ); }; const render =