fix: Custom fields lacks empty tag (#7777)

This PR fixes this issue #7250

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Ngan Phan
2024-10-20 23:33:59 -07:00
committed by GitHub
parent cc4b060932
commit d6810c3b42
2 changed files with 22 additions and 3 deletions

View File

@ -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', () => {

View File

@ -1,4 +1,4 @@
import { 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';
@ -58,7 +58,6 @@ export const isFieldValueEmpty = ({
isFieldNumber(fieldDefinition) ||
isFieldRating(fieldDefinition) ||
isFieldBoolean(fieldDefinition) ||
isFieldRelation(fieldDefinition) ||
isFieldRawJson(fieldDefinition) ||
isFieldRichText(fieldDefinition) ||
isFieldPosition(fieldDefinition)
@ -73,11 +72,19 @@ export const isFieldValueEmpty = ({
);
}
if (isFieldRelation(fieldDefinition)) {
if (isArray(fieldValue)) {
return !isNonEmptyArray(fieldValue);
}
return isValueEmpty(fieldValue);
}
if (isFieldMultiSelect(fieldDefinition) || isFieldArray(fieldDefinition)) {
return (
!isFieldArrayValue(fieldValue) ||
!isFieldMultiSelectValue(fieldValue, selectOptionValues) ||
!isDefined(fieldValue)
!isDefined(fieldValue) ||
!isNonEmptyArray(fieldValue)
);
}