I am using react-json-to-csv and stateless functional components to make a search function that can create spreadsheets based on the results. I have a set of filters that applies which fields are visible in the mapped array being passed through props into the array items. So what I need is on the functional component object, using the stream of prospects and the boolean restrictions to physically create a new array of objects that effectively mirrors what is being displayed in the map with the restricted fields.
so if the map looks like this
{prospects !== []
? prospects.map((prospect) => (
<ProspectItem
key={prospect._id}
prospect={prospect}
prosp={prosp}
/>
))
: ""}
where prosp is boolean object structured like this
{
showField:false,
filterField:false,
}
so basically I need some sort of forEach or filter or map which is the array currently being represented in the map.
the code I started with looks something like this
const keys = Object.keys(prosp).filter((k) => prosp[k]);
const r = prospects.filter(
(prospect) => !keys.find((key) => (key = "showCreateDate")) && prospect.createDate
);
this returns the entire prospect object in an array, so i feel like this something in the right direction as long as keys which is an array of string values where showField is true.
address2: ""
amount: "$25,000.00"
availableCredit: ""
caseWorkers: {originators: Array(0), loanProcessors: Array(0), documentProcessors: Array(0), upsells: Array(0), federalReso: Array(0), …}
city2: ""
compliant: "filed"
cpa: "cpa"
createDate: "2020-07-17T07:00:00.000Z"
email2: ""
email3: ""
employerName: ""
employerPhone: ""
employerTime: ""
family: []
files: []
filingStatus: "married"
fullName: "Steven Berardinelli"
home: ""
homePay: ""
income1Type: ""
income1Value: ""
income2Type: ""
income2Value: ""
income3Type: ""
income3Value: ""
lexId: ""
lienid: "5f065bf316d5951988e5e7c0"
name2: ""
notes: []
otherIncomeType: ""
otherIncomeValue: ""
paymentMethods: []
paymentSchedule: (2) [{…}, {…}]
paymentStatus: {balance: 5000, gross: 10000, initial: 5000, initialPaymentDate: "2020-07-17T07:00:00.000Z", lastPayment: 5000, …}
pdfs: []
phone: ""
phone2: ""
phone3: ""
pinCode: "202773"
prac: ""
problem1: ""
problem2: ""
problem3: ""
relation: ""
resSold: ""
resSold2: ""
resoStatus: {representation: Array(2), federalFile: Array(2), stateFile: Array(0), hardship: Array(0), paymentPlan: Array(0), …}
ssn: ""
ssn2: ""
state2: ""
status: "[object Object]"
totalCredit: ""
wages: ""
zip2: ""
__v: 0
_id: "5f11c137ddf8531a90996a61"
__proto__: Object