Is there a way to create a function that converts data from `DevicesType` to `GroupsType` below? Instead of having a list of devices showing the groups they belong to, I need a list of groups with their respective devices.
type DevicesType = {
id: string
name: string
status: "OK" | "FAULTY"
groups: {
id: string
name: string
}[]
}[]
type GroupsType = {
id: string
name: string
devices: {
id: string
name: string
status: "OK" | "FAULTY"
}[]
}[]
For example:
const devicesFromBackend: DevicesType = [
{
id: "d1",
name: "device 1",
status: "OK",
groups: [
{
id: "g1",
name: "group 1"
},
{
id: "g2",
name: "group 2"
}
]
},
{
id: "d2",
name: "device 2",
status: "FAULTY",
groups: [
{
id: "g2",
name: "group 2"
},
{
id: "g3",
name: "group 3"
}
]
}
];
I aim to achieve this in order to display tables for each group with a list of their corresponding devices.