Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): Harmonize rendering of new-lines in RunData #9614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/design-system/src/css/_tokens.dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/design-system/src/css/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/components/RunDataJson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export default defineComponent({
<style lang="scss">
.vjs-tree {
color: var(--color-json-default);
--color-line-break: var(--color-code-line-break);
}

.vjs-tree-node {
Expand Down
13 changes: 12 additions & 1 deletion packages/editor-ui/src/components/RunDataSchemaItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const key = computed((): string | undefined => {
const schemaName = computed(() =>
isSchemaParentTypeArray.value ? `${props.schema.type}[${props.schema.key}]` : props.schema.key,
);

const text = computed(() =>
Array.isArray(props.schema.value) ? '' : shorten(props.schema.value, 600, 0),
);
Expand Down Expand Up @@ -114,7 +115,11 @@ const getIconBySchemaType = (type: Schema['type']): string => {
/>
</span>
</div>
<span v-if="text" :class="$style.text">{{ text }}</span>
<span v-if="text" :class="$style.text">
<template v-for="(line, index) in text.split('\n')" :key="`line-${index}`">
<span v-if="index > 0" :class="$style.newLine">\n</span>{{ line }}
</template>
</span>
<input v-if="level > 0 && isSchemaValueArray" :id="subKey" type="checkbox" checked />
<label v-if="level > 0 && isSchemaValueArray" :class="$style.toggle" :for="subKey">
<font-awesome-icon icon="angle-up" />
Expand Down Expand Up @@ -286,6 +291,12 @@ const getIconBySchemaType = (type: Schema['type']): string => {
font-size: var(--font-size-2xs);
overflow: hidden;
word-break: break-word;

.newLine {
font-family: var(--font-family-monospace);
color: var(--color-line-break);
padding-right: 2px;
}
}

.toggle {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/RunDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export default defineComponent({
return this.$locale.baseText('runData.emptyString');
}
if (typeof value === 'string') {
return value.replaceAll('\n', '\\n');
return value;
}
if (Array.isArray(value) && value.length === 0) {
return this.$locale.baseText('runData.emptyArray');
Expand Down
17 changes: 16 additions & 1 deletion packages/editor-ui/src/components/TextWithHighlights.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@ const parts = computed(() => {
<span v-else-if="part.content" :key="`span-${index}`">{{ part.content }}</span>
</template>
</span>
<span v-else>{{ props.content }}</span>
<span v-else :class="$style.content">
<template v-if="typeof props.content === 'string'">
<span v-for="(line, index) in props.content.split('\n')" :key="`line-${index}`">
<span v-if="index > 0" :class="$style.newLine">\n</span>{{ line }}
</span>
</template>
<span v-else v-text="props.content" />
</span>
</template>

<style lang="scss" module>
:root .content .newLine {
font-family: var(--font-family-monospace);
color: var(--color-line-break);
padding-right: 2px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('TextWithHighlights', () => {
},
});

expect(wrapper.html()).toEqual('<span>Test content</span>');
expect(wrapper.html()).toEqual(
'<span class="content"><span><!--v-if-->Test content</span></span>',
);
expect(wrapper.html()).not.toContain('<mark>');
});

Expand All @@ -32,18 +34,19 @@ describe('TextWithHighlights', () => {
},
});

expect(wrapper.html()).toEqual('<span>1</span>');
expect(wrapper.html()).toEqual('<span class="content"><span>1</span></span>');
expect(wrapper.html()).not.toContain('<mark>');
});

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('<span>{\n "hello": "world"\n}</span>');
expect(wrapper.html()).toEqual(
'<span class="content"><span>{\n "hello": "world"\n}</span></span>',
);
expect(wrapper.html()).not.toContain('<mark>');
});

Expand All @@ -55,7 +58,9 @@ describe('TextWithHighlights', () => {
},
});

expect(wrapper.html()).toEqual('<span>{\n "hello": "world"\n}</span>');
expect(wrapper.html()).toEqual(
'<span class="content"><span>{\n "hello": "world"\n}</span></span>',
);
expect(wrapper.html()).not.toContain('<mark>');
});

Expand Down Expand Up @@ -100,4 +105,16 @@ describe('TextWithHighlights', () => {
'<span><span>Test content </span><mark>()^${}[]</mark><span> world</span></span>',
);
});

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(
'<span class="content"><span><!--v-if-->Line 1</span><span><span class="newLine">\\n</span> Line 2</span><span><span class="newLine">\\n</span>Line 3</span></span>',
);
});
});
Loading
Loading