From e0cd23d3b16e331e8a61decab275ba7ed83d6071 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Fri, 24 Jan 2025 19:15:06 +0200 Subject: [PATCH 1/7] fix: bug fix --- .../fe-v4/create-table-action.ts | 44 +++++++++---------- .../fe-v4/table-quick-action-base.ts | 3 ++ .../src/adp/quick-actions/fe-v4/utils.ts | 14 ++++++ .../test/unit/adp/quick-actions/fe-v4.test.ts | 21 ++++++++- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts index 2efa385da3..9a955128db 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts @@ -8,6 +8,7 @@ import { DialogFactory, DialogNames } from '../../dialog-factory'; import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator'; import { TableQuickActionDefinitionBase } from './table-quick-action-base'; import { MDC_TABLE_TYPE } from '../control-types'; +import { findParentById } from './utils'; export const CREATE_TABLE_ACTION = 'create_table_action'; const TOOLBAR_ACTION = 'sap.ui.mdc.ActionToolbar'; @@ -24,28 +25,27 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im async execute(path: string): Promise { const index = this.tableMap[path]; - const smartTablesToolbarAction = getRelevantControlFromActivePage( - this.context.controlIndex, - this.context.view, - [TOOLBAR_ACTION] - ); - for (let i = 0; i < smartTablesToolbarAction.length; i++) { - if (i === index) { - const section = getControlById(smartTablesToolbarAction[i].getId()); - const controlOverlay = OverlayUtil.getClosestOverlayFor(section); - if (controlOverlay) { - controlOverlay.setSelected(true); - await DialogFactory.createDialog( - controlOverlay, - this.context.rta, - DialogNames.ADD_FRAGMENT, - undefined, - { - aggregation: 'actions', - title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION' - } - ); - } + const actionToolbars = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ + TOOLBAR_ACTION + ]); + + const smartTableId = this.smartTables[index].getId(); + const toolBar = actionToolbars.find((item) => findParentById(item, smartTableId) !== undefined); + if (toolBar) { + const section = getControlById(toolBar.getId()); + const controlOverlay = OverlayUtil.getClosestOverlayFor(section); + if (controlOverlay) { + controlOverlay.setSelected(true); + await DialogFactory.createDialog( + controlOverlay, + this.context.rta, + DialogNames.ADD_FRAGMENT, + undefined, + { + aggregation: 'actions', + title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION' + } + ); } } diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts index c0ef815771..82263c635d 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts @@ -8,6 +8,7 @@ import { QuickActionContext } from '../../../cpe/quick-actions/quick-action-defi import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; import { EnablementValidator } from '../enablement-validator'; import { QuickActionDefinitionBase } from '../quick-action-base'; +import UI5Element from 'sap/ui/core/Element'; const ACTION_ID = 'CTX_SETTINGS0'; @@ -19,6 +20,7 @@ export abstract class TableQuickActionDefinitionBase extends QuickActionDefiniti isClearButtonEnabled = false; children: NestedQuickActionChild[] = []; tableMap: Record = {}; + smartTables: UI5Element[] = []; constructor( public readonly type: string, protected readonly controlTypes: string[], @@ -53,6 +55,7 @@ export abstract class TableQuickActionDefinitionBase extends QuickActionDefiniti children: [] }); this.tableMap[`${this.children.length - 1}`] = index; + this.smartTables.push(smartTable); index++; } } diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts index 5c0f571bd3..c9c994cc71 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts @@ -3,6 +3,7 @@ import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import { QuickActionContext } from '../../../cpe/quick-actions/quick-action-definition'; import CommandFactory from 'sap/ui/rta/command/CommandFactory'; import { getAppComponent, getPageName, getReference } from '../../../utils/fe-v4'; +import ManagedObject from 'sap/ui/base/ManagedObject'; export async function executeToggleAction( context: QuickActionContext, @@ -51,3 +52,16 @@ export async function executeToggleAction( return []; } + +export function findParentById(el: ManagedObject, id: string): ManagedObject | undefined { + const parent = el.getParent(); + if (!parent) { + return undefined; + } else { + if (parent.getId() === id) { + return parent; + } else { + return findParentById(parent, id); + } + } +} diff --git a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts index c2498aef55..6c7313b4c6 100644 --- a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts +++ b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts @@ -46,6 +46,7 @@ import { TableQuickActionDefinitionBase } from '../../../../src/adp/quick-action import * as QCUtils from '../../../../src/cpe/quick-actions/utils'; import ManagedObject from 'sap/ui/base/ManagedObject'; import * as versionUtils from 'open/ux/preview/client/utils/version'; +import { isA } from 'open/ux/preview/client/utils/core'; describe('FE V4 quick actions', () => { let sendActionMock: jest.Mock; @@ -660,6 +661,7 @@ describe('FE V4 quick actions', () => { jest.spyOn(ComponentMock, 'getOwnerComponentFor').mockImplementation(() => { return component as unknown as UIComponent; }); + let toolBarIndex = -1; sapCoreMock.byId.mockImplementation((id) => { if (id == 'Table') { return { @@ -675,14 +677,26 @@ describe('FE V4 quick actions', () => { } if (id == 'ToolbarAction') { + toolBarIndex++; return { isA: (type: string) => type === 'sap.ui.mdc.ActionToolbar', - getHeader: () => 'MyTable', + getHeader: () => 'MyChart', getId: () => id, getDomRef: () => ({ scrollIntoView }), - getParent: () => pageView, + getParent: () => + toolBarIndex == 0 + ? pageView + : { + isA: (type: string) => type === GRID_TABLE_TYPE, + getId: () => 'GridTable', + getParent: () => ({ + getId: () => 'Table', + isA: (type: string) => type === 'sap.ui.mdc.Table', + getParent: () => pageView + }) + }, getBusy: () => false }; } @@ -746,6 +760,9 @@ describe('FE V4 quick actions', () => { } as any ], 'sap.ui.mdc.ActionToolbar': [ + { + controlId: 'ToolbarAction' + } as any, { controlId: 'ToolbarAction' } as any From 0d40580f01744f5dc873212772ca42ae71b2cbc8 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Fri, 24 Jan 2025 19:41:14 +0200 Subject: [PATCH 2/7] fix: cset added --- .changeset/cyan-sloths-grow.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/cyan-sloths-grow.md diff --git a/.changeset/cyan-sloths-grow.md b/.changeset/cyan-sloths-grow.md new file mode 100644 index 0000000000..6aca2253c6 --- /dev/null +++ b/.changeset/cyan-sloths-grow.md @@ -0,0 +1,6 @@ +--- +'@sap-ux-private/preview-middleware-client': patch +'@sap-ux/preview-middleware': patch +--- + +fix: CPE Quick action bug fix in ALP v4 projects. Add Custom Table Action worked incorrectly on Analytical Pages having multiple action toolbars in charts and tables. From dd372c750503a0519a6f3bdb9bbd1b054c0153e4 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Fri, 24 Jan 2025 20:16:07 +0200 Subject: [PATCH 3/7] fix: linter --- .../test/unit/adp/quick-actions/fe-v4.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts index 6c7313b4c6..6bb59af1f8 100644 --- a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts +++ b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts @@ -46,7 +46,6 @@ import { TableQuickActionDefinitionBase } from '../../../../src/adp/quick-action import * as QCUtils from '../../../../src/cpe/quick-actions/utils'; import ManagedObject from 'sap/ui/base/ManagedObject'; import * as versionUtils from 'open/ux/preview/client/utils/version'; -import { isA } from 'open/ux/preview/client/utils/core'; describe('FE V4 quick actions', () => { let sendActionMock: jest.Mock; From a989ce7256b8820a3c32063ff152e41c0051d826 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Mon, 27 Jan 2025 10:00:44 +0200 Subject: [PATCH 4/7] fix: linter, jsdoc --- .../src/adp/quick-actions/fe-v4/utils.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts index c9c994cc71..e622c0bf2e 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts @@ -53,15 +53,19 @@ export async function executeToggleAction( return []; } +/** + * Recursively searches element (Managed Object) parents by id + * @param el element to search parents + * @param id parent id to search + * @returns parent element with the given id, if found, otherwise undefined + */ export function findParentById(el: ManagedObject, id: string): ManagedObject | undefined { const parent = el.getParent(); if (!parent) { return undefined; + } else if (parent.getId() === id) { + return parent; } else { - if (parent.getId() === id) { - return parent; - } else { - return findParentById(parent, id); - } + return findParentById(parent, id); } } From 03d915d6bcdca957d3056b2d9ed0170466070308 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Thu, 30 Jan 2025 15:38:02 +0200 Subject: [PATCH 5/7] fix: refactored v4 table related quick actions to reuse common table actions base class --- .changeset/cyan-sloths-grow.md | 3 +- .../adp/controllers/AddFragment.controller.ts | 2 +- .../fe-v4/change-table-columns.ts | 66 +++++++++++----- .../fe-v4/create-table-action.ts | 44 ++++------- .../fe-v4/lr-enable-table-filtering.ts | 23 +++--- .../fe-v4/table-quick-action-base.ts | 78 ------------------- .../test/unit/adp/quick-actions/fe-v4.test.ts | 66 +++++++--------- 7 files changed, 105 insertions(+), 177 deletions(-) delete mode 100644 packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts diff --git a/.changeset/cyan-sloths-grow.md b/.changeset/cyan-sloths-grow.md index 6aca2253c6..7445ff1492 100644 --- a/.changeset/cyan-sloths-grow.md +++ b/.changeset/cyan-sloths-grow.md @@ -3,4 +3,5 @@ '@sap-ux/preview-middleware': patch --- -fix: CPE Quick action bug fix in ALP v4 projects. Add Custom Table Action worked incorrectly on Analytical Pages having multiple action toolbars in charts and tables. +fix: CPE Quick action bug fix in ALP v4 projects. Add Custom Table Action worked incorrectly on Analytical Pages with multiple action toolbars in charts and tables. +Some V4 Quick Action code refactoring to optimize diff --git a/packages/preview-middleware-client/src/adp/controllers/AddFragment.controller.ts b/packages/preview-middleware-client/src/adp/controllers/AddFragment.controller.ts index 392a0b69d0..44711b7071 100644 --- a/packages/preview-middleware-client/src/adp/controllers/AddFragment.controller.ts +++ b/packages/preview-middleware-client/src/adp/controllers/AddFragment.controller.ts @@ -264,7 +264,7 @@ export default class AddFragment extends BaseDialog { targetAggregation === 'columns' ) { return 'ANALYTICAL_TABLE_COLUMN'; - } else if (currentControlName === 'sap.ui.mdc.ActionToolbar' && targetAggregation === 'actions') { + } else if (currentControlName === 'sap.ui.mdc.Table' && targetAggregation === 'actions') { return 'TABLE_ACTION'; } return ''; diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/change-table-columns.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/change-table-columns.ts index 1fd9826019..a2c0fbeaa4 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/change-table-columns.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/change-table-columns.ts @@ -2,15 +2,15 @@ import OverlayUtil from 'sap/ui/dt/OverlayUtil'; import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import FlexRuntimeInfoAPI from 'sap/ui/fl/apply/api/FlexRuntimeInfoAPI'; import { QuickActionContext, NestedQuickActionDefinition } from '../../../cpe/quick-actions/quick-action-definition'; -import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; import { getControlById } from '../../../utils/core'; -import { TableQuickActionDefinitionBase } from './table-quick-action-base'; +import { TableQuickActionDefinitionBase } from '../table-quick-action-base'; import { MDC_TABLE_TYPE } from '../control-types'; import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator'; +import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; +import Table from 'sap/ui/mdc/Table'; export const CHANGE_TABLE_COLUMNS = 'change-table-columns'; const ACTION_ID = 'CTX_SETTINGS0'; -const CONTROL_TYPE = 'sap.ui.mdc.Table'; /** * Quick Action for changing table columns. @@ -25,24 +25,50 @@ export class ChangeTableColumnsQuickAction ]); } - async execute(path: string): Promise { - const index = this.tableMap[path]; - const smartTables = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ - CONTROL_TYPE - ]); - for (let i = 0; i < smartTables.length; i++) { - if (i === index) { - const section = getControlById(smartTables[i].getId()); - const controlOverlay = OverlayUtil.getClosestOverlayFor(section); - if (controlOverlay) { - controlOverlay.setSelected(true); - } - const hasVariantManagement = FlexRuntimeInfoAPI.hasVariantManagement({ element: smartTables[i] }); - if (!hasVariantManagement) { - continue; - } - await this.context.actionService.execute(smartTables[i].getId(), ACTION_ID); + async initialize(): Promise { + for (const smartTable of getRelevantControlFromActivePage( + this.context.controlIndex, + this.context.view, + this.controlTypes + )) { + const hasVariantManagement = FlexRuntimeInfoAPI.hasVariantManagement({ element: smartTable }); + if (!hasVariantManagement) { + continue; } + + const actions = await this.context.actionService.get(smartTable.getId()); + const changeColumnAction = actions.find((action) => action.id === ACTION_ID); + if (changeColumnAction) { + this.children.push({ + label: `'${(smartTable as Table).getHeader()}' table`, + enabled: true, + children: [] + }); + this.tableMap[`${this.children.length - 1}`] = { + table: smartTable, + tableUpdateEventAttachedOnce: false + }; + } + } + + if (this.children.length > 0) { + this.isApplicable = true; + } + } + + async execute(path: string): Promise { + const { table } = this.tableMap[path]; + if (!table) { + return []; + } + const tableControl = getControlById(table.getId()); + const controlOverlay = OverlayUtil.getClosestOverlayFor(tableControl); + if (controlOverlay) { + controlOverlay.setSelected(true); + } + const hasVariantManagement = FlexRuntimeInfoAPI.hasVariantManagement({ element: table }); + if (hasVariantManagement) { + await this.context.actionService.execute(table.getId(), ACTION_ID); } return []; diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts index 9a955128db..cc93a96c57 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/create-table-action.ts @@ -2,51 +2,41 @@ import OverlayUtil from 'sap/ui/dt/OverlayUtil'; import type FlexCommand from 'sap/ui/rta/command/FlexCommand'; import { QuickActionContext, NestedQuickActionDefinition } from '../../../cpe/quick-actions/quick-action-definition'; -import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; import { getControlById } from '../../../utils/core'; import { DialogFactory, DialogNames } from '../../dialog-factory'; import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator'; -import { TableQuickActionDefinitionBase } from './table-quick-action-base'; +import { TableQuickActionDefinitionBase } from '../table-quick-action-base'; import { MDC_TABLE_TYPE } from '../control-types'; -import { findParentById } from './utils'; +import { preprocessActionExecution } from '../fe-v2/create-table-custom-column'; export const CREATE_TABLE_ACTION = 'create_table_action'; -const TOOLBAR_ACTION = 'sap.ui.mdc.ActionToolbar'; /** * Quick Action for creating table action. */ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase implements NestedQuickActionDefinition { constructor(context: QuickActionContext) { - super(CREATE_TABLE_ACTION, [MDC_TABLE_TYPE], 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION', context, true, [ + super(CREATE_TABLE_ACTION, [MDC_TABLE_TYPE], 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION', context, undefined, [ DIALOG_ENABLEMENT_VALIDATOR ]); } async execute(path: string): Promise { - const index = this.tableMap[path]; - const actionToolbars = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ - TOOLBAR_ACTION - ]); + const { table, sectionInfo, iconTabBarFilterKey } = this.tableMap[path]; + if (!table) { + return []; + } + + preprocessActionExecution(table, sectionInfo, this.iconTabBar, iconTabBarFilterKey); + const tableControl = getControlById(table.getId()); + const controlOverlay = OverlayUtil.getClosestOverlayFor(tableControl); + if (controlOverlay) { + controlOverlay.setSelected(true); - const smartTableId = this.smartTables[index].getId(); - const toolBar = actionToolbars.find((item) => findParentById(item, smartTableId) !== undefined); - if (toolBar) { - const section = getControlById(toolBar.getId()); - const controlOverlay = OverlayUtil.getClosestOverlayFor(section); - if (controlOverlay) { - controlOverlay.setSelected(true); - await DialogFactory.createDialog( - controlOverlay, - this.context.rta, - DialogNames.ADD_FRAGMENT, - undefined, - { - aggregation: 'actions', - title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION' - } - ); - } + await DialogFactory.createDialog(controlOverlay, this.context.rta, DialogNames.ADD_FRAGMENT, undefined, { + aggregation: 'actions', + title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION' + }); } return []; diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/lr-enable-table-filtering.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/lr-enable-table-filtering.ts index 4b5f53a5e7..939f51ce6a 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/lr-enable-table-filtering.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/lr-enable-table-filtering.ts @@ -2,7 +2,7 @@ import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import { NestedQuickActionDefinition, QuickActionContext } from '../../../cpe/quick-actions/quick-action-definition'; import Table from 'sap/ui/mdc/Table'; -import { TableQuickActionDefinitionBase } from './table-quick-action-base'; +import { TableQuickActionDefinitionBase } from '../table-quick-action-base'; import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; import { createManifestPropertyChange } from '../../../utils/fe-v4'; import { getUi5Version, isLowerThanMinimalUi5Version } from '../../../utils/version'; @@ -38,7 +38,7 @@ export class EnableTableFilteringQuickAction } const tooltipText = this.context.resourceBundle.getText('TABLE_FILTERING_CHANGE_HAS_ALREADY_BEEN_MADE'); - let index = 0; + for (const smartTable of getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ MDC_TABLE_TYPE ])) { @@ -54,27 +54,22 @@ export class EnableTableFilteringQuickAction tooltip: isFilterEnabled ? tooltipText : undefined, children: [] }); - this.tableMap[`${this.children.length - 1}`] = index; - index++; + this.tableMap[`${this.children.length - 1}`] = { + table: smartTable, + tableUpdateEventAttachedOnce: false + }; } if (this.children.length > 0) { this.isApplicable = true; } - - return Promise.resolve(); } async execute(path: string): Promise { const { flexSettings } = this.context; - const index = this.tableMap[path]; - - const smartTables = getRelevantControlFromActivePage(this.context.controlIndex, this.context.view, [ - MDC_TABLE_TYPE - ]); + const { table } = this.tableMap[path]; - const modifiedControl = smartTables[index]; - if (!modifiedControl) { + if (!table) { return []; } const propertyChange = { @@ -86,7 +81,7 @@ export class EnableTableFilteringQuickAction aggregate: true } }; - const command = await createManifestPropertyChange(modifiedControl, flexSettings, propertyChange); + const command = await createManifestPropertyChange(table, flexSettings, propertyChange); if (command) { return [command]; } else { diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts deleted file mode 100644 index 82263c635d..0000000000 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/table-quick-action-base.ts +++ /dev/null @@ -1,78 +0,0 @@ -import Table from 'sap/ui/mdc/Table'; -import FlexRuntimeInfoAPI from 'sap/ui/fl/apply/api/FlexRuntimeInfoAPI'; - -import type { NestedQuickActionChild, NestedQuickAction } from '@sap-ux-private/control-property-editor-common'; -import { NESTED_QUICK_ACTION_KIND } from '@sap-ux-private/control-property-editor-common'; - -import { QuickActionContext } from '../../../cpe/quick-actions/quick-action-definition'; -import { getRelevantControlFromActivePage } from '../../../cpe/quick-actions/utils'; -import { EnablementValidator } from '../enablement-validator'; -import { QuickActionDefinitionBase } from '../quick-action-base'; -import UI5Element from 'sap/ui/core/Element'; - -const ACTION_ID = 'CTX_SETTINGS0'; - -export abstract class TableQuickActionDefinitionBase extends QuickActionDefinitionBase< - typeof NESTED_QUICK_ACTION_KIND -> { - isApplicable = false; - - isClearButtonEnabled = false; - children: NestedQuickActionChild[] = []; - tableMap: Record = {}; - smartTables: UI5Element[] = []; - constructor( - public readonly type: string, - protected readonly controlTypes: string[], - protected readonly defaultTextKey: string, - protected readonly context: QuickActionContext, - protected readonly isSkipVariantManagementCheck?: boolean, - protected readonly enablementValidators: EnablementValidator[] = [] - ) { - super(type, NESTED_QUICK_ACTION_KIND, defaultTextKey, context, enablementValidators); - } - - async initialize(): Promise { - let index = 0; - for (const smartTable of getRelevantControlFromActivePage( - this.context.controlIndex, - this.context.view, - this.controlTypes - )) { - if (!this.isSkipVariantManagementCheck) { - const hasVariantManagement = FlexRuntimeInfoAPI.hasVariantManagement({ element: smartTable }); - if (!hasVariantManagement) { - continue; - } - } - - const actions = await this.context.actionService.get(smartTable.getId()); - const changeColumnAction = actions.find((action) => action.id === ACTION_ID); - if (changeColumnAction) { - this.children.push({ - label: `'${(smartTable as Table).getHeader()}' table`, - enabled: true, - children: [] - }); - this.tableMap[`${this.children.length - 1}`] = index; - this.smartTables.push(smartTable); - index++; - } - } - - if (this.children.length > 0) { - this.isApplicable = true; - } - } - - getActionObject(): NestedQuickAction { - return { - kind: NESTED_QUICK_ACTION_KIND, - id: this.id, - enabled: !this.isDisabled, - tooltip: this.tooltip, - title: this.context.resourceBundle.getText(this.textKey), - children: this.children - }; - } -} diff --git a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts index 6bb59af1f8..29d5861a76 100644 --- a/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts +++ b/packages/preview-middleware-client/test/unit/adp/quick-actions/fe-v4.test.ts @@ -660,7 +660,6 @@ describe('FE V4 quick actions', () => { jest.spyOn(ComponentMock, 'getOwnerComponentFor').mockImplementation(() => { return component as unknown as UIComponent; }); - let toolBarIndex = -1; sapCoreMock.byId.mockImplementation((id) => { if (id == 'Table') { return { @@ -675,31 +674,6 @@ describe('FE V4 quick actions', () => { }; } - if (id == 'ToolbarAction') { - toolBarIndex++; - return { - isA: (type: string) => type === 'sap.ui.mdc.ActionToolbar', - getHeader: () => 'MyChart', - getId: () => id, - getDomRef: () => ({ - scrollIntoView - }), - getParent: () => - toolBarIndex == 0 - ? pageView - : { - isA: (type: string) => type === GRID_TABLE_TYPE, - getId: () => 'GridTable', - getParent: () => ({ - getId: () => 'Table', - isA: (type: string) => type === 'sap.ui.mdc.Table', - getParent: () => pageView - }) - }, - getBusy: () => false - }; - } - if (id == 'NavContainer') { const container = new NavContainer(); const component = new TemplateComponentMock(); @@ -758,14 +732,6 @@ describe('FE V4 quick actions', () => { controlId: 'Table' } as any ], - 'sap.ui.mdc.ActionToolbar': [ - { - controlId: 'ToolbarAction' - } as any, - { - controlId: 'ToolbarAction' - } as any - ], 'sap.m.NavContainer': [ { controlId: 'NavContainer' @@ -818,7 +784,7 @@ describe('FE V4 quick actions', () => { describe('create table custom column', () => { test('initialize and execute action (%s)', async () => { const pageView = new XMLView(); - jest.spyOn(FlexRuntimeInfoAPI, 'hasVariantManagement').mockReturnValue(true); + jest.spyOn(FlexRuntimeInfoAPI, 'hasVariantManagement').mockReturnValue(false); const scrollIntoView = jest.fn(); const appComponent = new AppComponentMock(); const component = new TemplateComponentMock(); @@ -905,6 +871,20 @@ describe('FE V4 quick actions', () => { } ], 'enabled': true, + 'id': 'listReport0-create_table_action', + 'kind': 'nested', + 'title': 'Add Custom Table Action', + 'tooltip': undefined + }, + { + 'children': [ + { + 'children': [], + 'enabled': true, + 'label': `'MyTable' table` + } + ], + 'enabled': true, 'id': 'listReport0-create-table-custom-column', 'kind': 'nested', 'title': 'Add Custom Table Column' @@ -1051,7 +1031,21 @@ describe('FE V4 quick actions', () => { 'children': [ { 'children': [], - enabled: true, + 'enabled': true, + 'label': `'MyTable' table` + } + ], + 'enabled': true, + 'id': 'listReport0-create_table_action', + 'kind': 'nested', + 'title': 'Add Custom Table Action', + 'tooltip': undefined + }, + { + 'children': [ + { + 'children': [], + 'enabled': true, 'label': `'MyTable' table` } ], From a62d63c77ed1d4c2a089ba7b91e1d078ba62b08c Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Thu, 30 Jan 2025 16:19:19 +0200 Subject: [PATCH 6/7] fix: unit test fix --- .../test/unit/adp/controllers/AddFragment.controller.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/preview-middleware-client/test/unit/adp/controllers/AddFragment.controller.test.ts b/packages/preview-middleware-client/test/unit/adp/controllers/AddFragment.controller.test.ts index 88d1eff4d6..14cc05247e 100644 --- a/packages/preview-middleware-client/test/unit/adp/controllers/AddFragment.controller.test.ts +++ b/packages/preview-middleware-client/test/unit/adp/controllers/AddFragment.controller.test.ts @@ -1247,7 +1247,7 @@ describe('AddFragment', () => { jest.spyOn(ControlUtils, 'getRuntimeControl').mockReturnValue({ getMetadata: jest.fn().mockReturnValue({ getAllAggregations: jest.fn().mockReturnValue({}), - getName: jest.fn().mockReturnValue('sap.ui.mdc.ActionToolbar') + getName: jest.fn().mockReturnValue('sap.ui.mdc.Table') }) } as unknown as ManagedObject); From 07210f7282dae929af616cc359d1bd8325660256 Mon Sep 17 00:00:00 2001 From: "GLOBAL\\vadson71" Date: Thu, 30 Jan 2025 17:16:41 +0200 Subject: [PATCH 7/7] fix: cleanup --- .../src/adp/quick-actions/fe-v4/utils.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts index e622c0bf2e..5c0f571bd3 100644 --- a/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts +++ b/packages/preview-middleware-client/src/adp/quick-actions/fe-v4/utils.ts @@ -3,7 +3,6 @@ import FlexCommand from 'sap/ui/rta/command/FlexCommand'; import { QuickActionContext } from '../../../cpe/quick-actions/quick-action-definition'; import CommandFactory from 'sap/ui/rta/command/CommandFactory'; import { getAppComponent, getPageName, getReference } from '../../../utils/fe-v4'; -import ManagedObject from 'sap/ui/base/ManagedObject'; export async function executeToggleAction( context: QuickActionContext, @@ -52,20 +51,3 @@ export async function executeToggleAction( return []; } - -/** - * Recursively searches element (Managed Object) parents by id - * @param el element to search parents - * @param id parent id to search - * @returns parent element with the given id, if found, otherwise undefined - */ -export function findParentById(el: ManagedObject, id: string): ManagedObject | undefined { - const parent = el.getParent(); - if (!parent) { - return undefined; - } else if (parent.getId() === id) { - return parent; - } else { - return findParentById(parent, id); - } -}