Closed daisycrego closed 3 years ago
Download CSV
. Download manager opens and the user can download a file that looks like this:
property
is represented as a JSON object. This needs to be unpacked to a bunch of columns, 1 per key. Fixed the issue of missing fields. The api I have serving all of the events data specifically sends some fields, not all of the fields, so I had to go back in and specify all the fields I wanted to select
from the Event
model:
// event.controller.js
const list = async (req, res) => {
try {
let events = await Event.find().select(
"id updated created source property status processed processedAt eventId created isNewLead isPossibleZillowExemption isZillowEvent message person personId propertyId type"
);
res.json(events);
} catch (err) {
return res.status(400).json({
error: errorHandler.getErrorMessage(err),
});
}
};
Now, we still have the issue that the person
and property
objects aren't represented correctly, even though I do try to flatten them:
const EnhancedTableToolbar = (props) => {
const classes = useToolbarStyles();
const fields = [
"processed",
"processedAt",
"status",
"_id",
"eventId",
"created",
"isNewLead",
"isPossibleZillowExemption",
"isZillowEvent",
"message",
"person",
"personId",
"property",
"propertyId",
"source",
"type",
];
const opts = { fields };
const parser = new Parser(opts);
console.log(`rows:`);
console.log(props.rows);
const flattenedRows = props.rows.flatMap((row) => flatten(row));
console.log(`flattenedRows`);
console.log(flattenedRows);
const csv = parser.parse(flattenedRows);
I need to try flattening them differently.
I fixed that problem, so now the export seems to be working most of the time. It just seems like sometimes, even though I can see that the rows are loaded, the csv returned is empty. But re-downloading another time seems to resolve that issue, so it's not huge.
Something like this might help: https://stackoverflow.com/questions/48760815/export-to-csv-button-in-react-table