From 130585a8d146db3adc39511752daac0a805059ad Mon Sep 17 00:00:00 2001 From: Emerson Lopes <24904209+emerson-d-lopes@users.noreply.github.com> Date: Wed, 22 Jul 2026 20:03:19 -0300 Subject: [PATCH 1/2] fix(pou): show return type selector for graphical function POUs The return type selector in the variables editor was gated on editor.type === 'plc-textual', so functions written in FBD, LD, or SFC had no way to select their return type even though the store action, POU creation defaults, and the ST transpiler already fully support return types for graphical functions. Extend the condition to include 'plc-graphical'. Add a component test covering the selector's visibility for FBD/LD/ST functions and its absence for programs and function blocks. Fixes #696 Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01U5TQ1y3yBEDx73tYTHoUBj --- .../__tests__/return-type-visibility.test.tsx | 47 +++++++++++++++++++ .../_organisms/variables-editor/index.tsx | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/frontend/components/_organisms/variables-editor/__tests__/return-type-visibility.test.tsx diff --git a/src/frontend/components/_organisms/variables-editor/__tests__/return-type-visibility.test.tsx b/src/frontend/components/_organisms/variables-editor/__tests__/return-type-visibility.test.tsx new file mode 100644 index 000000000..f0bdda07a --- /dev/null +++ b/src/frontend/components/_organisms/variables-editor/__tests__/return-type-visibility.test.tsx @@ -0,0 +1,47 @@ +import { render, screen } from '@testing-library/react' + +// The variables code editor pulls in Monaco, which cannot run in jsdom. +vi.mock('@root/frontend/components/_organisms/variables-code-editor', () => ({ + VariablesCodeEditor: () =>
, +})) + +import { useOpenPLCStore } from '../../../../store' +import { VariablesEditor } from '../index' + +const createPou = (name: string, type: 'program' | 'function' | 'function-block', language: 'st' | 'fbd' | 'ld') => { + const result = useOpenPLCStore.getState().pouActions.create({ type, name, language }) + expect(result.ok).toBe(true) +} + +// https://github.com/Autonomy-Logic/openplc-editor/issues/696 +describe('VariablesEditor return type selector', () => { + it('shows the return type selector for a function written in FBD', () => { + createPou('FbdFunction', 'function', 'fbd') + render() + expect(screen.getByText('Return type :')).toBeTruthy() + }) + + it('shows the return type selector for a function written in LD', () => { + createPou('LdFunction', 'function', 'ld') + render() + expect(screen.getByText('Return type :')).toBeTruthy() + }) + + it('shows the return type selector for a function written in ST', () => { + createPou('StFunction', 'function', 'st') + render() + expect(screen.getByText('Return type :')).toBeTruthy() + }) + + it('does not show the return type selector for an FBD program', () => { + createPou('FbdProgram', 'program', 'fbd') + render() + expect(screen.queryByText('Return type :')).toBeNull() + }) + + it('does not show the return type selector for an FBD function block', () => { + createPou('FbdBlock', 'function-block', 'fbd') + render() + expect(screen.queryByText('Return type :')).toBeNull() + }) +}) diff --git a/src/frontend/components/_organisms/variables-editor/index.tsx b/src/frontend/components/_organisms/variables-editor/index.tsx index e3b650e59..582cb7ecd 100644 --- a/src/frontend/components/_organisms/variables-editor/index.tsx +++ b/src/frontend/components/_organisms/variables-editor/index.tsx @@ -1052,7 +1052,7 @@ const VariablesEditor = ({ name: propName, isActive: _isActive = true }: Variabl
{editorVariables.display === 'table' && (
- {editor.type === 'plc-textual' && editor.meta.pouType === 'function' && ( + {(editor.type === 'plc-textual' || editor.type === 'plc-graphical') && editor.meta.pouType === 'function' && (