Deletion propagation implemented

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-04 11:57:42 +02:00
parent c145be02b4
commit cfe1f35226

View file

@ -346,6 +346,16 @@ function reducer(previousState, action) {
};
newState = update(previousState, change);
break;
case "HOST_DEVICES_DELETE":
change = {
hostDevices: {
[action.hostId]: {
$unset: [action.deviceIds],
},
},
};
newState = update(previousState, change);
break;
case "AUTOMATION_SAVE":
change = {
@ -496,26 +506,40 @@ function reducer(previousState, action) {
(d.fromHostId === null || d.fromHostId === undefined) && !d.deleted
);
const hostDevicesMapByHostId = allDevices
.filter((d) => d.fromHostId && !d.deleted)
.filter((d) => d.fromHostId)
.reduce((a, e) => {
const hostId = e.fromHostId;
//delete e.fromHostId;
a[hostId] = a[hostId] || [];
a[hostId].push(e);
a[hostId] = a[hostId] || { updated: [], deletedIds: [] };
if (e.deleted) {
a[hostId].deletedIds.push(e.id);
} else {
a[hostId].updated.push(e);
}
return a;
}, {});
newState = reducer(previousState, {
type: "DEVICES_UPDATE",
partial: true,
devices,
});
for (const hostId in hostDevicesMapByHostId) {
newState = reducer(newState, {
type: "HOST_DEVICES_UPDATE",
devices: hostDevicesMapByHostId[hostId],
partial: true,
hostId,
});
if (hostDevicesMapByHostId[hostId].updated.length > 0)
newState = reducer(newState, {
type: "HOST_DEVICES_UPDATE",
devices: hostDevicesMapByHostId[hostId].updated,
partial: true,
hostId,
});
if (hostDevicesMapByHostId[hostId].deletedIds.length > 0) {
newState = reducer(newState, {
type: "HOST_DEVICES_DELETE",
deviceIds: hostDevicesMapByHostId[hostId].deletedIds,
partial: true,
hostId,
});
}
}
break;
case "HG_UPDATE":