[fix] Do not stringify json field value if null (#5348)

as per title 


https://github.com/twentyhq/twenty/assets/51697796/74ff0185-f20c-4ff1-9d89-3078063f23e1
This commit is contained in:
Marie 2024-05-10 13:00:24 +02:00 committed by GitHub
parent 8590bd7227
commit 999a66882d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -1,13 +1,18 @@
import { useJsonField } from '@/object-record/record-field/meta-types/hooks/useJsonField';
import { isFieldRawJsonValue } from '@/object-record/record-field/types/guards/isFieldRawJsonValue';
import { JsonDisplay } from '@/ui/field/display/components/JsonDisplay';
import { isDefined } from '~/utils/isDefined';
export const JsonFieldDisplay = () => {
const { fieldValue, maxWidth } = useJsonField();
return (
<JsonDisplay
text={isFieldRawJsonValue(fieldValue) ? JSON.stringify(fieldValue) : ''}
text={
isFieldRawJsonValue(fieldValue) && isDefined(fieldValue)
? JSON.stringify(fieldValue)
: ''
}
maxWidth={maxWidth}
/>
);

View File

@ -8,6 +8,7 @@ import { isFieldRawJsonValue } from '@/object-record/record-field/types/guards/i
import { isFieldRelation } from '@/object-record/record-field/types/guards/isFieldRelation';
import { computeEmptyDraftValue } from '@/object-record/record-field/utils/computeEmptyDraftValue';
import { isFieldValueEmpty } from '@/object-record/record-field/utils/isFieldValueEmpty';
import { isDefined } from '~/utils/isDefined';
type computeDraftValueFromFieldValueParams<FieldValue> = {
fieldDefinition: Pick<FieldDefinition<FieldMetadata>, 'type'>;
@ -41,7 +42,7 @@ export const computeDraftValueFromFieldValue = <FieldValue>({
}
if (isFieldRawJson(fieldDefinition)) {
return isFieldRawJsonValue(fieldValue)
return isFieldRawJsonValue(fieldValue) && isDefined(fieldValue)
? (JSON.stringify(
fieldValue,
null,