From c3820b1f593d36b8cab45ea0633e3f96d1fc1bd1 Mon Sep 17 00:00:00 2001 From: Priyan Vaithilingam Date: Tue, 9 May 2023 10:43:46 -0400 Subject: [PATCH] sort of working CSV node -- without handles --- chain-forge/src/CsvNode.js | 74 +++++++++++++++++++++++++++++++------- chain-forge/src/index.css | 19 ++++++++++ 2 files changed, 80 insertions(+), 13 deletions(-) diff --git a/chain-forge/src/CsvNode.js b/chain-forge/src/CsvNode.js index 0cf1f2f..678b906 100644 --- a/chain-forge/src/CsvNode.js +++ b/chain-forge/src/CsvNode.js @@ -1,33 +1,81 @@ import React, { useState, useRef, useEffect, useCallback } from 'react'; -import { Card, Text} from '@mantine/core'; +import { Card, Text } from '@mantine/core'; import useStore from './store'; import NodeLabel from './NodeLabelComponent' -import { IconFileText } from '@tabler/icons-react'; +import { IconCsv, IconFileText } from '@tabler/icons-react'; import { edit } from 'ace-builds'; const CsvNode = ({ data, id }) => { const setDataPropsForNode = useStore((state) => state.setDataPropsForNode); - const content = "test content"; + const [contentDiv, setContentDiv] = useState(null); + const [fields, setFields] = useState([]); + const [isEditing, setIsEditing] = useState(false); + const processCsv = (csv) => { + // Split the input string by rows, and merge + var res = csv.split('\n').join(','); + + // remove all the empty or whitespace-only elements + return res.split(',').map(e => e.trim()).filter(e => e.length > 0); + } // Handle a change in a text fields' input. const handleInputChange = useCallback((event) => { // Update the data for this text fields' id. - let new_data = { 'text': event.target.value }; + let new_data = {'text': event.target.value}; setDataPropsForNode(id, new_data); }, [id, setDataPropsForNode]); + const handKeyDown = useCallback((event) => { + if (event.key === 'Enter') { + setIsEditing(false); + } + }, []); + + const handleDivOnClick = useCallback((event) => { + setIsEditing(true); + }, []); + + // Initialize fields (run once at init) + useEffect(() => { + if (!data.text) { + setIsEditing(true); + } + }, []); + + // when data.text changes, update the content div + useEffect(() => { + if(isEditing) { + var text_val = data.text || ''; + setContentDiv( +
+