Deletion propagation implemented
This commit is contained in:
parent
c145be02b4
commit
cfe1f35226
1 changed files with 33 additions and 9 deletions
|
@ -346,6 +346,16 @@ function reducer(previousState, action) {
|
||||||
};
|
};
|
||||||
newState = update(previousState, change);
|
newState = update(previousState, change);
|
||||||
break;
|
break;
|
||||||
|
case "HOST_DEVICES_DELETE":
|
||||||
|
change = {
|
||||||
|
hostDevices: {
|
||||||
|
[action.hostId]: {
|
||||||
|
$unset: [action.deviceIds],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
newState = update(previousState, change);
|
||||||
|
break;
|
||||||
|
|
||||||
case "AUTOMATION_SAVE":
|
case "AUTOMATION_SAVE":
|
||||||
change = {
|
change = {
|
||||||
|
@ -496,26 +506,40 @@ function reducer(previousState, action) {
|
||||||
(d.fromHostId === null || d.fromHostId === undefined) && !d.deleted
|
(d.fromHostId === null || d.fromHostId === undefined) && !d.deleted
|
||||||
);
|
);
|
||||||
const hostDevicesMapByHostId = allDevices
|
const hostDevicesMapByHostId = allDevices
|
||||||
.filter((d) => d.fromHostId && !d.deleted)
|
.filter((d) => d.fromHostId)
|
||||||
.reduce((a, e) => {
|
.reduce((a, e) => {
|
||||||
const hostId = e.fromHostId;
|
const hostId = e.fromHostId;
|
||||||
//delete e.fromHostId;
|
//delete e.fromHostId;
|
||||||
a[hostId] = a[hostId] || [];
|
a[hostId] = a[hostId] || { updated: [], deletedIds: [] };
|
||||||
a[hostId].push(e);
|
if (e.deleted) {
|
||||||
|
a[hostId].deletedIds.push(e.id);
|
||||||
|
} else {
|
||||||
|
a[hostId].updated.push(e);
|
||||||
|
}
|
||||||
return a;
|
return a;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
newState = reducer(previousState, {
|
newState = reducer(previousState, {
|
||||||
type: "DEVICES_UPDATE",
|
type: "DEVICES_UPDATE",
|
||||||
partial: true,
|
partial: true,
|
||||||
devices,
|
devices,
|
||||||
});
|
});
|
||||||
for (const hostId in hostDevicesMapByHostId) {
|
for (const hostId in hostDevicesMapByHostId) {
|
||||||
newState = reducer(newState, {
|
if (hostDevicesMapByHostId[hostId].updated.length > 0)
|
||||||
type: "HOST_DEVICES_UPDATE",
|
newState = reducer(newState, {
|
||||||
devices: hostDevicesMapByHostId[hostId],
|
type: "HOST_DEVICES_UPDATE",
|
||||||
partial: true,
|
devices: hostDevicesMapByHostId[hostId].updated,
|
||||||
hostId,
|
partial: true,
|
||||||
});
|
hostId,
|
||||||
|
});
|
||||||
|
if (hostDevicesMapByHostId[hostId].deletedIds.length > 0) {
|
||||||
|
newState = reducer(newState, {
|
||||||
|
type: "HOST_DEVICES_DELETE",
|
||||||
|
deviceIds: hostDevicesMapByHostId[hostId].deletedIds,
|
||||||
|
partial: true,
|
||||||
|
hostId,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "HG_UPDATE":
|
case "HG_UPDATE":
|
||||||
|
|
Loading…
Reference in a new issue