Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 3a55313

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
refactor(gridMenu): add customItems array check in code before using it
1 parent 42f1632 commit 3a55313

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class GridMenuExtension implements Extension {
7474

7575
// merge original user grid menu items with internal items
7676
// then sort all Grid Menu Custom Items (sorted by pointer, no need to use the return)
77-
const originalCustomItems = this._userOriginalGridMenu.customItems || [];
77+
const originalCustomItems = Array.isArray(this._userOriginalGridMenu.customItems) && this._userOriginalGridMenu.customItems || [];
7878
this.sharedService.gridOptions.gridMenu.customItems = [...originalCustomItems, ...this.addGridMenuCustomCommands(originalCustomItems)];
7979
this.extensionUtility.translateItems(this.sharedService.gridOptions.gridMenu.customItems, 'titleKey', 'title');
8080
this.extensionUtility.sortItems(this.sharedService.gridOptions.gridMenu.customItems, 'positionOrder');
@@ -194,7 +194,7 @@ export class GridMenuExtension implements Extension {
194194

195195
// merge original user grid menu items with internal items
196196
// then sort all Grid Menu Custom Items (sorted by pointer, no need to use the return)
197-
const originalCustomItems = this._userOriginalGridMenu.customItems || [];
197+
const originalCustomItems = Array.isArray(this._userOriginalGridMenu.customItems) && this._userOriginalGridMenu.customItems || [];
198198
this.sharedService.gridOptions.gridMenu.customItems = [...originalCustomItems, ...this.addGridMenuCustomCommands(originalCustomItems)];
199199
this.extensionUtility.translateItems(this.sharedService.gridOptions.gridMenu.customItems, 'titleKey', 'title');
200200
this.extensionUtility.sortItems(this.sharedService.gridOptions.gridMenu.customItems, 'positionOrder');
@@ -222,9 +222,6 @@ export class GridMenuExtension implements Extension {
222222
private addGridMenuCustomCommands(originalCustomItems: GridMenuItem[]) {
223223
const backendApi = this.sharedService.gridOptions.backendServiceApi || null;
224224
const gridMenuCustomItems: GridMenuItem[] = [];
225-
if (!Array.isArray(originalCustomItems)) {
226-
originalCustomItems = [];
227-
}
228225

229226
if (this.sharedService.gridOptions && this.sharedService.gridOptions.enableFiltering) {
230227
// show grid menu: clear all filters

0 commit comments

Comments
 (0)