diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx index 5affcbbac..a95410383 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/code.tsx @@ -13,9 +13,15 @@ interface CodeProps { blockId: string subBlockId: string isConnecting: boolean + placeholder?: string } -export function Code({ blockId, subBlockId, isConnecting }: CodeProps) { +export function Code({ + blockId, + subBlockId, + isConnecting, + placeholder = 'Write JavaScript...', +}: CodeProps) { // State management const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlockId) const [code, setCode] = useState('') @@ -201,7 +207,7 @@ export function Code({ blockId, subBlockId, isConnecting }: CodeProps) { > {code.length === 0 && (
- Write JavaScript... + {placeholder}
)} diff --git a/app/w/[id]/components/workflow-block/components/sub-block/components/table.tsx b/app/w/[id]/components/workflow-block/components/sub-block/components/table.tsx index c89ea9e07..0849fa8f6 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/components/table.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/components/table.tsx @@ -18,39 +18,10 @@ interface TableRow { export function Table({ columns, blockId, subBlockId }: TableProps) { const [value, setValue] = useSubBlockValue(blockId, subBlockId) - const activePositionRef = useRef<{ rowIndex: number; column: string } | null>(null) - const inputRefs = useRef>(new Map()) - - useEffect(() => { - if (activePositionRef.current && document.activeElement === document.body) { - const { rowIndex, column } = activePositionRef.current - const input = document.querySelector( - `input[data-row="${rowIndex}"][data-column="${column}"]` - ) as HTMLInputElement - if (input) { - input.focus() - } - } - }) - - // Add new useEffect for handling input scrolling - useEffect(() => { - if (activePositionRef.current) { - const { rowIndex, column } = activePositionRef.current - const key = `${rowIndex}-${column}` - const input = inputRefs.current.get(key) - - if (input) { - const scrollPosition = (input.selectionStart ?? 0) * 8 - input.scrollLeft = scrollPosition - input.offsetWidth / 2 - } - } - }, [value]) // Ensure value is properly typed and initialized const rows = useMemo(() => { if (!Array.isArray(value)) { - // Initialize with a single empty row if value is null or invalid return [ { id: crypto.randomUUID(), @@ -71,7 +42,6 @@ export function Table({ columns, blockId, subBlockId }: TableProps) { : row ) - // Add new row if typing in the last row if (rowIndex === rows.length - 1 && value !== '') { updatedRows.push({ id: crypto.randomUUID(), @@ -83,73 +53,65 @@ export function Table({ columns, blockId, subBlockId }: TableProps) { } const handleDeleteRow = (rowIndex: number) => { - if (rows.length === 1) return // Don't delete if it's the last row + if (rows.length === 1) return setValue(rows.filter((_, index) => index !== rowIndex)) } + const renderHeader = () => ( + + + {columns.map((column, index) => ( + + {column} + + ))} + + + ) + + const renderCell = (row: TableRow, rowIndex: number, column: string, cellIndex: number) => ( + + handleCellChange(rowIndex, column, e.target.value)} + className="border-0 focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground placeholder:text-muted-foreground/50" + /> + + ) + + const renderDeleteButton = (rowIndex: number) => + rows.length > 1 && ( + + + + ) + return (
- - - {columns.map((column, index) => ( - - ))} - - + {renderHeader()} {rows.map((row, rowIndex) => ( - {columns.map((column, cellIndex) => ( - - ))} - {rows.length > 1 && ( - - )} + {columns.map((column, cellIndex) => renderCell(row, rowIndex, column, cellIndex))} + {renderDeleteButton(rowIndex)} ))} diff --git a/app/w/[id]/components/workflow-block/components/sub-block/sub-block.tsx b/app/w/[id]/components/workflow-block/components/sub-block/sub-block.tsx index 774dc034f..59841f03c 100644 --- a/app/w/[id]/components/workflow-block/components/sub-block/sub-block.tsx +++ b/app/w/[id]/components/workflow-block/components/sub-block/sub-block.tsx @@ -69,7 +69,14 @@ export function SubBlock({ blockId, config, isConnecting }: SubBlockProps) { case 'table': return
- {column} -
- { - if (el) { - inputRefs.current.set(`${rowIndex}-${column}`, el) - } else { - inputRefs.current.delete(`${rowIndex}-${column}`) - } - }} - data-row={rowIndex} - data-column={column} - value={row.cells[column] || ''} - placeholder={column} - onChange={(e) => handleCellChange(rowIndex, column, e.target.value)} - onFocus={() => { - activePositionRef.current = { rowIndex, column } - }} - onSelect={(e) => { - const input = e.currentTarget - const scrollPosition = (input.selectionStart ?? 0) * 8 - input.scrollLeft = scrollPosition - input.offsetWidth / 2 - }} - className="border-0 focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground placeholder:text-muted-foreground/50 allow-scroll" - /> - - -
case 'code': - return + return ( + + ) case 'switch': return case 'tool-input': diff --git a/blocks/blocks/api.ts b/blocks/blocks/api.ts index 1871fc951..969a4ef7f 100644 --- a/blocks/blocks/api.ts +++ b/blocks/blocks/api.ts @@ -24,6 +24,13 @@ export const ApiBlock: BlockConfig = { layout: 'half', options: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], }, + { + id: 'params', + title: 'Query Params', + type: 'table', + layout: 'full', + columns: ['Key', 'Value'], + }, { id: 'headers', title: 'Headers', @@ -36,6 +43,7 @@ export const ApiBlock: BlockConfig = { title: 'Body', type: 'code', layout: 'full', + placeholder: 'Enter JSON...', }, ], tools: {