I have got two arrays of objects. I want to filter data based on permissionObj.
This is coming from database. Here are arrays of sub-arrays in the permissionObj.
let permissionObj = [
{
"Deposit": [{
label: "can create",
value: "can_create"
},
]
},
{
"Journals": [{
label: "can create",
value: "can_create"
}]
},
{
"Dashboard": [{
label: "can view",
value: "can_view"
}]
},
]
this is static data. I want to compare this data based on permission.
const PubSidebar = [{
label: "Dashboard",
value: "can_view"
},
{
label: "OA deal",
content: [
{
label: "Deposit",
key: "Deposit",
value: "can_view"
},
{
label: "Corrections",
key: "Corrections",
value: "can_edit"
},
]
},
{
label: "Journal",
content: [{
label: "Add Journal",
key: "Journals",
value: "can_create"
},
]
},
];
Here is my PubSidebar , I need three types of filtering - if pubSidebar array of Objects then it will be filtering based on label.For examaple, Dashboard - if pubSidebar array of sub-array of objects, then filtering will be based label, key and value , For example, PermissionObj key: will be property name such as OA deal, Deposit, value : can_view or anything
My expected output would be :
const PubSidebar = [{
label: "Dashboard",
value: "can_view"
},
{
label: "OA deal",
content: [
{
label: "edit oadeal ",
key: "OA deal",
value: "can_edit"
},
{
label: "Deposit",
key: "Deposit",
value: "can_view"
},
]
},
{
label: "Journal",
content: [{
label: "Add Journal",
key: "Journals",
value: "can_create"
},
]
},
];