diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts index 2071ddcf2b..62660e9d32 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.test.ts @@ -11,7 +11,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -35,7 +35,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -59,7 +59,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -83,7 +83,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -107,7 +107,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -131,7 +131,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -155,7 +155,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -179,7 +179,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -203,7 +203,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -227,7 +227,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '

{{text}}

', + template: '

', }, { props: { @@ -242,4 +242,32 @@ describe('Directive n8n-truncate', () => { ); expect(html()).toBe('

42.12

'); }); + + it('rendered html should update when the value changes', async () => { + const { html, rerender } = render( + { + props: { + text: { + type: String, + }, + }, + template: '

', + }, + { + props: { + text: '42.12', + }, + global: { + directives: { + n8nSmartDecimal, + }, + }, + }, + ); + expect(html()).toBe('

42.12

'); + + await rerender({ text: '12.42' }); + + expect(html()).toBe('

12.42

'); + }); }); diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts index 13f4e72b89..93d33de77a 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-smart-decimal.ts @@ -8,12 +8,12 @@ import type { DirectiveBinding, FunctionDirective } from 'vue'; * In your Vue template, use the directive `v-n8n-smart-decimal` passing the number and optionally the decimal places. * * Example: - *

42.567

+ *

* * Compiles to:

42.57

* * Example with specified decimal places: - *

42.56789

+ *

* * Compiles to:

42.5679

* @@ -28,7 +28,7 @@ export const n8nSmartDecimal: FunctionDirective = ( el: HTMLElement, binding: DirectiveBinding, ) => { - const value = parseFloat(el.textContent ?? ''); + const value = parseFloat(binding.value?.toString() ?? ''); if (!isNaN(value)) { const decimals = isNaN(Number(binding.arg)) ? undefined : Number(binding.arg); const formattedValue = smartDecimal(value, decimals); diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.test.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.test.ts index 309cab4563..5377d2ee07 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.test.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.test.ts @@ -11,7 +11,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '
', }, { props: { @@ -35,7 +35,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '
', }, { props: { @@ -59,7 +59,7 @@ describe('Directive n8n-truncate', () => { type: String, }, }, - template: '
{{text}}
', + template: '
', }, { props: { @@ -74,4 +74,32 @@ describe('Directive n8n-truncate', () => { ); expect(html()).toBe('
This is a very long text ...
'); }); + + it('rendered html should update when the value changes', async () => { + const { html, rerender } = render( + { + props: { + text: { + type: String, + }, + }, + template: '
', + }, + { + props: { + text: 'This is a very long text that should be truncated', + }, + global: { + directives: { + n8nTruncate, + }, + }, + }, + ); + expect(html()).toBe('
This is a very long text ...
'); + + await rerender({ text: 'new text to truncate that should be truncated' }); + + expect(html()).toBe('
new text to truncate that...
'); + }); }); diff --git a/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.ts b/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.ts index b4b932aaec..0cd20f84f5 100644 --- a/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.ts +++ b/packages/frontend/@n8n/design-system/src/directives/n8n-truncate.ts @@ -1,5 +1,5 @@ import { truncate } from '@n8n/utils/string/truncate'; -import type { DirectiveBinding, ObjectDirective } from 'vue'; +import type { DirectiveBinding, FunctionDirective } from 'vue'; /** * Custom directive `n8nTruncate` to truncate text content of an HTML element. @@ -8,7 +8,7 @@ import type { DirectiveBinding, ObjectDirective } from 'vue'; * In your Vue template, use the directive `v-n8n-truncate` with an argument to specify the length to truncate to. * * Example: - *

Some long text that will be truncated

+ *

* * This will truncate the text content of the paragraph to 10 characters. * @@ -16,11 +16,11 @@ import type { DirectiveBinding, ObjectDirective } from 'vue'; * https://vuejs.org/guide/reusability/custom-directives#usage-on-components */ -export const n8nTruncate: ObjectDirective = { - mounted(el: HTMLElement, binding: DirectiveBinding) { - el.textContent = truncate(el.textContent ?? '', Number(binding.arg) || undefined); - }, - updated(el: HTMLElement, binding: DirectiveBinding) { - el.textContent = truncate(el.textContent ?? '', Number(binding.arg) || undefined); - }, +export const n8nTruncate: FunctionDirective = ( + el: HTMLElement, + binding: DirectiveBinding, +) => { + if (binding.value !== binding.oldValue) { + el.textContent = truncate(binding.value ?? '', Number(binding.arg) || undefined); + } }; diff --git a/packages/frontend/editor-ui/src/components/Projects/ProjectCardBadge.vue b/packages/frontend/editor-ui/src/components/Projects/ProjectCardBadge.vue index c640297ca7..48e4cbb1e6 100644 --- a/packages/frontend/editor-ui/src/components/Projects/ProjectCardBadge.vue +++ b/packages/frontend/editor-ui/src/components/Projects/ProjectCardBadge.vue @@ -161,9 +161,9 @@ const projectLocation = computed(() => { > - {{ badgeText }} + - {{ badgeText }} +