Skip to content

Commit a892d99

Browse files
committed
Updated Status bar to only trigger an update when there is value changes
1 parent 59d64c7 commit a892d99

File tree

5 files changed

+91
-30
lines changed

5 files changed

+91
-30
lines changed

src/EventLogExpert.UI.Tests/Store/StatusBar/StatusBarStoreTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ public void ReduceSetEventsLoading_WithNewActivity_ShouldAddActivity()
189189
Assert.Equal((100, 5), result.EventsLoading[activityId]);
190190
}
191191

192+
[Fact]
193+
public void ReduceSetEventsLoading_WithUnchangedValues_ShouldReturnSameState()
194+
{
195+
var activityId = Guid.NewGuid();
196+
197+
var state = new StatusBarState
198+
{
199+
EventsLoading = ImmutableDictionary<Guid, (int, int)>.Empty.Add(activityId, (100, 5))
200+
};
201+
202+
var action = new StatusBarAction.SetEventsLoading(activityId, 100, 5);
203+
204+
var result = StatusBarReducers.ReduceSetEventsLoading(state, action);
205+
206+
Assert.Same(state, result);
207+
}
208+
192209
[Fact]
193210
public void ReduceSetEventsLoading_WithZeroCount_ShouldRemoveActivity()
194211
{

src/EventLogExpert.UI/Store/EventLog/EventLogEffects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public async Task HandleOpenLog(EventLogAction.OpenLog action, IDispatcher dispa
144144
_ => { dispatcher.Dispatch(new StatusBarAction.SetEventsLoading(activityId, events.Count, failed)); },
145145
null,
146146
TimeSpan.Zero,
147-
TimeSpan.FromSeconds(1));
147+
TimeSpan.FromSeconds(3));
148148

149149
using var reader = new EventLogReader(action.LogName, action.PathType, filterState?.Value.IsXmlEnabled ?? false);
150150

src/EventLogExpert.UI/Store/StatusBar/StatusBarReducers.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ public static StatusBarState ReduceClearStatus(StatusBarState state, StatusBarAc
2727
[ReducerMethod]
2828
public static StatusBarState ReduceSetEventsLoading(StatusBarState state, StatusBarAction.SetEventsLoading action)
2929
{
30-
return state with
31-
{
32-
EventsLoading = CommonLoadingReducer(state.EventsLoading, action.ActivityId, action.Count, action.FailedCount)
33-
};
30+
var newLoading = CommonLoadingReducer(state.EventsLoading, action.ActivityId, action.Count, action.FailedCount);
31+
32+
return ReferenceEquals(newLoading, state.EventsLoading) ? state : state with { EventsLoading = newLoading };
3433
}
3534

3635
[ReducerMethod]
@@ -44,11 +43,13 @@ public static StatusBarState
4443
int count,
4544
int failedCount)
4645
{
47-
if (loadingEntries.ContainsKey(activityId))
46+
if (loadingEntries.TryGetValue(activityId, out var existing) && existing == (count, failedCount))
4847
{
49-
loadingEntries = loadingEntries.Remove(activityId);
48+
return loadingEntries;
5049
}
5150

52-
return count == 0 ? loadingEntries : loadingEntries.Add(activityId, (count, failedCount));
51+
var updated = loadingEntries.Remove(activityId);
52+
53+
return count == 0 ? updated : updated.Add(activityId, (count, failedCount));
5354
}
5455
}
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
@using EventLogExpert.UI.Store.EventLog
2-
@using EventLogExpert.UI.Store.EventTable
3-
@using EventLogExpert.UI.Store.FilterPane
4-
@using EventLogExpert.UI.Store.StatusBar
5-
@using EventLogExpert.UI
1+
@using EventLogExpert.UI
62
@inherits FluxorComponent
73

8-
@inject IState<EventLogState> EventLogState
9-
@inject IState<EventTableState> EventTableState
10-
@inject IState<FilterPaneState> FilterPaneState
11-
@inject IState<StatusBarState> StatusBarState
12-
134
<div class="status-bar">
14-
@foreach (var loadingProgress in StatusBarState.Value.EventsLoading)
5+
@foreach (var loadingProgress in _statusBarState.EventsLoading)
156
{
167
<span>Loading: @loadingProgress.Value.Item1</span>
178

@@ -21,42 +12,42 @@
2112
}
2213
}
2314

24-
<span>Events Loaded: @EventLogState.Value.ActiveLogs.Values.Sum(log => log.Events.Count)</span>
15+
<span>Events Loaded: @_eventLogState.ActiveLogs.Values.Sum(log => log.Events.Count)</span>
2516

