Skip to content

Introduce IModalCoordinator with strongly-typed ModalId and async inline-alert disposal#546

Draft
jschick04 wants to merge 4 commits into
jschick/add_dbtools_uifrom
jschick/modal-coordinator-refactor
Draft

Introduce IModalCoordinator with strongly-typed ModalId and async inline-alert disposal#546
jschick04 wants to merge 4 commits into
jschick/add_dbtools_uifrom
jschick/modal-coordinator-refactor

Conversation

@jschick04
Copy link
Copy Markdown
Collaborator

First in the sequential SoC refactor split (squashed to a single PR for shipping; split for easier review).

Scope

  • Folds the deleted IInlineAlertHostBroker into the new IModalCoordinator (one front-door for modal lifecycle + inline-alert host registry, one shared source of truth via IModalService.StateChanged).
  • Introduces strongly-typed ModalId (readonly record struct ModalId(long Value) with ModalId.None sentinel) to match the established codebase pattern (FilterId, FilterGroupId, BannerId, etc.). Internal long _idCounter in ModalService is preserved; the wrap happens at the public surface.
  • Converts inline-alert CancellationTokenRegistration disposal to await DisposeAsync() where the enclosing context is genuinely async:
    • ShowInlineAlertAsync is now async; await prior.CancellationRegistration.DisposeAsync() replaces sync Dispose().
    • DisposeAsyncCore awaits DisposeAsync() on the pending registration.
    • HandleInlineAlertResolvedAsync is now genuinely async (no more fire-and-forget _ = InvokeAsync(StateHasChanged)); inlines the lock-and-clear path so DisposeAsync() can be awaited.
    • TryClearInlineAlertFromCallback stays sync — it's only called from the cancellationToken.Register Action delegate where the BCL contract forces sync.
  • Critical concurrency fix in ModalService: reorder Complete / CancelActive / Show so state-clear under lock → StateChanged?.Invoke() → tcs/cancel-delegate ALL fire outside the lock. Without the reorder, an awaiter resuming on a RunContinuationsAsynchronously continuation could observe stale state via subscribers (e.g., the new IModalCoordinator mirror).

Tests

  • 13 new ModalCoordinatorTests covering the coordinator contract (state mirror, host register/unregister, stale-id lazy invalidation, dispose unhooks, push preempts prior).
  • 3 new ModalServiceCompletionOrderingTests verifying StateChanged fires before awaiter resumes on Complete/CancelActive/Show preempt paths.
  • Deleted: InlineAlertHostBrokerTests (broker folded into coordinator).
  • Existing tests updated to ModalId.
  • Build: 0 warnings, 0 errors.
  • Test run: 892 Runtime + 150 UI = 1,042 passing.

Files

19 files changed (+652 / -349):

New:

  • src/EventLogExpert.Runtime/Modal/IModalCoordinator.cs
  • src/EventLogExpert.Runtime/Modal/ModalCoordinator.cs
  • src/EventLogExpert.Runtime/Modal/ModalId.cs
  • src/EventLogExpert.Runtime/Modal/ModalSession.cs
  • tests/Unit/EventLogExpert.Runtime.Tests/Modal/ModalCoordinatorTests.cs
  • tests/Unit/EventLogExpert.Runtime.Tests/Modal/ModalServiceCompletionOrderingTests.cs

Deleted:

  • src/EventLogExpert.Runtime/Alerts/IInlineAlertHostBroker.cs
  • src/EventLogExpert.Runtime/Alerts/InlineAlertHostBroker.cs
  • tests/Unit/EventLogExpert.Runtime.Tests/Alerts/InlineAlertHostBrokerTests.cs

Modified:

  • src/EventLogExpert.Runtime/Modal/IModalService.cs (ActiveModalId/Complete take ModalId)
  • src/EventLogExpert.Runtime/Modal/ModalService.cs (concurrency reorder + ModalId public surface)
  • src/EventLogExpert.UI/Modal/ModalBase.cs (async refactor + ModalId)
  • src/EventLogExpert.Runtime/Alerts/AlertDialogService.cs (accepts IModalCoordinator; host is null flow)
  • src/EventLogExpert.Runtime/DependencyInjection/RuntimeServiceCollectionExtensions.cs
  • src/EventLogExpert/MauiProgram.cs (factory resolves IModalCoordinator)
  • 4 test files updated for ModalId

Notes

