From 1eee1c1d11123b99c0c4c66b8c4db7fea8f7a942 Mon Sep 17 00:00:00 2001 From: Priyan Vaithilingam Date: Fri, 5 May 2023 16:10:13 -0400 Subject: [PATCH 1/8] DO NOT MERGE TO MAIN.. WIP --- .gitignore | 3 ++- chain-forge/src/App.css | 5 +++++ chain-forge/src/App.js | 10 +++++++++- chain-forge/src/CsvNode.js | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 chain-forge/src/CsvNode.js diff --git a/.gitignore b/.gitignore index 017cae5..903297f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ __pycache__ python-backend/cache # venv -venv \ No newline at end of file +venv +node_modules diff --git a/chain-forge/src/App.css b/chain-forge/src/App.css index 6071c72..47b2fab 100644 --- a/chain-forge/src/App.css +++ b/chain-forge/src/App.css @@ -45,3 +45,8 @@ path.react-flow__edge-path:hover { transform: rotate(360deg); } } + +.rich-editor { + min-width: 500px; + min-height: 500px; +} \ No newline at end of file diff --git a/chain-forge/src/App.js b/chain-forge/src/App.js index 50698a2..72c8725 100644 --- a/chain-forge/src/App.js +++ b/chain-forge/src/App.js @@ -15,6 +15,7 @@ import EvaluatorNode from './EvaluatorNode'; import VisNode from './VisNode'; import InspectNode from './InspectorNode'; import ScriptNode from './ScriptNode'; +import CsvNode from './CsvNode'; import './text-fields-node.css'; // State management (from https://reactflow.dev/docs/guides/state-management/) @@ -40,7 +41,8 @@ const nodeTypes = { evaluator: EvaluatorNode, vis: VisNode, inspect: InspectNode, - script: ScriptNode + script: ScriptNode, + csv: CsvNode, }; const connectionLineStyle = { stroke: '#ddd' }; @@ -91,6 +93,11 @@ const App = () => { addNode({ id: 'scriptNode-'+Date.now(), type: 'script', data: {}, position: {x: x-200, y:y-100} }); }; + const addCsvNode = (event) => { + const { x, y } = getViewportCenter(); + addNode({ id: 'csvNode-'+Date.now(), type: 'csv', data: {}, position: {x: x-200, y:y-100} }); + }; + /** * SAVING / LOADING, IMPORT / EXPORT (from JSON) */ @@ -201,6 +208,7 @@ const App = () => { + diff --git a/chain-forge/src/CsvNode.js b/chain-forge/src/CsvNode.js new file mode 100644 index 0000000..0cf1f2f --- /dev/null +++ b/chain-forge/src/CsvNode.js @@ -0,0 +1,35 @@ +import React, { useState, useRef, useEffect, useCallback } from 'react'; +import { Card, Text} from '@mantine/core'; +import useStore from './store'; +import NodeLabel from './NodeLabelComponent' +import { IconFileText } from '@tabler/icons-react'; +import { edit } from 'ace-builds'; + +const CsvNode = ({ data, id }) => { + const setDataPropsForNode = useStore((state) => state.setDataPropsForNode); + const content = "test content"; + + + // 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 }; + setDataPropsForNode(id, new_data); + }, [id, setDataPropsForNode]); + + return ( +
+ } /> + + + + With Fjord Tours you can explore more of the magical fjord landscapes with tours and + activities on and around the fjords of Norway + + + +
+ ); +}; + +export default CsvNode; \ No newline at end of file From c3820b1f593d36b8cab45ea0633e3f96d1fc1bd1 Mon Sep 17 00:00:00 2001 From: Priyan Vaithilingam Date: Tue, 9 May 2023 10:43:46 -0400 Subject: [PATCH 2/8] 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( +
+