Untitled
collectionData= { "catalogId": 551, "title": "dfsdf", "description": "gsdfgsdfgdsfg", "rfiDetails": [ { "id": 23601, "questionsList": [ { "rfiId": 23601, "id": 36052, "question": "q1", "description": "d1" } ], "title": "rfi", "description": "desc", "reqDT": "2024-07-26T11:29:18.130079", "state": "IN", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "08-10-2024", "offering": "EE" }, { "id": 23651, "questionsList": [ { "rfiId": 23651, "id": 36053, "question": "ww", "description": "" } ], "title": "rfbb", "description": " bb", "reqDT": "2024-07-26T11:40:24.512873", "state": "CT", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "08-10-2024", "offering": "EE" }, { "id": 20451, "questionsList": [ { "rfiId": 20451, "id": 27151, "question": "fsdgd", "description": "" } ], "title": "fdsaf", "description": "", "reqDT": "2024-06-28T13:50:50.481233", "state": "NY", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "06-28-2024", "offering": "EE" }, { "id": 15751, "questionsList": [ { "rfiId": 15751, "id": 19151, "question": "nvmn", "description": "" } ], "title": "vmnv", "description": "", "reqDT": "2024-06-13T21:42:22.562716", "state": "NM", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "06-13-2024", "offering": "EE" }, { "id": 15801, "questionsList": [ { "rfiId": 15801, "id": 19201, "question": "dfg", "description": "gfd" } ], "title": "abc", "description": "fgdg", "reqDT": "2024-06-14T10:25:56.403095", "state": "AL", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "06-14-2024", "offering": "EE" }, { "id": 23451, "questionsList": [ { "rfiId": 23451, "id": 36003, "question": "Question 1 for AK RFI for testing attention needed", "description": "", "answers": [ { "id": 93755, "quesnId": 36003, "answer": "IL RESPONDED ", "respondDt": "2024-07-25T17:40:48.69381", "state": "IL" } ] }, { "rfiId": 23451, "id": 36004, "question": "Question 2 AK RFI for testing attention needed", "description": "", "answers": [ { "id": 93753, "quesnId": 36004, "answer": "Responded as Michigan", "respondDt": "2024-07-25T15:50:54.130178", "state": "MI" } ] }, { "rfiId": 23451, "id": 36005, "question": "Question 3 AK RFI for testing attention needed", "description": "", "answers": [ { "id": 93802, "quesnId": 36005, "answer": "gdfgdsfg", "respondDt": "2024-07-26T11:42:54.20372", "state": "NH" } ] }, { "rfiId": 23451, "id": 36006, "question": "Question 4 AK RFI for testing attention needed", "description": "", "answers": [ { "id": 93803, "quesnId": 36006, "answer": "gsdfgsdfgsdfg", "respondDt": "2024-07-26T11:43:03.513999", "state": "NV" } ] } ], "title": "AK RFI for testing attention needed", "description": "Description for AK RFI for testing attention needed", "reqDT": "2024-07-25T15:46:59.142912", "state": "AR", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "07-26-2024", "offering": "EE" }, { "id": 23501, "questionsList": [ { "rfiId": 23501, "id": 36007, "question": "Question MI", "description": "", "answers": [ { "id": 93754, "quesnId": 36007, "answer": "IL RESPONDED ", "respondDt": "2024-07-25T17:39:23.427467", "state": "IL" }, { "id": 93952, "quesnId": 36007, "answer": "", "respondDt": "2024-07-30T12:24:43.623291", "state": "CT" } ] } ], "title": "MI RFI Created Title", "description": "", "reqDT": "2024-07-25T17:05:21.534463", "state": "MI", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "07-26-2024", "offering": "EE" }, { "id": 23551, "questionsList": [ { "rfiId": 23551, "id": 36008, "question": "QUES1", "description": "" } ], "title": "IL RFI", "description": "", "reqDT": "2024-07-25T17:38:19.4079", "state": "IL", "programs": "ALL", "category": "ALL", "status": "CL", "dueDT": "07-26-2024", "offering": "EE" } ] }, Update the below code to filter out the states present in collectionData and create a list of unique states and set them using setFilteredStates const fetchStateList = (collectionData) => { const distinctStatesValues = [...new Set(collectionData.flatMap((item) => item.states))]; if (refTableContent) { const distinctStatesList = refTableContent.STATE?.filter((state) => distinctStatesValues?.includes(state.CODE), ); if (distinctStatesValues?.includes(ConstantKeys.REF_VALUE.ALL)) { distinctStatesList.push({ CODE: ConstantKeys.REF_VALUE.ALL, DESCRIPTION: ConstantKeys.CONTEXT_KEYS.ALL_LOWERCASE, }); } setFilteredStates( distinctStatesList.sort((a, b) => a.DESCRIPTION.localeCompare(b.DESCRIPTION)), ); } };
Leave a Comment