@jschick04 jschick04 requested a review from a team as a code owner May 25, 2026 20:27
@jschick04 jschick04 marked this pull request as draft May 25, 2026 20:28
@jschick04 jschick04 requested a review from Copilot May 25, 2026 20:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new IModalCoordinator as the single coordination surface for modal lifecycle + inline-alert host registration, while also adding a strongly-typed ModalId and adjusting modal/inline-alert completion ordering to avoid stale state observations by subscribers.

Changes:

  • Added IModalCoordinator/ModalCoordinator + ModalSession to mirror IModalService state and own inline-alert host registration.
  • Introduced ModalId (with ModalId.None) and updated IModalService/call sites/tests to use it instead of long.
  • Refactored ModalBase inline-alert handling to use async disposal (DisposeAsync) and reordered ModalService completion/cancel/show paths to invoke StateChanged before resuming awaiters.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/EventLogExpert.Runtime/Modal/IModalCoordinator.cs New coordinator contract for modal lifecycle + inline-alert host registry.
src/EventLogExpert.Runtime/Modal/ModalCoordinator.cs Implements coordinator mirror + inline-alert host registry.
src/EventLogExpert.Runtime/Modal/ModalId.cs Adds strongly-typed modal identifier with None sentinel.
src/EventLogExpert.Runtime/Modal/ModalSession.cs Adds active-modal snapshot type exposed by the coordinator.
tests/Unit/EventLogExpert.Runtime.Tests/Modal/ModalCoordinatorTests.cs Adds coordinator behavior tests (mirror, registry, disposal).
tests/Unit/EventLogExpert.Runtime.Tests/Modal/ModalServiceCompletionOrderingTests.cs Adds ordering tests for StateChanged vs awaiter resumption.
src/EventLogExpert.Runtime/Alerts/IInlineAlertHostBroker.cs Deleted (responsibility moved into IModalCoordinator).
src/EventLogExpert.Runtime/Alerts/InlineAlertHostBroker.cs Deleted (responsibility moved into ModalCoordinator).
tests/Unit/EventLogExpert.Runtime.Tests/Alerts/InlineAlertHostBrokerTests.cs Deleted (replaced by coordinator tests).
src/EventLogExpert.Runtime/Modal/IModalService.cs Updates surface to use ModalId for ActiveModalId/Complete.
src/EventLogExpert.Runtime/Modal/ModalService.cs Wraps id as ModalId and reorders completion/cancel/show for correct notification sequencing.
src/EventLogExpert.UI/Modal/ModalBase.cs Uses IModalCoordinator, ModalId, and async inline-alert registration disposal.
src/EventLogExpert.Runtime/Alerts/AlertDialogService.cs Routes inline alerts via IModalCoordinator instead of broker.
src/EventLogExpert.Runtime/DependencyInjection/RuntimeServiceCollectionExtensions.cs Registers IModalCoordinator and removes broker registration.
src/EventLogExpert/MauiProgram.cs Resolves IModalCoordinator for AlertDialogService factory wiring.
tests/Unit/EventLogExpert.UI.Tests/DebugLog/DebugLogModalTests.cs Updates test DI setup to provide IModalCoordinator and ModalId.
tests/Unit/EventLogExpert.Runtime.Tests/Modal/ModalServiceTests.cs Updates assertions to use ModalId.None.
tests/Unit/EventLogExpert.Runtime.Tests/DependencyInjection/RuntimeServiceCollectionExtensionsTests.cs Updates DI registration expectations to IModalCoordinator.
tests/Unit/EventLogExpert.Runtime.Tests/Alerts/AlertDialogServiceTests.cs Updates routing tests to use IModalCoordinator.TryGetInlineAlertHost.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/EventLogExpert.Runtime/Modal/ModalService.cs
@jschick04 jschick04 force-pushed the jschick/modal-coordinator-refactor branch from 127e880 to c73e24b Compare May 25, 2026 20:58
@jschick04 jschick04 requested a review from Copilot May 25, 2026 20:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Comment thread src/EventLogExpert.Runtime/Modal/ModalService.cs Outdated
Comment thread src/EventLogExpert.Runtime/Modal/ModalService.cs Outdated
Comment thread src/EventLogExpert.Runtime/Modal/ModalService.cs Outdated
@jschick04 jschick04 force-pushed the jschick/modal-coordinator-refactor branch from c73e24b to 1a89e51 Compare May 25, 2026 21:28
@jschick04 jschick04 requested a review from Copilot May 25, 2026 21:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

@jschick04 jschick04 force-pushed the jschick/modal-coordinator-refactor branch from 1a89e51 to 4ee620e Compare May 25, 2026 22:13
@jschick04 jschick04 requested a review from Copilot May 25, 2026 22:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants