import React, { useState } from "react"; import { Separator } from "../separator.js"; export function DataSetChanger({ onChangeOfDataset, show, listOfElements }) { /*let [value, setValue] = useState(`[ { "name": "Some element. The name field is necessary", "url": "http://www.example.com", "somethirdfield": "a" }, { "name": "Another element", "url": "http://www.example1.com", "somethirdfield": "b" }, { "name": "A third element", "url": "http://www.example2.com", "isReferenceValue": true, "somethirdfield": "c" } ]`);*/ let [value, setValue] = useState(JSON.stringify(listOfElements, null, 4)); const [displayingDoneMessage, setDisplayingDoneMessage] = useState(false); const [displayingDoneMessageTimer, setDisplayingDoneMessageTimer] = useState(null); let handleChange = (event) => { setValue(event.target.value); }; let handleSubmitInner = (event) => { clearTimeout(displayingDoneMessageTimer); event.preventDefault(); console.log("value@handleSubmitInner@DataSetChanger"); console.log(value); try { let newData = JSON.parse(value); if (!newData.length || newData.length < 2) { throw Error("Not enough objects"); } onChangeOfDataset(newData); setDisplayingDoneMessage(true); let timer = setTimeout(() => setDisplayingDoneMessage(false), 3000); setDisplayingDoneMessageTimer(timer); } catch (error) { setDisplayingDoneMessage(false); alert(error); } }; return (