I'm trying to dyamically export a CSV to an S3 depending on the columns the user picks. I have a few nested objects, and arrays, and I'm having a hard time to use it with flatten. basically I'm doing this:
const common = (name: keyof Data.CitizenDataSetMixin) => (d: Data.CitizenDataSet, field: any, meh: any) => {
let value = _.get(d, name, '')
switch (name) {
/* do some value transforms here */
}
return value/**/
}
const csv = await bluebird.fromCallback<string>((resolve) => {
json2csv<Data.CitizenDataSetMixin>({
data,
fields: selected.map((field: keyof Data.CitizenDataSetMixin) => {
return {
label: Data.CitizenFieldGuard[field] || field,
value: common(field)
}
}),
...defaultCSVOptions
}, resolve)
})
the problem is that I have some paths that turns out as phone.0.value or documents.1.type, and since it's dynamic (some rows doesn't have all the information), I'm having a hard time 'translating' the paths before hand. I really don't want to transverse all the items and collecting their max number for each dynamic column to find out how to set the name (like transform document field chosen by the user to document.0.type, document.1.type, and so on). so I was thinking to passing some extra meta data, but having no idea how to even make a PR to implement this
I'm trying to dyamically export a CSV to an S3 depending on the columns the user picks. I have a few nested objects, and arrays, and I'm having a hard time to use it with
flatten
. basically I'm doing this:the problem is that I have some paths that turns out as
phone.0.value
ordocuments.1.type
, and since it's dynamic (some rows doesn't have all the information), I'm having a hard time 'translating' the paths before hand. I really don't want to transverse all the items and collecting their max number for each dynamic column to find out how to set the name (like transformdocument
field chosen by the user todocument.0.type
,document.1.type
, and so on). so I was thinking to passing some extra meta data, but having no idea how to even make a PR to implement this