From d66a9c08b695df52b17f23f78b64d4d0912aa1cc Mon Sep 17 00:00:00 2001 From: nganphan123 <jill01009@gmail.com> Date: Thu, 17 Oct 2024 00:38:58 -0700 Subject: [PATCH 1/3] add fidx --- .../record-field/utils/isFieldValueEmpty.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts index 93ee5eaa5458..be0ced50aca9 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts @@ -1,4 +1,4 @@ -import { isString } from '@sniptt/guards'; +import { isNonEmptyArray, isString } from '@sniptt/guards'; import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition'; import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; @@ -28,6 +28,8 @@ import { isFieldPosition } from '@/object-record/record-field/types/guards/isFie import { isFieldRating } from '@/object-record/record-field/types/guards/isFieldRating'; import { isFieldRawJson } from '@/object-record/record-field/types/guards/isFieldRawJson'; import { isFieldRelation } from '@/object-record/record-field/types/guards/isFieldRelation'; +import { isFieldRelationFromManyValue } from '@/object-record/record-field/types/guards/isFieldRelationFromManyValue'; +import { isFieldRelationToOneValue } from '@/object-record/record-field/types/guards/isFieldRelationToOneValue'; import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText'; import { isFieldSelect } from '@/object-record/record-field/types/guards/isFieldSelect'; import { isFieldSelectValue } from '@/object-record/record-field/types/guards/isFieldSelectValue'; @@ -58,7 +60,6 @@ export const isFieldValueEmpty = ({ isFieldNumber(fieldDefinition) || isFieldRating(fieldDefinition) || isFieldBoolean(fieldDefinition) || - isFieldRelation(fieldDefinition) || isFieldRawJson(fieldDefinition) || isFieldRichText(fieldDefinition) || isFieldPosition(fieldDefinition) @@ -73,11 +74,20 @@ export const isFieldValueEmpty = ({ ); } + if (isFieldRelation(fieldDefinition)) { + return ( + !isFieldRelationToOneValue(fieldValue) || + !isFieldRelationFromManyValue(fieldValue) || + !isNonEmptyArray(fieldValue) + ); + } + if (isFieldMultiSelect(fieldDefinition) || isFieldArray(fieldDefinition)) { return ( !isFieldArrayValue(fieldValue) || !isFieldMultiSelectValue(fieldValue, selectOptionValues) || - !isDefined(fieldValue) + !isDefined(fieldValue) || + !isNonEmptyArray(fieldValue) ); } From 302f1171db6aafe25321e7be97c34a5593a6ac9f Mon Sep 17 00:00:00 2001 From: nganphan123 <jill01009@gmail.com> Date: Thu, 17 Oct 2024 01:22:18 -0700 Subject: [PATCH 2/3] small fix --- .../record-field/utils/isFieldValueEmpty.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts index be0ced50aca9..e8e3ebe3fb86 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueEmpty.ts @@ -1,4 +1,4 @@ -import { isNonEmptyArray, isString } from '@sniptt/guards'; +import { isArray, isNonEmptyArray, isString } from '@sniptt/guards'; import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition'; import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'; @@ -28,8 +28,6 @@ import { isFieldPosition } from '@/object-record/record-field/types/guards/isFie import { isFieldRating } from '@/object-record/record-field/types/guards/isFieldRating'; import { isFieldRawJson } from '@/object-record/record-field/types/guards/isFieldRawJson'; import { isFieldRelation } from '@/object-record/record-field/types/guards/isFieldRelation'; -import { isFieldRelationFromManyValue } from '@/object-record/record-field/types/guards/isFieldRelationFromManyValue'; -import { isFieldRelationToOneValue } from '@/object-record/record-field/types/guards/isFieldRelationToOneValue'; import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText'; import { isFieldSelect } from '@/object-record/record-field/types/guards/isFieldSelect'; import { isFieldSelectValue } from '@/object-record/record-field/types/guards/isFieldSelectValue'; @@ -75,11 +73,10 @@ export const isFieldValueEmpty = ({ } if (isFieldRelation(fieldDefinition)) { - return ( - !isFieldRelationToOneValue(fieldValue) || - !isFieldRelationFromManyValue(fieldValue) || - !isNonEmptyArray(fieldValue) - ); + if (isArray(fieldValue)) { + return !isNonEmptyArray(fieldValue); + } + return isValueEmpty(fieldValue); } if (isFieldMultiSelect(fieldDefinition) || isFieldArray(fieldDefinition)) { From a441afae09f58c339609f1c5df8436ad02862488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= <felix@twenty.com> Date: Thu, 17 Oct 2024 11:06:27 +0200 Subject: [PATCH 3/3] Add more tests --- .../utils/__tests__/isFieldValueEmpty.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueEmpty.test.ts b/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueEmpty.test.ts index 07761aef8822..db247716ab9a 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueEmpty.test.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/utils/__tests__/isFieldValueEmpty.test.ts @@ -46,6 +46,18 @@ describe('isFieldValueEmpty', () => { fieldValue: { foo: 'bar' }, }), ).toBe(false); + expect( + isFieldValueEmpty({ + fieldDefinition: relationFieldDefinition, + fieldValue: [], + }), + ).toBe(true); + expect( + isFieldValueEmpty({ + fieldDefinition: relationFieldDefinition, + fieldValue: [{ id: '123' }], + }), + ).toBe(false); }); it('should return correct value for select field', () => {