Skip to content

Commit

Permalink
feat: added input for reading csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbignacio committed Sep 7, 2019
1 parent 3e76e93 commit b3d7403
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"classnames": "^2.2.6",
"csvtojson": "^2.0.10",
"lodash": "^4.17.15",
"prettier": "^1.18.2",
"react": "^16.9.0",
Expand Down
39 changes: 38 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import _ from "lodash";
import cn from "classnames";
import csvtojson from "csvtojson";

const onlyTakeMeaningfulTags = items =>
_.filter(items, item => ["phase:1.1", "phase:1.2", "phase:2.0", "surprise-change", "requirement-not-fixed"].includes(item));

const takeTags = _.flow([_.map, _.flatten, _.uniq, onlyTakeMeaningfulTags]);
const takeTypes = _.flow([_.map, _.flatten, _.uniq]);
const millisecondsToHours = ms => parseFloat((ms * (1 / 1000) * (1 / 60) * (1 / 60)).toFixed(3));
Expand Down Expand Up @@ -40,10 +42,24 @@ const getTaskNameList = (summationCategory, fullListItem, listItemCategoryPropNa
}, {});
};

const parseJsonObjectValues = dataObj => {
const returnObj = {};
_.forEach(dataObj, (val, key) => {
try {
const parsedValue = JSON.parse(val);
returnObj[key] = parsedValue;
} catch (e) {
returnObj[key] = val;
}
});
return returnObj;
};

function App() {
const [lastSelectedItem, setLastSelectedItem] = React.useState("");
const [clickUpData, setClickUpData] = React.useState([]);

const sortedByTimeLogged = _.sortBy(DUMMY_DATA, ["User Period Time Spent"]);
const sortedByTimeLogged = _.sortBy(clickUpData, ["User Period Time Spent"]);

const tags = takeTags(sortedByTimeLogged, item => item.Tags);
const types = takeTypes(sortedByTimeLogged, item => item.Type);
Expand All @@ -60,6 +76,27 @@ function App() {
padding: "1.25rem"
}}
>
<input
type="file"
accept="text/csv"
onChange={e => {
if (e.target.files && e.target.files[0]) {
const myFile = e.target.files[0];
const reader = new FileReader();

reader.onload = e => {
(async () => {
const csvConvertedToArr = await csvtojson().fromString(e.target.result);
const jsonParsedCsvArr = csvConvertedToArr.map(dataObj => parseJsonObjectValues(dataObj));
setClickUpData(jsonParsedCsvArr);
})();
};

reader.readAsBinaryString(myFile);
}
}}
/>

<h1>
<strong>TOTAL:</strong> {totalTime}
</h1>
Expand Down

0 comments on commit b3d7403

Please sign in to comment.