From 8bed07fc0caa9bb0e4d80e9fd50f5e0d90c409d3 Mon Sep 17 00:00:00 2001 From: Devessier Date: Wed, 18 Dec 2024 11:28:15 +0100 Subject: [PATCH] feat: remove validation for raw json field --- .../components/FormRawJsonFieldInput.tsx | 19 ------------------- .../FormRawJsonFieldInput.stories.tsx | 18 ++++++++---------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormRawJsonFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormRawJsonFieldInput.tsx index 264214eaad7c..851b7c5615a3 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormRawJsonFieldInput.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/FormRawJsonFieldInput.tsx @@ -5,7 +5,6 @@ import { TextVariableEditor } from '@/object-record/record-field/form-types/comp import { useTextVariableEditor } from '@/object-record/record-field/form-types/hooks/useTextVariableEditor'; import { VariablePickerComponent } from '@/object-record/record-field/form-types/types/VariablePickerComponent'; import { InputLabel } from '@/ui/input/components/InputLabel'; -import { CAPTURE_VARIABLE_TAG_REGEX } from '@/workflow/search-variables/utils/initializeEditorContent'; import { useId } from 'react'; import { isDefined } from 'twenty-ui'; import { turnIntoEmptyStringIfWhitespacesOnly } from '~/utils/string/turnIntoEmptyStringIfWhitespacesOnly'; @@ -43,24 +42,6 @@ export const FormRawJsonFieldInput = ({ return; } - const textWithReplacedVariables = text.replaceAll( - new RegExp(CAPTURE_VARIABLE_TAG_REGEX, 'g'), - '0', - ); - - let isValidJson; - try { - JSON.parse(textWithReplacedVariables); - - isValidJson = true; - } catch { - isValidJson = false; - } - - if (!isValidJson) { - return; - } - onPersist(text); }, }); diff --git a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx index c2b8aaa93758..aac0d2b69996 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/form-types/components/__stories__/FormRawJsonFieldInput.stories.tsx @@ -58,17 +58,15 @@ export const SaveValidJson: Story = { const editor = canvasElement.querySelector('.ProseMirror > p'); expect(editor).toBeVisible(); - await Promise.all([ - userEvent.type(editor, '{{ "a": {{ "b" : "d" } }'), + await userEvent.type(editor, '{{ "a": {{ "b" : "d" } }'); - waitFor(() => { - expect(args.onPersist).toHaveBeenCalledWith('{ "a": { "b" : "d" } }'); - }), - ]); + await waitFor(() => { + expect(args.onPersist).toHaveBeenCalledWith('{ "a": { "b" : "d" } }'); + }); }, }; -export const IgnoreInvalidJson: Story = { +export const DoesNotIgnoreInvalidJson: Story = { args: { placeholder: 'Enter valid json', onPersist: fn(), @@ -81,7 +79,7 @@ export const IgnoreInvalidJson: Story = { await userEvent.click(canvasElement); - expect(args.onPersist).not.toHaveBeenCalled(); + expect(args.onPersist).toHaveBeenCalledWith('lol'); }, }; @@ -211,7 +209,7 @@ export const ClearField: Story = { * Line breaks are not authorized in JSON strings. Users should instead put newlines characters themselves. * See https://stackoverflow.com/a/42073. */ -export const BreaksWhenUserInsertsNewlineInJsonString: Story = { +export const DoesNotBreakWhenUserInsertsNewlineInJsonString: Story = { args: { placeholder: 'Enter valid json', onPersist: fn(), @@ -224,7 +222,7 @@ export const BreaksWhenUserInsertsNewlineInJsonString: Story = { await userEvent.click(canvasElement); - expect(args.onPersist).not.toHaveBeenCalled(); + expect(args.onPersist).toHaveBeenCalled(); }, };