From 3fa92e245e1228bf36861581cb5da08d85e73a80 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 1 Feb 2025 18:32:32 -0800 Subject: [PATCH] Added a dropdown selector for envvars to enhance UX for short-input and long-input sub-blocks --- .../sub-block/components/long-input.tsx | 42 +++++- .../sub-block/components/short-input.tsx | 44 +++++- components/ui/env-var-dropdown.tsx | 137 ++++++++++++++++++ 3 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 components/ui/env-var-dropdown.tsx diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/long-input.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/long-input.tsx index f8d191f9e0..d7a9c98c26 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/long-input.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/long-input.tsx @@ -1,9 +1,10 @@ import { Textarea } from '@/components/ui/textarea' import { useSubBlockValue } from '../hooks/use-sub-block-value' import { cn } from '@/lib/utils' -import { useState, useRef, useEffect } from 'react' +import { useState, useRef } from 'react' import { SubBlockConfig } from '@/blocks/types' import { formatDisplayText } from '@/components/ui/formatted-text' +import { EnvVarDropdown, checkEnvVarTrigger } from '@/components/ui/env-var-dropdown' interface LongInputProps { placeholder?: string @@ -21,9 +22,23 @@ export function LongInput({ config, }: LongInputProps) { const [value, setValue] = useSubBlockValue(blockId, subBlockId) + const [showEnvVars, setShowEnvVars] = useState(false) + const [searchTerm, setSearchTerm] = useState('') + const [cursorPosition, setCursorPosition] = useState(0) const textareaRef = useRef(null) const overlayRef = useRef(null) + // Handle input changes + const handleChange = (e: React.ChangeEvent) => { + const newValue = e.target.value + const newCursorPosition = e.target.selectionStart ?? 0 + setValue(newValue) + setCursorPosition(newCursorPosition) + const { show, searchTerm } = checkEnvVarTrigger(newValue, newCursorPosition) + setShowEnvVars(show) + setSearchTerm(searchTerm) + } + // Sync scroll position between textarea and overlay const handleScroll = (e: React.UIEvent) => { if (overlayRef.current) { @@ -64,6 +79,13 @@ export function LongInput({ e.preventDefault() } + // Handle key combinations + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Escape') { + setShowEnvVars(false) + } + } + return (