Core views frontend (#13932)

Parallel code path to read and write core views when
IS_CORE_VIEW_ENABLED.

Migrated view key to an enum.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Raphaël Bosi
2025-08-20 19:04:58 +02:00
committed by GitHub
parent deec9c96da
commit 30c42345f0
114 changed files with 5019 additions and 254 deletions
@@ -0,0 +1,33 @@
import { parseJson } from "@/utils/parseJson";
describe('parseJson', () => {
it('if value is null', () => {
const result = parseJson(null);
expect(result).toBeNull();
});
it('if value is number', () => {
const result = parseJson(123);
expect(result).toBe(123);
});
it('if value is string', () => {
const result = parseJson('"mystring"');
expect(result).toBe('mystring');
});
it('if value is an object', () => {
const result = parseJson('{"name": "John"}');
expect(result).toEqual({ name: 'John' });
});
it('if value is an array', () => {
const result = parseJson('[1, 2, 3]');
expect(result).toEqual([1, 2, 3]);
});
it('if value is a boolean', () => {
const result = parseJson(true);
expect(result).toBe(true);
});
});
+10 -3
View File
@@ -1,7 +1,14 @@
export const parseJson = <T>(json: string): T | null => {
import { isDefined } from "@/utils/validation";
export const parseJson = <T>(rawJson: string | boolean | null | number): T | null => {
try {
return JSON.parse(json);
if (!isDefined(rawJson)) {
return null;
}
// This is a hack to handle the case where the value is a scalar value which is part of JSON spec but not implemented before ES2019
return JSON.parse("[" + rawJson + "]")[0];
} catch {
return null;
return null;
}
};