Dialog: Use ParameterState, make DialogOptions immutable#10066
Dialog: Use ParameterState, make DialogOptions immutable#10066ScarletKuro merged 18 commits intoMudBlazor:devfrom
Conversation
|
Please read carefully the description. |
Isn't this the easiest solution?
Are you sure this is worth it? I mean if a simple |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #10066 +/- ##
==========================================
+ Coverage 91.13% 91.15% +0.02%
==========================================
Files 410 411 +1
Lines 12459 12466 +7
Branches 2419 2419
==========================================
+ Hits 11354 11364 +10
+ Misses 560 557 -3
Partials 545 545 ☔ View full report in Codecov by Sentry. |
Obviously, We can create a We will also need to rename the current |
Maybe |
Ig, we can discuss it once the implementation is ready. |
|
@henon, done. Called it MudDialogContainer. |
|
Haha, after this change, I want to rewrite the dialogs, especially finally add a |
|
For now, I'm casting However, when I will rewrite this for v9, I will use KeyInterceptorService directly. In my opinion, bUnit tests should be closer to real conditions. We rely too much on invoking internal methods directly instead of simulating actions via bUnit. |
That is a great name |
| if (GetDialogOptionsOrDefault.CloseOnEscapeKey.HasValue) | ||
| return GetDialogOptionsOrDefault.CloseOnEscapeKey.Value; | ||
|
|
||
| if (GlobalDialogOptions.CloseOnEscapeKey.HasValue) | ||
| return GlobalDialogOptions.CloseOnEscapeKey.Value; | ||
|
|
||
| return false; |
There was a problem hiding this comment.
Maybe in the v9 rewrite we could just move the global dialog option values into MudGlobal for consistency.
There was a problem hiding this comment.
Was my thought as well.
|
Ideas for v9:
|
I will add test for #10036 and then merge it. |
|
Great, I added a point to the ideas:
|
|
Added to the v8 migration guide at #9953 |
|
We ran into a minor issue with unit testing some of our dialogs using bunit. We rendered the dialog instance cascading value in the unit tests previously using MudDialogInstance and the change to IMudDialogInstance prevents rendering. The simple fix was to render it in the unit test using MudDialogContainer which I found in this thread. Something that others might also run into. |
Description
Fixes: #10036
Removes
DialogHelperComponent, as it is no longer needed and can interfere with theParameterState. I don’t believe that Blazored.Modal is using it either: https://github.com/Blazored/Modal/blob/main/src/Blazored.Modal/Services/ModalService.csMakes the
DialogOptionsimmutable to prevent consumers from modifying theOptionsparameter directly. They should use the new approach with thewithsyntax, as shown inDialogSetOptionsExample_Dialog.razor/DialogToggleFullscreen.razorthe examples.Despite my comment here: #10036 (comment), I still had to add
OptionsChangedfor two-way binding. WhileParameterStatewas working, one case wasn’t covered, which was this:The problem is that if you click on
ToggleFullscreenAsynca second time, it wouldn’t work as expected. At that point, onlyParameterStatewould update, whileMudDialog.Options.FullScreenwould not, since we never write to it. This means you wouldn’t be able to toggleFullScreenwhen relying onMudDialog.Options.FullScreen, as its value never updates.This could be solved by:
GetOptions()in theMudDialogInstanceto return_dialogOptionsState.Value._dialogOptionsStateandOptions.I decided that the most appropriate solution is to introduce two-way binding for the parameters we modify.
To achieve this, I had to create an additional layer,
MudDialogInstanceParent, because for two-way binding to work, I need a reference toComponentBase. I couldn’t do that in the following code:MudBlazor/src/MudBlazor/Services/Dialog/DialogService.cs
Lines 152 to 161 in 336434d
This is because it doesn’t provide any API, and
OpenComponentdoesn’t return the instance. There is also nothing that points to theComponentBaseof what we are currently creating.How Has This Been Tested?
bunit test
Type of Changes
Checklist
dev).