diff --git a/package-lock.json b/package-lock.json index 76c8ed8..427eb02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4800,6 +4800,11 @@ } } }, + "csv-parse": { + "version": "4.16.0", + "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-4.16.0.tgz", + "integrity": "sha512-Zb4tGPANH4SW0LgC9+s9Mnequs9aqn7N3/pCqNbVjs2XhEF6yWNU2Vm4OGl1v2Go9nw8rXt87Cm2QN/o6Vpqgg==" + }, "cyclist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz", diff --git a/package.json b/package.json index 195dd99..0068740 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "axios": "^0.21.1", + "csv-parse": "^4.16.0", "express": "^4.17.1", "gh-pages": "^3.2.3", "react": "^17.0.2", diff --git a/src/App.js b/src/App.js index 48a91cc..ec12d13 100644 --- a/src/App.js +++ b/src/App.js @@ -19,6 +19,7 @@ import TestHeader from './TestHeader'; // Test Header! import TestPanel from './TestPanel'; // Dudley's Test Panel const axios = require('axios'); +const parse = require('csv-parse/lib/sync') const BACKEND_URL = process.env.REACT_APP_GITPOD_WORKSPACE_URL||process.env.REACT_APP_BACKEND_URL||'https://projectdivar.com:4504'; //You can specify a .env file locally with REACT_APP_BACKEND_URL defining a URL to retrieve data from. @@ -428,6 +429,9 @@ function TableEditor(p) { const [submitVals,setSubmitVal] = useReducer(updateVals,initialVals) const [loading,setLoading] = useState(false) const [dependencies,setDependencies] = useState([]) + const [importAllowed,setImportAllowed] = useState(false) + const [fileData,setFileData] = useState(undefined) + const [debugMessage,setDebugMessage] = useState("") function SubmitBoxes() { axios.post(BACKEND_URL+p.path,submitVals) @@ -447,6 +451,26 @@ function TableEditor(p) { useEffect(()=>{ setUpdate(true) },[p.path]) + + useEffect(()=>{ + var promises=[] + parse(fileData,{columns:true,skip_empty_lines:true}).forEach((entry)=>{ + promises.push(axios.post(BACKEND_URL+p.path,entry)) + }) + Promise.allSettled(promises) + .then(()=>{ + setUpdate(true) + }) + },[fileData]) + + useEffect(()=>{ + for (var col of fields) { + if (col.name==="name") { + setImportAllowed(true) + break; + } + } + },[fields]) useEffect(()=>{ if (update) { @@ -482,6 +506,14 @@ function TableEditor(p) { {!loading?
diff --git a/src/style.css b/src/style.css index 1b780ef..ed5b9f0 100644 --- a/src/style.css +++ b/src/style.css @@ -946,4 +946,9 @@ button{ p.adminNav hr { border-bottom: 1px solid white; margin: 10px 0; +} +.buttonLabel{ + border: 2px solid black; + background:white; + color:black; } \ No newline at end of file |
---|