26-
@if (EventTableState.Value.ActiveEventLogId is not null && FilterMethods.IsFilteringEnabled(EventLogState.Value.AppliedFilter))
17+
@if (_eventTableState.ActiveEventLogId is not null && FilterMethods.IsFilteringEnabled(_eventLogState.AppliedFilter))
2718
{
28-
var activeTable = EventTableState.Value.EventTables.FirstOrDefault(table => table.Id == EventTableState.Value.ActiveEventLogId);
19+
var activeTable = _eventTableState.EventTables.FirstOrDefault(table => table.Id == _eventTableState.ActiveEventLogId);
2920

3021
if (activeTable is null) { return; }
3122

3223
var totalEvents = activeTable.IsCombined ?
33-
EventLogState.Value.ActiveLogs.Sum(l => l.Value.Events.Count) :
34-
EventLogState.Value.ActiveLogs[activeTable.LogName].Events.Count;
24+
_eventLogState.ActiveLogs.Sum(l => l.Value.Events.Count) :
25+
_eventLogState.ActiveLogs[activeTable.LogName].Events.Count;
3526

3627
var filteredEvents = activeTable.DisplayedEvents.Count;
3728

3829
<span>Visible: @(filteredEvents) Hidden by filter: @(totalEvents - filteredEvents)</span>
3930
}
4031

41-
@if (EventLogState.Value.ActiveLogs.Values.Any(l => l.Type == PathType.LogName))
32+
@if (_eventLogState.ActiveLogs.Values.Any(l => l.Type == PathType.LogName))
4233
{
43-
@if (EventLogState.Value.ContinuouslyUpdate)
34+
@if (_eventLogState.ContinuouslyUpdate)
4435
{
4536
<span>Continuously Updating</span>
4637
}
4738
else
4839
{
49-
<span>New Events: @EventLogState.Value.NewEventBuffer.Count</span>
40+
<span>New Events: @_eventLogState.NewEventBuffer.Count</span>
5041

51-
@if (EventLogState.Value.NewEventBufferIsFull)
42+
@if (_eventLogState.NewEventBufferIsFull)
5243
{
5344
<span>Buffer Full</span>
5445
}
5546
}
5647
}
5748

58-
@if (!string.IsNullOrEmpty(StatusBarState.Value.ResolverStatus))
49+
@if (!string.IsNullOrEmpty(_statusBarState.ResolverStatus))
5950
{
60-
<span>@StatusBarState.Value.ResolverStatus</span>
51+
<span>@_statusBarState.ResolverStatus</span>
6152
}
6253
</div>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// // Copyright (c) Microsoft Corporation.
2+
// // Licensed under the MIT License.
3+
4+
using EventLogExpert.UI.Store.EventLog;
5+
using EventLogExpert.UI.Store.EventTable;
6+
using EventLogExpert.UI.Store.FilterPane;
7+
using EventLogExpert.UI.Store.StatusBar;
8+
using Fluxor;
9+
using Microsoft.AspNetCore.Components;
10+
11+
namespace EventLogExpert.Components;
12+
13+
public sealed partial class StatusBar
14+
{
15+
private EventLogState _eventLogState = null!;
16+
private EventTableState _eventTableState = null!;
17+
private FilterPaneState _filterPaneState = null!;
18+
private StatusBarState _statusBarState = null!;
19+
20+
[Inject] private IState<EventLogState> EventLogState { get; set; } = null!;
21+
22+
[Inject] private IState<EventTableState> EventTableState { get; set; } = null!;
23+
24+
[Inject] private IState<FilterPaneState> FilterPaneState { get; set; } = null!;
25+
26+
[Inject] private IState<StatusBarState> StatusBarState { get; set; } = null!;
27+
28+
protected override void OnInitialized()
29+
{
30+
base.OnInitialized();
31+
32+
_eventLogState = EventLogState.Value;
33+
_eventTableState = EventTableState.Value;
34+
_filterPaneState = FilterPaneState.Value;
35+
_statusBarState = StatusBarState.Value;
36+
}
37+
38+
protected override bool ShouldRender()
39+
{
40+
if (ReferenceEquals(EventLogState.Value, _eventLogState) &&
41+
ReferenceEquals(EventTableState.Value, _eventTableState) &&
42+
ReferenceEquals(FilterPaneState.Value, _filterPaneState) &&
43+
ReferenceEquals(StatusBarState.Value, _statusBarState)) { return false; }
44+
45+
_eventLogState = EventLogState.Value;
46+
_eventTableState = EventTableState.Value;
47+
_filterPaneState = FilterPaneState.Value;
48+
_statusBarState = StatusBarState.Value;
49+
50+
return true;
51+
}
52+
}

0 commit comments

Comments
 (0)