From 9769646a30c1a522e0724828764da0431b8803f9 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Tue, 4 Jun 2024 12:43:45 +0200 Subject: [PATCH 1/5] feat(editor): Harmonize rendering of new-lines in RunData Signed-off-by: Oleg Ivaniv --- .../src/components/RunDataSchemaItem.vue | 24 +++++++++++++---- .../editor-ui/src/components/RunDataTable.vue | 2 +- .../src/components/TextWithHighlights.vue | 27 +++++++++++++++++-- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/packages/editor-ui/src/components/RunDataSchemaItem.vue b/packages/editor-ui/src/components/RunDataSchemaItem.vue index fed0df3d3d46b..e2a4a87301a11 100644 --- a/packages/editor-ui/src/components/RunDataSchemaItem.vue +++ b/packages/editor-ui/src/components/RunDataSchemaItem.vue @@ -1,10 +1,11 @@ - {{ props.content }} + + + + + From 68b155fb0f57a7eabd59eb7f2947ece8101edea7 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Tue, 4 Jun 2024 13:22:51 +0200 Subject: [PATCH 2/5] Update snapshots & add new unit-test Signed-off-by: Oleg Ivaniv --- .../src/components/RunDataSchemaItem.vue | 2 - .../src/components/TextWithHighlights.vue | 6 ++- .../__tests__/TextWithHIghlights.test.ts | 23 +++++++--- .../__snapshots__/RunDataJson.test.ts.snap | 46 ++++++++++++------- .../__snapshots__/RunDataSchema.test.ts.snap | 32 +++++++------ 5 files changed, 69 insertions(+), 40 deletions(-) diff --git a/packages/editor-ui/src/components/RunDataSchemaItem.vue b/packages/editor-ui/src/components/RunDataSchemaItem.vue index e2a4a87301a11..cafcfbbf17c70 100644 --- a/packages/editor-ui/src/components/RunDataSchemaItem.vue +++ b/packages/editor-ui/src/components/RunDataSchemaItem.vue @@ -121,8 +121,6 @@ const getIconBySchemaType = (type: Schema['type']): string => { /> - - - - diff --git a/packages/editor-ui/src/components/__tests__/TextWithHIghlights.test.ts b/packages/editor-ui/src/components/__tests__/TextWithHIghlights.test.ts index 555ae1dae879b..2a9207159ba6c 100644 --- a/packages/editor-ui/src/components/__tests__/TextWithHIghlights.test.ts +++ b/packages/editor-ui/src/components/__tests__/TextWithHIghlights.test.ts @@ -21,7 +21,7 @@ describe('TextWithHighlights', () => { }, }); - expect(wrapper.html()).toEqual('Test content'); + expect(wrapper.html()).toEqual('Test content'); expect(wrapper.html()).not.toContain(''); }); @@ -32,18 +32,17 @@ describe('TextWithHighlights', () => { }, }); - expect(wrapper.html()).toEqual('1'); + expect(wrapper.html()).toEqual('1'); expect(wrapper.html()).not.toContain(''); }); - it('renders correctly objects when search is not set', () => { + it('renders correctly objects when search is not set', async () => { const wrapper = shallowMount(TextWithHighlights, { props: { content: { hello: 'world' }, }, }); - - expect(wrapper.html()).toEqual('{\n "hello": "world"\n}'); + expect(wrapper.html()).toEqual('{\n "hello": "world"\n}'); expect(wrapper.html()).not.toContain(''); }); @@ -55,7 +54,7 @@ describe('TextWithHighlights', () => { }, }); - expect(wrapper.html()).toEqual('{\n "hello": "world"\n}'); + expect(wrapper.html()).toEqual('{\n "hello": "world"\n}'); expect(wrapper.html()).not.toContain(''); }); @@ -100,4 +99,16 @@ describe('TextWithHighlights', () => { 'Test content ()^${}[] world', ); }); + + it('renders new lines in the content correctly', () => { + const wrapper = shallowMount(TextWithHighlights, { + props: { + content: 'Line 1\n Line 2\nLine 3', + }, + }); + + expect(wrapper.html()).toContain( + 'Line 1\\n Line 2\\nLine 3', + ); + }); }); diff --git a/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataJson.test.ts.snap b/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataJson.test.ts.snap index 0f8242eacead8..a9dbb0f55938a 100644 --- a/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataJson.test.ts.snap +++ b/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataJson.test.ts.snap @@ -86,7 +86,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` > renders json values properly 1`] = ` > renders json values properly 1`] = ` > renders json values properly 1`] = ` > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-string" > - + "Joe" @@ -435,7 +437,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-number" > - + 123 @@ -490,7 +494,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-string" > - + "456" @@ -545,7 +551,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-string" > - + "abc" @@ -600,7 +608,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-null" > - + null @@ -655,7 +665,7 @@ exports[`RunDataJson.vue > renders json values properly 1`] = ` > renders json values properly 1`] = ` class="vjs-value vjs-value-undefined" > - + diff --git a/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataSchema.test.ts.snap b/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataSchema.test.ts.snap index 60c00cceb70c6..30dfc65e2af22 100644 --- a/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataSchema.test.ts.snap +++ b/packages/editor-ui/src/components/__tests__/__snapshots__/RunDataSchema.test.ts.snap @@ -59,7 +59,7 @@ exports[`RunDataJsonSchema.vue > renders schema for data 1`] = ` name @@ -109,7 +109,7 @@ exports[`RunDataJsonSchema.vue > renders schema for data 1`] = ` age @@ -159,7 +159,7 @@ exports[`RunDataJsonSchema.vue > renders schema for data 1`] = ` hobbies @@ -228,11 +228,13 @@ exports[`RunDataJsonSchema.vue > renders schema for data 1`] = ` fill="currentColor" /> - + hobbies [0] @@ -280,11 +282,13 @@ exports[`RunDataJsonSchema.vue > renders schema for data 1`] = ` fill="currentColor" /> - + hobbies [1] @@ -417,7 +421,7 @@ exports[`RunDataJsonSchema.vue > renders schema with spaces and dots 1`] = ` hello world @@ -486,11 +490,13 @@ exports[`RunDataJsonSchema.vue > renders schema with spaces and dots 1`] = ` fill="currentColor" /> - + hello world [0] @@ -561,7 +567,7 @@ exports[`RunDataJsonSchema.vue > renders schema with spaces and dots 1`] = ` test @@ -632,7 +638,7 @@ exports[`RunDataJsonSchema.vue > renders schema with spaces and dots 1`] = ` more to think about @@ -685,7 +691,7 @@ exports[`RunDataJsonSchema.vue > renders schema with spaces and dots 1`] = ` test.how From 678c21a14dfadac8cf295485d94cfecf3ac8bac8 Mon Sep 17 00:00:00 2001 From: Giulio Andreini Date: Tue, 4 Jun 2024 15:03:27 +0200 Subject: [PATCH 3/5] Style for line breaks in input/output views. --- packages/design-system/src/css/_tokens.dark.scss | 2 ++ packages/design-system/src/css/_tokens.scss | 2 ++ packages/editor-ui/src/components/RunDataJson.vue | 1 + packages/editor-ui/src/components/RunDataSchemaItem.vue | 5 +++-- packages/editor-ui/src/components/TextWithHighlights.vue | 5 +++-- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/design-system/src/css/_tokens.dark.scss b/packages/design-system/src/css/_tokens.dark.scss index 44ee54404f784..64ca5ed9e7158 100644 --- a/packages/design-system/src/css/_tokens.dark.scss +++ b/packages/design-system/src/css/_tokens.dark.scss @@ -114,6 +114,8 @@ --color-code-gutterBackground: var(--prim-gray-670); --color-code-gutterForeground: var(--prim-gray-320); --color-code-tags-comment: var(--prim-gray-200); + --color-line-break: var(--prim-gray-420); + --color-code-line-break: var(--prim-color-secondary-tint-100); // Variables --color-variables-usage-font: var(--prim-color-alt-a-tint-300); diff --git a/packages/design-system/src/css/_tokens.scss b/packages/design-system/src/css/_tokens.scss index 0b2940f0151e9..db2485c2080f6 100644 --- a/packages/design-system/src/css/_tokens.scss +++ b/packages/design-system/src/css/_tokens.scss @@ -146,6 +146,8 @@ --color-code-gutterBackground: var(--prim-gray-0); --color-code-gutterForeground: var(--prim-gray-320); --color-code-tags-comment: var(--prim-gray-420); + --color-line-break: var(--prim-gray-320); + --color-code-line-break: var(--prim-color-secondary-tint-200); // Variables --color-variables-usage-font: var(--color-success); diff --git a/packages/editor-ui/src/components/RunDataJson.vue b/packages/editor-ui/src/components/RunDataJson.vue index 2281cc64ba2e8..7ffc626c5c895 100644 --- a/packages/editor-ui/src/components/RunDataJson.vue +++ b/packages/editor-ui/src/components/RunDataJson.vue @@ -264,6 +264,7 @@ export default defineComponent({ From 2f70adf9e13fd6e5d0a8fe2e70397a5efc5bea69 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Mon, 10 Jun 2024 11:00:33 +0200 Subject: [PATCH 4/5] Split by new-line and replace v-html Signed-off-by: Oleg Ivaniv --- .../src/components/RunDataSchemaItem.vue | 17 ++- .../src/components/TextWithHighlights.vue | 25 ++-- .../__tests__/TextWithHIghlights.test.ts | 16 ++- .../__snapshots__/RunDataJson.test.ts.snap | 116 ++++++++++++++--- .../__snapshots__/RunDataSchema.test.ts.snap | 121 ++++++++++++++++-- 5 files changed, 234 insertions(+), 61 deletions(-) diff --git a/packages/editor-ui/src/components/RunDataSchemaItem.vue b/packages/editor-ui/src/components/RunDataSchemaItem.vue index 8bc3a99e4dd0b..315fdf9cee72b 100644 --- a/packages/editor-ui/src/components/RunDataSchemaItem.vue +++ b/packages/editor-ui/src/components/RunDataSchemaItem.vue @@ -5,7 +5,6 @@ import { checkExhaustive } from '@/utils/typeGuards'; import { shorten } from '@/utils/typesUtils'; import { getMappedExpression } from '@/utils/mappingUtils'; import TextWithHighlights from './TextWithHighlights.vue'; -import { sanitizeHtml } from '@/utils/htmlUtils'; type Props = { schema: Schema; @@ -40,14 +39,10 @@ const key = computed((): string | undefined => { const schemaName = computed(() => isSchemaParentTypeArray.value ? `${props.schema.type}[${props.schema.key}]` : props.schema.key, ); -const text = computed(() => { - if (Array.isArray(props.schema.value)) return ''; - return sanitizeHtml(shorten(props.schema.value, 600, 0)).replaceAll( - '\n', - `\\n`, - ); -}); +const text = computed(() => + Array.isArray(props.schema.value) ? '' : shorten(props.schema.value, 600, 0), +); const dragged = computed(() => props.draggingPath === props.schema.path); @@ -121,7 +116,11 @@ const getIconBySchemaType = (type: Schema['type']): string => { /> - + + + - + + + +