JSFiddle - React, Tailwind, and code Playground
by Cristofer Sousa
JavaScript
const quarta = {
"name": "cris-quarta",
"traffic": "A2P",
"description": "teste-quarta",
"clusterProfileRulesBlock": [
{
"useCaseLabel": [
"tfa",
"re-mt-shaft"
],
"domainLabel": "banking",
"routeAction": "BLOCK"
},
{
"useCaseLabel": [
"shaft-or"
],
"domainLabel": "delivery",
"routeAction": "BLOCK"
},
{
useCaseLabel: [],
domainLabel: '',
routeAction: 'BLOCK',
},
],
"clusterProfileRulesReroute": [
{
"useCaseLabel": [
"sexual"
],
"domainLabel": "banking",
"routeAction": "REROUTE"
},
{
"useCaseLabel": [],
"domainLabel": "banking",
"routeAction": "REROUTE"
},
{
useCaseLabel: [],
domainLabel: '',
routeAction: 'REROUTE',
},
]
}
const getData = (quarta) => {
const rulesAll = quarta.clusterProfileRulesBlock.concat(quarta.clusterProfileRulesReroute);
return rulesAll.map((item) => {
if(item.domainLabel) {
if(item.useCaseLabel.length === 0) {
return { label: {...item, useCaseLabel: ''} }
}
return item.useCaseLabel.map((label) => {
// const dataRule = {
// label: {
// domainLabel: item.domainLabel,
// routeAction: item.routeAction,
// useCaseLabel: label,
// }
// }
return {label: {...item, useCaseLabel: label}}
console.log(dataRule);
})
}
}).flat().filter((item) => item );
}
getData(quarta);