From ad13e93232248e91d5837ae0742440df87e3a1a8 Mon Sep 17 00:00:00 2001 From: jan hach Date: Sun, 14 Jul 2024 23:03:24 +0200 Subject: [PATCH 1/9] feat: allow FluentSortableList to know where an item was dragged from and dropped to --- ...crosoft.FluentUI.AspNetCore.Components.xml | 12 +++ .../SortableListMoveBetweenLists.razor | 87 ++++++++----------- .../SortableList/FluentSortableList.razor | 2 +- .../SortableList/FluentSortableList.razor.cs | 10 +-- .../SortableList/FluentSortableList.razor.js | 4 +- .../FluentSortableListEventArgs.cs | 16 +++- 6 files changed, 73 insertions(+), 58 deletions(-) diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml index 3ca6c314d6..a3003085f3 100644 --- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml +++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml @@ -7959,6 +7959,18 @@ Gets the index of the item in the list after the update. + + + Gets the id of the list the item was in before the update. + May be null if no Id was set for + + + + + Gets the id of the list the item is in after the update. + May be null if no Id was set for + + diff --git a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor index 28fd742f45..d3ce5fe633 100644 --- a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor +++ b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor @@ -2,19 +2,28 @@ .fluent-sortable-list.darker { --fluent-sortable-list-background-color: var(--neutral-layer-4) !important; } + .fluent-sortable-list.lighter { + --fluent-sortable-list-background-color: var(--neutral-layer-1) !important; + }
List 1
- + @item.Name
List 2
- + + @item.Name + +
+ +
List 3
+ @item.Name
@@ -33,65 +42,34 @@ public List items2 = Enumerable.Range(11, 10).Select(i => new Item { Id = i, Name = $"Item {i}" }).ToList(); - private void ListOneRemove(FluentSortableListEventArgs args) - { - if (args is null) - { - return; - } + public List items3 = Enumerable.Range(21, 10).Select(i => new Item { Id = i, Name = $"Item {i}" }).ToList(); - // get the item at the old index in list 1 - var item = items1[args.OldIndex]; - // add it to the new index in list 2 - items2.Insert(args.NewIndex, item); - - // remove the item from the old index in list 1 - items1.Remove(items1[args.OldIndex]); - } - - private void ListTwoRemove(FluentSortableListEventArgs args) + private void HandleRemove(FluentSortableListEventArgs args) { - if (args is null) + if (args?.FromId is null || args?.ToId is null || args.FromId == args.ToId) { return; } - // get the item at the old index in list 2 - var item = items2[args.OldIndex]; + // get the old list (currently containing the item) + var from = GetList(args.FromId); - // add it to the new index in list 1 - items1.Insert(args.NewIndex, item); + // get the new list (the list the item was dropped on) + var to = GetList(args.ToId); - // remove the item from the old index in list 2 - items2.Remove(items2[args.OldIndex]); - } - private void SortListOne(FluentSortableListEventArgs args) - { - if (args is null || args.OldIndex == args.NewIndex) - { - return; - } + // get the item at the old index in list from + var item = from[args.OldIndex]; - var oldIndex = args.OldIndex; - var newIndex = args.NewIndex; - - var items = this.items1; - var itemToMove = items[oldIndex]; - items.RemoveAt(oldIndex); + // add it to the new index in list to + to.Insert(args.NewIndex, item); - if (newIndex < items.Count) - { - items.Insert(newIndex, itemToMove); - } - else - { - items.Add(itemToMove); - } + // remove the item from the old index in list from + from.Remove(from[args.OldIndex]); } - private void SortListTwo(FluentSortableListEventArgs args) + private void HandleSort(FluentSortableListEventArgs args) { - if (args is null || args.OldIndex == args.NewIndex) + if (args?.FromId is null || args?.ToId is null || args.FromId != args.ToId) { return; } @@ -99,7 +77,8 @@ var oldIndex = args.OldIndex; var newIndex = args.NewIndex; - var items = this.items2; + // the item is dropped on the same list it is from, so it doesn't matter which list we get + var items = GetList(args.FromId); var itemToMove = items[oldIndex]; items.RemoveAt(oldIndex); @@ -112,4 +91,14 @@ items.Add(itemToMove); } } + + private List GetList(string id) => + id switch + { + "shared1" => items1, + "shared2" => items2, + "shared3" => items3, + _ => throw new ArgumentException($"No list with id {id}") + }; + } diff --git a/src/Core/Components/SortableList/FluentSortableList.razor b/src/Core/Components/SortableList/FluentSortableList.razor index b4e58b79b5..ebe0da1162 100644 --- a/src/Core/Components/SortableList/FluentSortableList.razor +++ b/src/Core/Components/SortableList/FluentSortableList.razor @@ -7,7 +7,7 @@ @if (ItemTemplate is not null) { -
+
@foreach (var item in Items) {
@ItemTemplate(item)
diff --git a/src/Core/Components/SortableList/FluentSortableList.razor.cs b/src/Core/Components/SortableList/FluentSortableList.razor.cs index 70b3a29911..aeb999190e 100644 --- a/src/Core/Components/SortableList/FluentSortableList.razor.cs +++ b/src/Core/Components/SortableList/FluentSortableList.razor.cs @@ -126,22 +126,22 @@ protected bool GetItemFiltered(TItem item) } [JSInvokable] - public void OnUpdateJS(int oldIndex, int newIndex) + public void OnUpdateJS(int oldIndex, int newIndex, string fromId, string toId) { if (OnUpdate.HasDelegate) { - // invoke the OnUpdate event passing in the oldIndex and the newIndex - OnUpdate.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex)); + // invoke the OnUpdate event passing in the oldIndex, the newIndex, the fromId and the toId + OnUpdate.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromId, toId)); } } [JSInvokable] - public void OnRemoveJS(int oldIndex, int newIndex) + public void OnRemoveJS(int oldIndex, int newIndex, string fromId, string toId) { if (OnRemove.HasDelegate) { // remove the item from the list - OnRemove.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex)); + OnRemove.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromId, toId)); } } diff --git a/src/Core/Components/SortableList/FluentSortableList.razor.js b/src/Core/Components/SortableList/FluentSortableList.razor.js index 857b417112..324b5e4e0d 100644 --- a/src/Core/Components/SortableList/FluentSortableList.razor.js +++ b/src/Core/Components/SortableList/FluentSortableList.razor.js @@ -16,7 +16,7 @@ export function init(list, group, pull, put, sort, handle, filter, fallback, com event.to.insertBefore(event.item, event.to.childNodes[event.oldIndex]); // Notify .NET to update its model and re-render - component.invokeMethodAsync('OnUpdateJS', event.oldDraggableIndex, event.newDraggableIndex); + component.invokeMethodAsync('OnUpdateJS', event.oldDraggableIndex, event.newDraggableIndex, event.from.id, event.to.id); }, onRemove: (event) => { if (event.pullMode === 'clone') { @@ -28,7 +28,7 @@ export function init(list, group, pull, put, sort, handle, filter, fallback, com event.from.insertBefore(event.item, event.from.childNodes[event.oldIndex]); // Notify .NET to update its model and re-render - component.invokeMethodAsync('OnRemoveJS', event.oldDraggableIndex, event.newDraggableIndex); + component.invokeMethodAsync('OnRemoveJS', event.oldDraggableIndex, event.newDraggableIndex, event.from.id, event.to.id); } }); } diff --git a/src/Core/Components/SortableList/FluentSortableListEventArgs.cs b/src/Core/Components/SortableList/FluentSortableListEventArgs.cs index 07475fbcae..72007b64ed 100644 --- a/src/Core/Components/SortableList/FluentSortableListEventArgs.cs +++ b/src/Core/Components/SortableList/FluentSortableListEventArgs.cs @@ -7,10 +7,12 @@ public FluentSortableListEventArgs() } - public FluentSortableListEventArgs(int oldIndex, int newIndex) + public FluentSortableListEventArgs(int oldIndex, int newIndex, string? fromId, string? toId) { OldIndex = oldIndex; NewIndex = newIndex; + FromId = fromId; + ToId = toId; } /// @@ -22,4 +24,16 @@ public FluentSortableListEventArgs(int oldIndex, int newIndex) /// Gets the index of the item in the list after the update. /// public int NewIndex { get; } + + /// + /// Gets the id of the list the item was in before the update. + /// May be null if no Id was set for + /// + public string? FromId { get; } + + /// + /// Gets the id of the list the item is in after the update. + /// May be null if no Id was set for + /// + public string? ToId { get; } } From dd70d48803743a14ea99ce795806683bd2c8538e Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 17:13:11 +0200 Subject: [PATCH 2/9] Renamed properties --- .../Examples/SortableListMoveBetweenLists.razor | 10 +++++----- .../SortableList/FluentSortableListEventArgs.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor index d3ce5fe633..5da092580c 100644 --- a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor +++ b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor @@ -47,15 +47,15 @@ private void HandleRemove(FluentSortableListEventArgs args) { - if (args?.FromId is null || args?.ToId is null || args.FromId == args.ToId) + if (args?.FromListId is null || args?.ToListId is null || args.FromListId == args.ToListId) { return; } // get the old list (currently containing the item) - var from = GetList(args.FromId); + var from = GetList(args.FromListId); // get the new list (the list the item was dropped on) - var to = GetList(args.ToId); + var to = GetList(args.ToListId); // get the item at the old index in list from var item = from[args.OldIndex]; @@ -69,7 +69,7 @@ private void HandleSort(FluentSortableListEventArgs args) { - if (args?.FromId is null || args?.ToId is null || args.FromId != args.ToId) + if (args?.FromListId is null || args?.ToListId is null || args.FromListId != args.ToListId) { return; } @@ -78,7 +78,7 @@ var newIndex = args.NewIndex; // the item is dropped on the same list it is from, so it doesn't matter which list we get - var items = GetList(args.FromId); + var items = GetList(args.FromListId); var itemToMove = items[oldIndex]; items.RemoveAt(oldIndex); diff --git a/src/Core/Components/SortableList/FluentSortableListEventArgs.cs b/src/Core/Components/SortableList/FluentSortableListEventArgs.cs index 72007b64ed..483ed3e23f 100644 --- a/src/Core/Components/SortableList/FluentSortableListEventArgs.cs +++ b/src/Core/Components/SortableList/FluentSortableListEventArgs.cs @@ -7,12 +7,12 @@ public FluentSortableListEventArgs() } - public FluentSortableListEventArgs(int oldIndex, int newIndex, string? fromId, string? toId) + public FluentSortableListEventArgs(int oldIndex, int newIndex, string? fromListId, string? toListId) { OldIndex = oldIndex; NewIndex = newIndex; - FromId = fromId; - ToId = toId; + FromListId = fromListId; + ToListId = toListId; } /// @@ -29,11 +29,11 @@ public FluentSortableListEventArgs(int oldIndex, int newIndex, string? fromId, s /// Gets the id of the list the item was in before the update. /// May be null if no Id was set for /// - public string? FromId { get; } + public string? FromListId { get; } /// /// Gets the id of the list the item is in after the update. /// May be null if no Id was set for /// - public string? ToId { get; } + public string? ToListId { get; } } From 874417cfd7ec0831b147fbd2329a51fe0d2ec395 Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 17:14:33 +0200 Subject: [PATCH 3/9] Changed example back to two lists The swapping is still handled differently (getting the list through the ids) than before. --- .../Examples/SortableListMoveBetweenLists.razor | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor index 5da092580c..cbe7aef32c 100644 --- a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor +++ b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor @@ -2,9 +2,6 @@ .fluent-sortable-list.darker { --fluent-sortable-list-background-color: var(--neutral-layer-4) !important; } - .fluent-sortable-list.lighter { - --fluent-sortable-list-background-color: var(--neutral-layer-1) !important; - } @@ -21,12 +18,6 @@ @item.Name - -
List 3
- - @item.Name - -
@code { @@ -42,8 +33,6 @@ public List items2 = Enumerable.Range(11, 10).Select(i => new Item { Id = i, Name = $"Item {i}" }).ToList(); - public List items3 = Enumerable.Range(21, 10).Select(i => new Item { Id = i, Name = $"Item {i}" }).ToList(); - private void HandleRemove(FluentSortableListEventArgs args) { @@ -97,7 +86,6 @@ { "shared1" => items1, "shared2" => items2, - "shared3" => items3, _ => throw new ArgumentException($"No list with id {id}") }; From 033f53eaf9c5921091de19a63058111b894b307b Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 17:25:36 +0200 Subject: [PATCH 4/9] Reverted to the previous example with added traces for the id. --- .../SortableListMoveBetweenLists.razor | 77 +++++++++++++------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor index cbe7aef32c..86cb6b7577 100644 --- a/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor +++ b/examples/Demo/Shared/Pages/SortableList/Examples/SortableListMoveBetweenLists.razor @@ -8,13 +8,13 @@
List 1
- + @item.Name
List 2
- + @item.Name
@@ -33,32 +33,45 @@ public List items2 = Enumerable.Range(11, 10).Select(i => new Item { Id = i, Name = $"Item {i}" }).ToList(); - - private void HandleRemove(FluentSortableListEventArgs args) + private void ListOneRemove(FluentSortableListEventArgs args) { - if (args?.FromListId is null || args?.ToListId is null || args.FromListId == args.ToListId) + if (args is null) { return; } - // get the old list (currently containing the item) - var from = GetList(args.FromListId); - // get the new list (the list the item was dropped on) - var to = GetList(args.ToListId); + // get the item at the old index in list 1 + var item = items1[args.OldIndex]; - // get the item at the old index in list from - var item = from[args.OldIndex]; + // add it to the new index in list 2 + items2.Insert(args.NewIndex, item); - // add it to the new index in list to - to.Insert(args.NewIndex, item); + // remove the item from the old index in list 1 + items1.Remove(items1[args.OldIndex]); - // remove the item from the old index in list from - from.Remove(from[args.OldIndex]); + DemoLogger.WriteLine($"Moved item from list {args.FromListId} to list {args.ToListId}"); } - private void HandleSort(FluentSortableListEventArgs args) + private void ListTwoRemove(FluentSortableListEventArgs args) + { + if (args is null) + { + return; + } + // get the item at the old index in list 2 + var item = items2[args.OldIndex]; + + // add it to the new index in list 1 + items1.Insert(args.NewIndex, item); + + // remove the item from the old index in list 2 + items2.Remove(items2[args.OldIndex]); + + DemoLogger.WriteLine($"Moved item from list {args.FromListId} to list {args.ToListId}"); + } + private void SortListOne(FluentSortableListEventArgs args) { - if (args?.FromListId is null || args?.ToListId is null || args.FromListId != args.ToListId) + if (args is null || args.OldIndex == args.NewIndex) { return; } @@ -66,8 +79,7 @@ var oldIndex = args.OldIndex; var newIndex = args.NewIndex; - // the item is dropped on the same list it is from, so it doesn't matter which list we get - var items = GetList(args.FromListId); + var items = this.items1; var itemToMove = items[oldIndex]; items.RemoveAt(oldIndex); @@ -81,12 +93,27 @@ } } - private List GetList(string id) => - id switch + private void SortListTwo(FluentSortableListEventArgs args) + { + if (args is null || args.OldIndex == args.NewIndex) { - "shared1" => items1, - "shared2" => items2, - _ => throw new ArgumentException($"No list with id {id}") - }; + return; + } + var oldIndex = args.OldIndex; + var newIndex = args.NewIndex; + + var items = this.items2; + var itemToMove = items[oldIndex]; + items.RemoveAt(oldIndex); + + if (newIndex < items.Count) + { + items.Insert(newIndex, itemToMove); + } + else + { + items.Add(itemToMove); + } + } } From 3c679b261dee11cd235d9ccdb5a1a76da6940e77 Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 17:39:10 +0200 Subject: [PATCH 5/9] Added a test to verify the Id is added to the list --- ...crosoft.FluentUI.AspNetCore.Components.xml | 4 +-- ...luentUI.AspNetCore.Components.Tests.csproj | 4 +++ ...entSortableList_WithId.verified.razor.html | 33 +++++++++++++++++++ .../FluentSortableListTests.razor | 17 +++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml index a3003085f3..785c9b8e82 100644 --- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml +++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml @@ -7959,13 +7959,13 @@ Gets the index of the item in the list after the update.
- + Gets the id of the list the item was in before the update. May be null if no Id was set for - + Gets the id of the list the item is in after the update. May be null if no Id was set for diff --git a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj index 8a437f05aa..615f331c3b 100644 --- a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj +++ b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj @@ -58,5 +58,9 @@ $([System.String]::Copy('%(FileName)').Split('.')[0]) %(ParentFile).razor + + FluentSortableListTests + FluentSortableListTests.razor + diff --git a/tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html b/tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html new file mode 100644 index 0000000000..6f95a3347d --- /dev/null +++ b/tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html @@ -0,0 +1,33 @@ + +
+
+
Item 1
+
+
+
Item 2
+
+
+
Item 3
+
+
+
Item 4
+
+
+
Item 5
+
+
+
Item 6
+
+
+
Item 7
+
+
+
Item 8
+
+
+
Item 9
+
+
+
Item 10
+
+
diff --git a/tests/Core/SortableList/FluentSortableListTests.razor b/tests/Core/SortableList/FluentSortableListTests.razor index 17686c32ea..9aab803929 100644 --- a/tests/Core/SortableList/FluentSortableListTests.razor +++ b/tests/Core/SortableList/FluentSortableListTests.razor @@ -23,7 +23,7 @@ public void FluentSortableList_Default() { // Arrange && Act - + var cut = Render(@
@context.Name
@@ -34,6 +34,21 @@ cut.Verify(); } + [Fact] + public void FluentSortableList_WithId() + { + // Arrange && Act + + var cut = Render(@ + +
@context.Name
+
+
); + + // Assert + cut.Verify(); + } + } From 87d265012f1e219cb463452dfd35bdbfd8cdba95 Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 17:49:33 +0200 Subject: [PATCH 6/9] Renamed the test to clarify intent --- .../Microsoft.FluentUI.AspNetCore.Components.Tests.csproj | 2 +- ...tTests.FluentSortableList_IdIsAdded.verified.razor.html} | 0 tests/Core/SortableList/FluentSortableListTests.razor | 6 +++++- 3 files changed, 6 insertions(+), 2 deletions(-) rename tests/Core/SortableList/{FluentSortableListTests.FluentSortableList_WithId.verified.razor.html => FluentSortableListTests.FluentSortableList_IdIsAdded.verified.razor.html} (100%) diff --git a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj index 615f331c3b..26ce03977c 100644 --- a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj +++ b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj @@ -58,7 +58,7 @@ $([System.String]::Copy('%(FileName)').Split('.')[0]) %(ParentFile).razor - + FluentSortableListTests FluentSortableListTests.razor diff --git a/tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html b/tests/Core/SortableList/FluentSortableListTests.FluentSortableList_IdIsAdded.verified.razor.html similarity index 100% rename from tests/Core/SortableList/FluentSortableListTests.FluentSortableList_WithId.verified.razor.html rename to tests/Core/SortableList/FluentSortableListTests.FluentSortableList_IdIsAdded.verified.razor.html diff --git a/tests/Core/SortableList/FluentSortableListTests.razor b/tests/Core/SortableList/FluentSortableListTests.razor index 9aab803929..72c675f258 100644 --- a/tests/Core/SortableList/FluentSortableListTests.razor +++ b/tests/Core/SortableList/FluentSortableListTests.razor @@ -35,7 +35,7 @@ } [Fact] - public void FluentSortableList_WithId() + public void FluentSortableList_IdIsAdded() { // Arrange && Act @@ -49,6 +49,10 @@ cut.Verify(); } + [Fact] + public void FluentSortableList_OnUpdateIsCalled() + { + } } From fb90e9ec7512323185e4c63a53f533c44cea5f9b Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 19:50:45 +0200 Subject: [PATCH 7/9] Added unit test for OnUpdate --- .../FluentSortableListTests.razor | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/tests/Core/SortableList/FluentSortableListTests.razor b/tests/Core/SortableList/FluentSortableListTests.razor index 72c675f258..14c623a166 100644 --- a/tests/Core/SortableList/FluentSortableListTests.razor +++ b/tests/Core/SortableList/FluentSortableListTests.razor @@ -1,5 +1,6 @@ @using Xunit; @inherits TestContext + @code { public class Item @@ -25,10 +26,10 @@ // Arrange && Act var cut = Render(@ - -
@context.Name
-
-
); + +
@context.Name
+
+
); // Assert cut.Verify(); @@ -40,19 +41,64 @@ // Arrange && Act var cut = Render(@ - -
@context.Name
-
-
); + +
@context.Name
+
+ ); // Assert cut.Verify(); } [Fact] - public void FluentSortableList_OnUpdateIsCalled() + public void FluentSortableList_OnUpdate() + { + // Arrange + FluentSortableListEventArgs? args = null; + var callback = new EventCallbackFactory().Create + (this, (e => args = e)); + var sortableList = new FluentSortableList() + { + Items = items, + OnUpdate = callback + }; + + // Act + sortableList.OnUpdateJS(0, 1, "fromList", "toList"); + + // Verify + Assert.Equal(new FluentSortableListEventArgs(0, 1, "fromList", "toList"), args, + FluentSortableListEventArgsComparer); + } + + private static bool FluentSortableListEventArgsComparer(FluentSortableListEventArgs? first, FluentSortableListEventArgs? second) { + if (first is null || second is null) + { + return false; + } + + if (first.FromListId is null || !first.FromListId.Equals(second.FromListId)) + { + return false; + } + + if (first.ToListId is null || !first.ToListId.Equals(second.ToListId)) + { + return false; + } + + if (first.OldIndex != second.OldIndex) + { + return false; + } + + if (first.NewIndex != second.NewIndex) + { + return false; + } + return true; } } From e300799ff2b701d27d4e2776837d4543cfbf4496 Mon Sep 17 00:00:00 2001 From: jan hach Date: Mon, 15 Jul 2024 20:26:57 +0200 Subject: [PATCH 8/9] Changed parameter names to reflect property names --- .../Components/SortableList/FluentSortableList.razor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Core/Components/SortableList/FluentSortableList.razor.cs b/src/Core/Components/SortableList/FluentSortableList.razor.cs index aeb999190e..09b4f3a59a 100644 --- a/src/Core/Components/SortableList/FluentSortableList.razor.cs +++ b/src/Core/Components/SortableList/FluentSortableList.razor.cs @@ -126,22 +126,22 @@ protected bool GetItemFiltered(TItem item) } [JSInvokable] - public void OnUpdateJS(int oldIndex, int newIndex, string fromId, string toId) + public void OnUpdateJS(int oldIndex, int newIndex, string fromListId, string toListId) { if (OnUpdate.HasDelegate) { // invoke the OnUpdate event passing in the oldIndex, the newIndex, the fromId and the toId - OnUpdate.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromId, toId)); + OnUpdate.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromListId, toListId)); } } [JSInvokable] - public void OnRemoveJS(int oldIndex, int newIndex, string fromId, string toId) + public void OnRemoveJS(int oldIndex, int newIndex, string fromListId, string toListId) { if (OnRemove.HasDelegate) { // remove the item from the list - OnRemove.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromId, toId)); + OnRemove.InvokeAsync(new FluentSortableListEventArgs(oldIndex, newIndex, fromListId, toListId)); } } From a6ac7c7b8f00881f2d48e0384725c1bd847bcc79 Mon Sep 17 00:00:00 2001 From: jan hach Date: Tue, 16 Jul 2024 10:45:45 +0200 Subject: [PATCH 9/9] Reverted changes made by the IDE --- .../Microsoft.FluentUI.AspNetCore.Components.Tests.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj index 26ce03977c..8a437f05aa 100644 --- a/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj +++ b/tests/Core/Microsoft.FluentUI.AspNetCore.Components.Tests.csproj @@ -58,9 +58,5 @@ $([System.String]::Copy('%(FileName)').Split('.')[0]) %(ParentFile).razor - - FluentSortableListTests - FluentSortableListTests.razor -