From 8dc4eff19d547fb013931aa2b5345bc7379aaa2c Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Wed, 15 May 2024 16:56:17 +0300 Subject: [PATCH 1/7] fix: the logic error on hasAvailableActions function to get the visible action length instead --- .../extensible-table.component.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index 8ed24133f22..4e8be19df11 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -206,8 +206,20 @@ export class ExtensibleTableComponent implements OnChanges { }); } - hasAvailableActions(index, row): boolean { - const { permission, visible } = this.actionList.get(index).value; - return this.permissionService.getGrantedPolicy(permission) && visible(row); + hasAvailableActions(rowData: any): boolean { + const actions = this.actionList.toArray(); + const visibleActions = actions.filter(action => { + const { visible, permission } = action; + + if (permission && visible) { + const visibilityCheck = visible({ record: rowData, getInjected: this.getInjected }); + const permissionCheck = this.permissionService.getGrantedPolicy(permission); + return visibilityCheck && permissionCheck; + } + + return false; + }); + + return visibleActions.length > 0; } } From 676ba0ada064fb854f02ffdd2cb06f3f3ff5dc78 Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Wed, 15 May 2024 16:58:50 +0300 Subject: [PATCH 2/7] update: function parameters --- .../components/extensible-table/extensible-table.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html index 59d50a40ecb..e9b08947e99 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html @@ -17,7 +17,7 @@ *ngTemplateOutlet="actionsTemplate || gridActions; context: { $implicit: row, index: i }" > - @if (hasAvailableActions(i, row)) { + @if (hasAvailableActions(row)) { } From 6aa2361a084500da18089ba5a5a5bce0c212deed Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Thu, 16 May 2024 08:51:54 +0300 Subject: [PATCH 3/7] update: rename hasAvailableActions function as hasVisibleActions --- .../components/extensible-table/extensible-table.component.html | 2 +- .../components/extensible-table/extensible-table.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html index e9b08947e99..de9ecca0a2a 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html @@ -17,7 +17,7 @@ *ngTemplateOutlet="actionsTemplate || gridActions; context: { $implicit: row, index: i }" > - @if (hasAvailableActions(row)) { + @if (hasVisibleActions(row)) { } diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index 4e8be19df11..4d53871f98a 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -206,7 +206,7 @@ export class ExtensibleTableComponent implements OnChanges { }); } - hasAvailableActions(rowData: any): boolean { + hasVisibleActions(rowData: any): boolean { const actions = this.actionList.toArray(); const visibleActions = actions.filter(action => { const { visible, permission } = action; From 1657ba779f2256d347acd0f85a1875e1f30d4a3f Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Thu, 16 May 2024 09:10:03 +0300 Subject: [PATCH 4/7] fix: logical error if action has neither permission nor visible config by default --- .../components/extensible-table/extensible-table.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index 4d53871f98a..c58c7ab307c 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -217,7 +217,7 @@ export class ExtensibleTableComponent implements OnChanges { return visibilityCheck && permissionCheck; } - return false; + return true; }); return visibleActions.length > 0; From 62f4a873f0248d96c5592fb31e7b30915f3c8295 Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Thu, 16 May 2024 13:28:15 +0300 Subject: [PATCH 5/7] update: rename hasVisibleActions function as isVisibleActions --- .../components/extensible-table/extensible-table.component.html | 2 +- .../components/extensible-table/extensible-table.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html index de9ecca0a2a..689fc60f059 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.html @@ -17,7 +17,7 @@ *ngTemplateOutlet="actionsTemplate || gridActions; context: { $implicit: row, index: i }" > - @if (hasVisibleActions(row)) { + @if (isVisibleActions(row)) { } diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index c58c7ab307c..c385c1a2aff 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -206,7 +206,7 @@ export class ExtensibleTableComponent implements OnChanges { }); } - hasVisibleActions(rowData: any): boolean { + isVisibleActions(rowData: any): boolean { const actions = this.actionList.toArray(); const visibleActions = actions.filter(action => { const { visible, permission } = action; From 4f5d1b6482ad059804764485ba89c62f00a6485b Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Thu, 16 May 2024 14:26:58 +0300 Subject: [PATCH 6/7] fix: cover all possible availability cases for visible and permission properties --- .../extensible-table.component.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index c385c1a2aff..40d0a238bc5 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -211,13 +211,22 @@ export class ExtensibleTableComponent implements OnChanges { const visibleActions = actions.filter(action => { const { visible, permission } = action; - if (permission && visible) { - const visibilityCheck = visible({ record: rowData, getInjected: this.getInjected }); - const permissionCheck = this.permissionService.getGrantedPolicy(permission); - return visibilityCheck && permissionCheck; + // Case 1: assuming that the action has neither permission nor visible properties, so no need to make an extra check + let isVisible = true; + let hasPermission = true; + + // Case 2: action has visible condition + if (visible) { + isVisible = visible({ record: rowData, getInjected: this.getInjected }); + } + + // Case 3: action has permission condition + if (permission) { + hasPermission = this.permissionService.getGrantedPolicy(permission); } - return true; + // Return true if the action is both visible and has permission, otherwise return false + return isVisible && hasPermission; }); return visibleActions.length > 0; From e7e1ef041921a9859fcdaf055c1a9afcdc2b89b5 Mon Sep 17 00:00:00 2001 From: sumeyyeKurtulus Date: Thu, 16 May 2024 15:01:41 +0300 Subject: [PATCH 7/7] update: remove non-necessary comments --- .../components/extensible-table/extensible-table.component.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts index 40d0a238bc5..e7b8371240a 100644 --- a/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts +++ b/npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts @@ -211,21 +211,17 @@ export class ExtensibleTableComponent implements OnChanges { const visibleActions = actions.filter(action => { const { visible, permission } = action; - // Case 1: assuming that the action has neither permission nor visible properties, so no need to make an extra check let isVisible = true; let hasPermission = true; - // Case 2: action has visible condition if (visible) { isVisible = visible({ record: rowData, getInjected: this.getInjected }); } - // Case 3: action has permission condition if (permission) { hasPermission = this.permissionService.getGrantedPolicy(permission); } - // Return true if the action is both visible and has permission, otherwise return false return isVisible && hasPermission; });