-
Notifications
You must be signed in to change notification settings - Fork 45
PR 10 Commits B+C+D: Per-row upgrade progress + AttentionBanner suppression + Banner cycle in ModalChrome (closes #526) #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jschick04
wants to merge
6
commits into
jschick/modal-coordinator-pr10-a
from
jschick/modal-coordinator-pr10-bcd
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c35f6f3
Surface upgrade progress per row in DatabaseToolsModal Manage tab
jschick04 77c9918
Suppress AttentionBanner while DatabaseToolsModal is the active modal
jschick04 8aac802
Lift banner cycle into ModalChrome via singleton state service with c…
jschick04 cf3dfff
Synchronized BannerCycleStateService cycle mutations, isolated Upgrad…
jschick04 0560e44
Awaited InvokeAsync in Retry Upgrade and Restore From Backup click la…
jschick04 e3ec101
Widened Restore button guard to honor per-row UpgradeProgress so impo…
jschick04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
230 changes: 230 additions & 0 deletions
230
src/EventLogExpert.UI/Banner/BannerCycleStateService.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| // // Copyright (c) Microsoft Corporation. | ||
| // // Licensed under the MIT License. | ||
|
|
||
| using EventLogExpert.Runtime.Banner; | ||
| using EventLogExpert.Runtime.Modal; | ||
| using EventLogExpert.UI.DatabaseTools; | ||
|
|
||
| namespace EventLogExpert.UI.Banner; | ||
|
|
||
| public sealed class BannerCycleStateService : IBannerCycleStateService, IDisposable | ||
| { | ||
| private readonly IAttentionBannerService _attention; | ||
| private readonly ICriticalErrorService _critical; | ||
| private readonly IErrorBannerService _errors; | ||
| private readonly IInfoBannerService _infos; | ||
| private readonly IModalCoordinator _modalCoordinator; | ||
| private readonly IProgressBannerService _progress; | ||
| private readonly Lock _stateLock = new(); | ||
|
|
||
| private BannerView _currentView; | ||
| private int _displayedIndex; | ||
| private IReadOnlyList<BannerCycleItem> _items = []; | ||
| private bool _modalContentDisplayed; | ||
| private BannerCycleItem? _pendingOverrideItem; | ||
| private BannerCycleItem? _selectedItem; | ||
|
|
||
| public BannerCycleStateService( | ||
| IAttentionBannerService attention, | ||
| IErrorBannerService errors, | ||
| IInfoBannerService infos, | ||
| IProgressBannerService progress, | ||
| ICriticalErrorService critical, | ||
| IModalCoordinator modalCoordinator) | ||
| { | ||
| _attention = attention; | ||
| _errors = errors; | ||
| _infos = infos; | ||
| _progress = progress; | ||
| _critical = critical; | ||
| _modalCoordinator = modalCoordinator; | ||
|
|
||
| _attention.StateChanged += OnFacetChanged; | ||
| _errors.StateChanged += OnFacetChanged; | ||
| _infos.StateChanged += OnFacetChanged; | ||
| _progress.StateChanged += OnFacetChanged; | ||
| _critical.StateChanged += OnFacetChanged; | ||
| _modalCoordinator.StateChanged += OnFacetChanged; | ||
|
|
||
| RebuildAndReselect(); | ||
| } | ||
|
|
||
| public event Action? StateChanged; | ||
|
|
||
| public BannerView CurrentView | ||
| { | ||
| get { using (_stateLock.EnterScope()) { return _currentView; } } | ||
| } | ||
|
|
||
| public int DisplayedIndex | ||
| { | ||
| get { using (_stateLock.EnterScope()) { return _displayedIndex; } } | ||
| } | ||
|
|
||
| public IReadOnlyList<BannerCycleItem> Items | ||
| { | ||
| get { using (_stateLock.EnterScope()) { return _items; } } | ||
| } | ||
|
|
||
| public bool ModalContentDisplayed | ||
| { | ||
| get { using (_stateLock.EnterScope()) { return _modalContentDisplayed; } } | ||
| } | ||
|
|
||
| public BannerCycleItem? SelectedItem | ||
| { | ||
| get { using (_stateLock.EnterScope()) { return _selectedItem; } } | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _attention.StateChanged -= OnFacetChanged; | ||
| _errors.StateChanged -= OnFacetChanged; | ||
| _infos.StateChanged -= OnFacetChanged; | ||
| _progress.StateChanged -= OnFacetChanged; | ||
| _critical.StateChanged -= OnFacetChanged; | ||
| _modalCoordinator.StateChanged -= OnFacetChanged; | ||
| } | ||
|
|
||
| public void MoveNext() | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| var items = _items; | ||
| if (_displayedIndex >= items.Count - 1) { return; } | ||
|
|
||
| _displayedIndex++; | ||
| _selectedItem = items[_displayedIndex]; | ||
| _currentView = _selectedItem.View; | ||
| } | ||
|
|
||
| StateChanged?.Invoke(); | ||
| } | ||
|
|
||
| public void MovePrev() | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| var items = _items; | ||
| if (_displayedIndex <= 0 || items.Count == 0) { return; } | ||
|
|
||
| _displayedIndex--; | ||
| _selectedItem = items[_displayedIndex]; | ||
| _currentView = _selectedItem.View; | ||
| } | ||
|
|
||
| StateChanged?.Invoke(); | ||
| } | ||
|
|
||
| public void RegisterFallbackError(BannerCycleItem newCycleItem) | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| _pendingOverrideItem = newCycleItem; | ||
| RebuildAndReselectLocked(); | ||
| } | ||
|
|
||
| StateChanged?.Invoke(); | ||
| } | ||
|
|
||
| public void SetModalContentDisplayed(bool displayed) | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| if (_modalContentDisplayed == displayed) { return; } | ||
|
|
||
| _modalContentDisplayed = displayed; | ||
| } | ||
|
|
||
| StateChanged?.Invoke(); | ||
| } | ||
|
|
||
| private static bool ItemMatches(BannerCycleItem selected, BannerCycleItem candidate) | ||
| { | ||
| if (selected.View != candidate.View) { return false; } | ||
|
|
||
| return selected.EntryId == candidate.EntryId; | ||
| } | ||
|
|
||
| private void OnFacetChanged() | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| RebuildAndReselectLocked(); | ||
| } | ||
|
|
||
| StateChanged?.Invoke(); | ||
| } | ||
|
|
||
| private void RebuildAndReselect() | ||
| { | ||
| using (_stateLock.EnterScope()) | ||
| { | ||
| RebuildAndReselectLocked(); | ||
| } | ||
| } | ||
|
|
||
| private void RebuildAndReselectLocked() | ||
| { | ||
| if (_modalCoordinator.ActiveSession is null) | ||
| { | ||
| _modalContentDisplayed = false; | ||
| } | ||
|
|
||
| bool attentionSuppressed = | ||
| _modalCoordinator.ActiveSession?.ComponentType == typeof(DatabaseToolsModal); | ||
|
|
||
| IReadOnlyList<BannerCycleItem> items = BannerViewSelector.BuildCycle( | ||
| _critical.CurrentCritical, | ||
| _errors.ErrorBanners, | ||
| _attention.AttentionEntries, | ||
| _attention.AttentionDismissed, | ||
| attentionSuppressed, | ||
| _progress.BackgroundProgress, | ||
| _infos.InfoBanners); | ||
|
|
||
| _items = items; | ||
|
|
||
| if (items.Count == 0) | ||
| { | ||
| _selectedItem = null; | ||
| _displayedIndex = 0; | ||
| _currentView = BannerView.None; | ||
| _pendingOverrideItem = null; | ||
| return; | ||
| } | ||
|
|
||
| if (_pendingOverrideItem is not null) | ||
| { | ||
| for (int i = 0; i < items.Count; i++) | ||
| { | ||
| if (!ItemMatches(_pendingOverrideItem, items[i])) { continue; } | ||
|
|
||
| _displayedIndex = i; | ||
| _selectedItem = items[i]; | ||
| _currentView = _selectedItem.View; | ||
| _pendingOverrideItem = null; | ||
| return; | ||
| } | ||
|
|
||
| _pendingOverrideItem = null; | ||
| } | ||
|
|
||
| if (_selectedItem is not null) | ||
| { | ||
| for (int i = 0; i < items.Count; i++) | ||
| { | ||
| if (!ItemMatches(_selectedItem, items[i])) { continue; } | ||
|
|
||
| _displayedIndex = i; | ||
| _selectedItem = items[i]; | ||
| _currentView = _selectedItem.View; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| _displayedIndex = Math.Clamp(_displayedIndex, 0, items.Count - 1); | ||
| _selectedItem = items[_displayedIndex]; | ||
| _currentView = _selectedItem.View; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,70 +1,66 @@ | ||
| @{ | ||
| @if (RendersContent) | ||
| { | ||
| BannerCycleItem? selected = CycleState.SelectedItem; | ||
| IReadOnlyList<BannerCycleItem> items = CycleState.Items; | ||
| BannerView view = CycleState.CurrentView; | ||
| int displayedIndex = CycleState.DisplayedIndex; | ||
|
|
||
| Exception? currentCritical = CriticalErrorService.CurrentCritical; | ||
| IReadOnlyList<ErrorBannerEntry> errors = ErrorBannerService.ErrorBanners; | ||
| IReadOnlyList<BannerInfoEntry> infos = InfoBannerService.InfoBanners; | ||
| IReadOnlyList<DatabaseEntry> attentionEntries = AttentionBannerService.AttentionEntries; | ||
| bool attentionDismissed = AttentionBannerService.AttentionDismissed; | ||
| BannerProgressEntry? backgroundProgress = ProgressBannerService.BackgroundProgress; | ||
|
|
||
| (BannerCycleItem? selected, BannerView view) = RebuildItemsAndPickSelected( | ||
| currentCritical, | ||
| errors, | ||
| attentionEntries, | ||
| attentionDismissed, | ||
| backgroundProgress, | ||
| infos); | ||
|
|
||
| _currentView = view; | ||
| bool showCyclePagination = _items.Count > 1 && view != BannerView.Critical; | ||
| bool showCyclePagination = items.Count > 1 && view != BannerView.Critical; | ||
|
|
||
| RenderFragment cycleNav = @<text> | ||
| @if (showCyclePagination) | ||
| { | ||
| <span class="banner-pagination">@(_displayedIndex + 1) of @_items.Count</span> | ||
| <span class="banner-pagination">@(displayedIndex + 1) of @items.Count</span> | ||
| <button aria-label="Previous banner" | ||
| class="banner-cycle-prev button" | ||
| disabled="@(_displayedIndex == 0)" | ||
| @onclick="OnCyclePrev" | ||
| disabled="@(displayedIndex == 0)" | ||
| @onclick="CycleState.MovePrev" | ||
| type="button"> | ||
| <i aria-hidden="true" class="bi bi-chevron-left"></i> | ||
| </button> | ||
| <button aria-label="Next banner" | ||
| class="banner-cycle-next button" | ||
| disabled="@(_displayedIndex == _items.Count - 1)" | ||
| @onclick="OnCycleNext" | ||
| disabled="@(displayedIndex == items.Count - 1)" | ||
| @onclick="CycleState.MoveNext" | ||
| type="button"> | ||
| <i aria-hidden="true" class="bi bi-chevron-right"></i> | ||
| </button> | ||
| } | ||
| </text>; | ||
| } | ||
|
|
||
| @switch (view) | ||
| { | ||
| case BannerView.Critical when currentCritical != null: | ||
| <CriticalBanner Critical="currentCritical" /> | ||
| @switch (view) | ||
| { | ||
| case BannerView.Critical when currentCritical != null: | ||
| <CriticalBanner Critical="currentCritical" /> | ||
|
|
||
| break; | ||
| break; | ||
|
|
||
| case BannerView.Error when selected != null && selected.IndexWithinSlice < errors.Count: | ||
| <ErrorBanner CycleNav="cycleNav" Entry="errors[selected.IndexWithinSlice]" /> | ||
| case BannerView.Error when selected != null && selected.IndexWithinSlice < errors.Count: | ||
| <ErrorBanner CycleNav="cycleNav" Entry="errors[selected.IndexWithinSlice]" /> | ||
|
|
||
| break; | ||
| break; | ||
|
|
||
| case BannerView.Attention when attentionEntries.Count > 0: | ||
| <AttentionBanner AttentionCount="attentionEntries.Count" | ||
| CycleNav="cycleNav" | ||
| OnFallbackErrorPosted="HandleFallbackErrorPosted" /> | ||
| case BannerView.Attention when attentionEntries.Count > 0: | ||
| <AttentionBanner AttentionCount="attentionEntries.Count" | ||
| CycleNav="cycleNav" | ||
| OnFallbackErrorPosted="HandleFallbackErrorPosted" /> | ||
|
|
||
| break; | ||
| break; | ||
|
|
||
| case BannerView.UpgradeProgress when backgroundProgress is { } progress: | ||
| <UpgradeProgressBanner CycleNav="cycleNav" Progress="progress" /> | ||
| case BannerView.UpgradeProgress when backgroundProgress is { } progress: | ||
| <UpgradeProgressBanner CycleNav="cycleNav" Progress="progress" /> | ||
|
|
||
| break; | ||
| break; | ||
|
|
||
| case BannerView.Info when selected != null && selected.IndexWithinSlice < infos.Count: | ||
| <InfoBanner CycleNav="cycleNav" Entry="infos[selected.IndexWithinSlice]" /> | ||
| case BannerView.Info when selected != null && selected.IndexWithinSlice < infos.Count: | ||
| <InfoBanner CycleNav="cycleNav" Entry="infos[selected.IndexWithinSlice]" /> | ||
|
|
||
| break; | ||
| break; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.