From 0896ece4459015b792c0f0b40f506dcb2818db3f Mon Sep 17 00:00:00 2001 From: Antonio <58663328+Kr4tos94@users.noreply.github.com> Date: Sat, 18 Nov 2023 18:25:58 +0100 Subject: [PATCH] Fix issue #14119 - Migrating mutate function to update function for WritableSignal updates. --- .../components/cascadeselect/cascadeselect.ts | 2 +- src/app/components/contextmenu/contextmenu.ts | 25 +++++---- src/app/components/megamenu/megamenu.ts | 11 ++-- src/app/components/menubar/menubar.ts | 7 +-- src/app/components/panelmenu/panelmenu.ts | 2 +- src/app/components/slidemenu/slidemenu.ts | 51 +++++++++---------- src/app/components/tieredmenu/tieredmenu.ts | 5 +- 7 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/app/components/cascadeselect/cascadeselect.ts b/src/app/components/cascadeselect/cascadeselect.ts index 249530d350a..1439ff3e23a 100755 --- a/src/app/components/cascadeselect/cascadeselect.ts +++ b/src/app/components/cascadeselect/cascadeselect.ts @@ -980,7 +980,7 @@ export class CascadeSelect implements OnInit, AfterContentInit { changeFocusedOptionIndex(event, index) { if (this.focusedOptionInfo().index !== index) { - this.focusedOptionInfo.mutate((value) => (value.index = index)); + this.focusedOptionInfo.update((value) => ({...value, index})); this.scrollInView(); } diff --git a/src/app/components/contextmenu/contextmenu.ts b/src/app/components/contextmenu/contextmenu.ts index 0b593c9e55a..608be226516 100755 --- a/src/app/components/contextmenu/contextmenu.ts +++ b/src/app/components/contextmenu/contextmenu.ts @@ -833,10 +833,11 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy { onEscapeKey(event: KeyboardEvent) { this.hide(); const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex()); - this.focusedItemInfo.mutate((value) => { - value.index = this.findFirstFocusedItemIndex(); - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: this.findFirstFocusedItemIndex(), + item: processedItem.item + })); event.preventDefault(); } @@ -863,9 +864,10 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy { const grouped = this.isProccessedItemGroup(processedItem); if (!grouped) { - this.focusedItemInfo.mutate((value) => { - value.index = this.findFirstFocusedItemIndex(); - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: this.findFirstFocusedItemIndex() + })); } } @@ -1086,10 +1088,11 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy { changeFocusedItemIndex(event: any, index: number) { const processedItem = this.findVisibleItem(index); if (this.focusedItemInfo().index !== index) { - this.focusedItemInfo.mutate((value) => { - value.index = index; - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: index, + item: processedItem.item + })); this.scrollInView(); } } diff --git a/src/app/components/megamenu/megamenu.ts b/src/app/components/megamenu/megamenu.ts index 061a28c31c6..ccd01dcf877 100755 --- a/src/app/components/megamenu/megamenu.ts +++ b/src/app/components/megamenu/megamenu.ts @@ -830,11 +830,12 @@ export class MegaMenu implements AfterContentInit, OnDestroy, OnInit { changeFocusedItemInfo(event, index) { const processedItem = this.findVisibleItem(index); - this.focusedItemInfo.mutate((value) => { - value.index = index; - value.key = ObjectUtils.isNotEmpty(processedItem) ? processedItem.key : ''; - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: index, + key: ObjectUtils.isNotEmpty(processedItem) ? processedItem.key : '', + item: processedItem.item + })); this.scrollInView(); } diff --git a/src/app/components/menubar/menubar.ts b/src/app/components/menubar/menubar.ts index de2caaaecb6..453fd9f48c4 100755 --- a/src/app/components/menubar/menubar.ts +++ b/src/app/components/menubar/menubar.ts @@ -669,12 +669,9 @@ export class Menubar implements AfterContentInit, OnDestroy, OnInit { } changeFocusedItemIndex(event: any, index: number) { - const processedItem = this.findVisibleItem(index); + const { item } = this.findVisibleItem(index); if (this.focusedItemInfo().index !== index) { - this.focusedItemInfo.mutate((value) => { - value.index = index; - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({...value, index, item })); this.scrollInView(); } } diff --git a/src/app/components/panelmenu/panelmenu.ts b/src/app/components/panelmenu/panelmenu.ts index 690d791b0ba..98e34dcde19 100644 --- a/src/app/components/panelmenu/panelmenu.ts +++ b/src/app/components/panelmenu/panelmenu.ts @@ -492,7 +492,7 @@ export class PanelMenuList implements OnChanges { expanded && activeItemPath.push(processedItem); this.activeItemPath.set(activeItemPath); - this.processedItems.mutate((value) => value.map((i) => (i === processedItem ? processedItem : i))); + this.processedItems.update((value) => value.map((i) => (i === processedItem ? processedItem : i))); this.focusedItem.set(processedItem); } diff --git a/src/app/components/slidemenu/slidemenu.ts b/src/app/components/slidemenu/slidemenu.ts index f9444b4be06..2cf435ca2a1 100755 --- a/src/app/components/slidemenu/slidemenu.ts +++ b/src/app/components/slidemenu/slidemenu.ts @@ -711,12 +711,13 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { const grouped = this.isProcessedItemGroup(processedItem); if (grouped) { - this.focusedItemInfo.mutate((value) => { - value.index = -1; - value.level = value.level + 1; - value.parentKey = processedItem.key; - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: -1, + level: value.level + 1, + parentKey: processedItem.key, + item: processedItem.item + })); this.animate('right'); } else { this.onItemChange(event); @@ -796,10 +797,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { case 'Enter': case 'Space': this.onArrowLeftKey(event); - this.focusedItemInfo.mutate((value) => { - value.index = -1; - value.item = null; - }); + this.focusedItemInfo.update((value) => ({...value, index: -1, item: null })); break; default: break; @@ -909,10 +907,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { onEscapeKey(event: KeyboardEvent) { if (this.popup) { this.hide(event, true); - this.focusedItemInfo.mutate((value) => { - value.index = this.findLastFocusedItemIndex(); - value.item = null; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: this.findLastFocusedItemIndex(), + item: null + })); event.preventDefault(); } @@ -941,10 +940,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { const anchorElement = element && DomHandler.findSingle(element, 'a[data-pc-section="action"]'); anchorElement ? anchorElement.click() : element && element.click(); - this.focusedItemInfo.mutate((value) => { - value.index = processedItem.index; - value.item = processedItem.item; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: processedItem.index, + item: processedItem.item + })); } } @@ -976,7 +976,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { } if (this.focusedItemInfo().index === -1 && this.left < 0) { - this.focusedItemInfo.mutate((value) => (value.index = 0)); + this.focusedItemInfo.update((value) => ({...value, index: 0})); } if (this.focusedItemInfo().index === -1 && !this.left) { @@ -988,10 +988,11 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { this.focused = false; this.popup && this.focusedItemInfo.set({ index: -1, level: 0, parentKey: '', item: null }); if (!this.popup) { - this.focusedItemInfo.mutate((value) => { - value.index = -1; - value.item = null; - }); + this.focusedItemInfo.update((value) => ({ + ...value, + index: -1, + item: null + })); } this.searchValue = ''; !this.popup && this.unbindOutsideClickListener(); @@ -1217,9 +1218,7 @@ export class SlideMenu implements OnInit, AfterContentInit, OnDestroy { changeFocusedItemIndex(event: any, index: number) { if (this.focusedItemInfo().index !== index) { - this.focusedItemInfo.mutate((value) => { - value.index = index; - }); + this.focusedItemInfo.update((value) => ({...value, index})); this.scrollInView(); } } diff --git a/src/app/components/tieredmenu/tieredmenu.ts b/src/app/components/tieredmenu/tieredmenu.ts index 9f063f8f3ed..ad47598f4ab 100755 --- a/src/app/components/tieredmenu/tieredmenu.ts +++ b/src/app/components/tieredmenu/tieredmenu.ts @@ -1064,10 +1064,7 @@ export class TieredMenu implements OnInit, AfterContentInit, OnDestroy { changeFocusedItemIndex(event: any, index: number) { if (this.focusedItemInfo().index !== index) { - this.focusedItemInfo.mutate((value) => { - value.index = index; - value.item = this.visibleItems[index].item; - }); + this.focusedItemInfo.update((value) => ({ ...value, index, item: this.visibleItems[index].item })); this.scrollInView(); } }