From 08b56ec7e2b9ca208ce4a790e57ba441e514c57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20M?= Date: Wed, 6 Sep 2023 11:22:42 +0200 Subject: [PATCH] fix: can't set ARR of company to empty (#1474) --- front/src/modules/ui/editable-field/types/ViewField.ts | 2 +- .../editable-field/types/guards/isViewFieldMoneyValue.ts | 5 ++++- .../type/components/GenericEditableMoneyCellEditMode.tsx | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/front/src/modules/ui/editable-field/types/ViewField.ts b/front/src/modules/ui/editable-field/types/ViewField.ts index 3a9a49f6c948..55288f2e6076 100644 --- a/front/src/modules/ui/editable-field/types/ViewField.ts +++ b/front/src/modules/ui/editable-field/types/ViewField.ts @@ -130,7 +130,7 @@ export type ViewFieldDateValue = string; export type ViewFieldPhoneValue = string; export type ViewFieldEmailValue = string; export type ViewFieldBooleanValue = boolean; -export type ViewFieldMoneyValue = number; +export type ViewFieldMoneyValue = number | null; export type ViewFieldURLValue = string; export type ViewFieldNumberValue = number | null; export type ViewFieldProbabilityValue = number; diff --git a/front/src/modules/ui/editable-field/types/guards/isViewFieldMoneyValue.ts b/front/src/modules/ui/editable-field/types/guards/isViewFieldMoneyValue.ts index 11983b9e69c7..db233d3b62c3 100644 --- a/front/src/modules/ui/editable-field/types/guards/isViewFieldMoneyValue.ts +++ b/front/src/modules/ui/editable-field/types/guards/isViewFieldMoneyValue.ts @@ -3,5 +3,8 @@ import { ViewFieldMoneyValue } from '../ViewField'; export function isViewFieldMoneyValue( fieldValue: unknown, ): fieldValue is ViewFieldMoneyValue { - return typeof fieldValue === 'number'; + return ( + fieldValue === null || + (fieldValue !== undefined && typeof fieldValue === 'number') + ); } diff --git a/front/src/modules/ui/table/editable-cell/type/components/GenericEditableMoneyCellEditMode.tsx b/front/src/modules/ui/table/editable-cell/type/components/GenericEditableMoneyCellEditMode.tsx index e4f153b2db95..d136f4b205b5 100644 --- a/front/src/modules/ui/table/editable-cell/type/components/GenericEditableMoneyCellEditMode.tsx +++ b/front/src/modules/ui/table/editable-cell/type/components/GenericEditableMoneyCellEditMode.tsx @@ -31,17 +31,17 @@ export function GenericEditableMoneyCellEditMode({ if (newText === fieldValue) return; try { - const numberValue = parseInt(newText); + const numberValue = newText !== '' ? parseInt(newText) : null; - if (isNaN(numberValue)) { + if (numberValue && isNaN(numberValue)) { throw new Error('Not a number'); } - if (numberValue > 2000000000) { + if (numberValue && numberValue > 2000000000) { throw new Error('Number too big'); } - setFieldValue(numberValue.toString()); + setFieldValue(numberValue ? numberValue.toString() : ''); if (currentRowEntityId && updateField) { updateField(currentRowEntityId, columnDefinition, numberValue);