Skip to content

Commit

Permalink
feat: remove validation for raw json field
Browse files Browse the repository at this point in the history
  • Loading branch information
Devessier committed Dec 18, 2024
1 parent c91f188 commit 8bed07f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -81,7 +79,7 @@ export const IgnoreInvalidJson: Story = {

await userEvent.click(canvasElement);

expect(args.onPersist).not.toHaveBeenCalled();
expect(args.onPersist).toHaveBeenCalledWith('lol');
},
};

Expand Down Expand Up @@ -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(),
Expand All @@ -224,7 +222,7 @@ export const BreaksWhenUserInsertsNewlineInJsonString: Story = {

await userEvent.click(canvasElement);

expect(args.onPersist).not.toHaveBeenCalled();
expect(args.onPersist).toHaveBeenCalled();
},
};

Expand Down

0 comments on commit 8bed07f

Please sign in to comment.