From 8be89121aa17e362219b8fb3f129ebdbfe307bca Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 25 Sep 2020 23:11:32 -0700 Subject: [PATCH] Fix re-rendering of devices when they go offline. --- Server/wwwroot/src/Main/DataGrid.ts | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Server/wwwroot/src/Main/DataGrid.ts b/Server/wwwroot/src/Main/DataGrid.ts index 433bf93a..506aeef4 100644 --- a/Server/wwwroot/src/Main/DataGrid.ts +++ b/Server/wwwroot/src/Main/DataGrid.ts @@ -72,27 +72,18 @@ export function ApplyFilterToAll() { } export function ApplyFilterToDevice(device: Device) { + var existingDevice = FilteredDevices.findIndex(x => x.ID == device.ID); - if (GridState.HideOffline && !device.IsOnline) { - return; - } - - if (!GridState.ShowAllGroups && - (device.DeviceGroupID || "") != (GridState.GroupFilter || "")) { - return; - } - - if (deviceMatchesSearchFilter(device)) { - var existingIndex = FilteredDevices.findIndex(x => x.ID == device.ID); - - if (existingIndex > -1) { - FilteredDevices[existingIndex] = device; + if (shouldDeviceBeShown(device)) { + if (existingDevice > -1) { + FilteredDevices[existingDevice] = device; } else { FilteredDevices.push(device); } - - return; + } + else if (existingDevice > -1) { + FilteredDevices.splice(existingDevice, 1); } } @@ -276,7 +267,18 @@ export function UpdateDeviceCounts() { } } -function deviceMatchesSearchFilter(device: Device) { +function shouldDeviceBeShown(device: Device) { + + if (GridState.HideOffline && !device.IsOnline) { + return false; + } + + if (!GridState.ShowAllGroups && + (device.DeviceGroupID || "") != (GridState.GroupFilter || "")) { + return false; + } + + if (!GridState.SearchFilter) { return true; }