From ce1deb8aea528eef996fc774d0fff1dc61df5843 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Mon, 3 Feb 2025 08:50:24 +0100 Subject: [PATCH] fix(editor): Make AI transform node read only in executions view (#12970) --- .../ButtonParameter/ButtonParameter.test.ts | 15 ++++-- .../ButtonParameter/ButtonParameter.vue | 47 ++++++++++--------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.test.ts b/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.test.ts index ba5070e3356..52648212327 100644 --- a/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.test.ts +++ b/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { mount } from '@vue/test-utils'; import { createTestingPinia } from '@pinia/testing'; -import ButtonParameter from '@/components/ButtonParameter/ButtonParameter.vue'; +import ButtonParameter, { type Props } from '@/components/ButtonParameter/ButtonParameter.vue'; import { useNDVStore } from '@/stores/ndv.store'; import { useWorkflowsStore } from '@/stores/workflows.store'; import { usePostHog } from '@/stores/posthog.store'; @@ -20,7 +20,7 @@ vi.mock('@/composables/useI18n'); vi.mock('@/composables/useToast'); describe('ButtonParameter', () => { - const defaultProps = { + const defaultProps: Props = { parameter: { name: 'testParam', displayName: 'Test Parameter', @@ -38,6 +38,7 @@ describe('ButtonParameter', () => { }, } as INodeProperties, value: '', + isReadOnly: false, path: 'testPath', }; @@ -78,9 +79,9 @@ describe('ButtonParameter', () => { } as any); }); - const mountComponent = (props = defaultProps) => { + const mountComponent = (props: Partial = {}) => { return mount(ButtonParameter, { - props, + props: { ...defaultProps, ...props }, global: { plugins: [createTestingPinia()], }, @@ -134,4 +135,10 @@ describe('ButtonParameter', () => { expect(useToast().showMessage).toHaveBeenCalled(); }); + + it('disables input and button when in read only mode', async () => { + const wrapper = mountComponent({ isReadOnly: true }); + expect(wrapper.find('textarea').attributes('disabled')).toBeDefined(); + expect(wrapper.find('button').attributes('disabled')).toBeDefined(); + }); }); diff --git a/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.vue b/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.vue index a28b68d3dd3..e10933bd19a 100644 --- a/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.vue +++ b/packages/editor-ui/src/components/ButtonParameter/ButtonParameter.vue @@ -14,7 +14,6 @@ import { getTextareaCursorPosition, } from './utils'; import { useTelemetry } from '@/composables/useTelemetry'; -import { useUIStore } from '@/stores/ui.store'; import { propertyNameFromExpression } from '../../utils/mappingUtils'; @@ -24,11 +23,13 @@ const emit = defineEmits<{ valueChanged: [value: IUpdateInformation]; }>(); -const props = defineProps<{ +export type Props = { parameter: INodeProperties; value: string; path: string; -}>(); + isReadOnly?: boolean; +}; +const props = defineProps(); const { activeNode } = useNDVStore(); @@ -48,8 +49,7 @@ const buttonLabel = computed( () => props.parameter.typeOptions?.buttonConfig?.label ?? props.parameter.displayName, ); const isSubmitEnabled = computed(() => { - if (!hasExecutionData.value) return false; - if (!prompt.value) return false; + if (!hasExecutionData.value || !prompt.value || props.isReadOnly) return false; const maxlength = inputFieldMaxLength.value; if (maxlength && prompt.value.length > maxlength) return false; @@ -156,16 +156,6 @@ function onPromptInput(inputValue: string) { }); } -function useDarkBackdrop(): string { - const theme = useUIStore().appliedTheme; - - if (theme === 'light') { - return 'background-color: var(--color-background-xlight);'; - } else { - return 'background-color: var(--color-background-light);'; - } -} - onMounted(() => { parentNodes.value = getParentNodes(); }); @@ -213,8 +203,11 @@ async function updateCursorPositionOnMouseMove(event: MouseEvent, activeDrop: bo color="text-dark" > -
-
+
+