Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create custom table action v2 app #2941

Merged
merged 6 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/nervous-tables-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ux-private/preview-middleware-client': patch
'@sap-ux/preview-middleware': patch
---

fix: "Add Table Custom Action" quick action not being working in some V2 apps
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getControlById, isA } from '../../../utils/core';
import { DialogFactory, DialogNames } from '../../dialog-factory';
import { TableQuickActionDefinitionBase } from '../table-quick-action-base';
import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator';
import type OverflowToolbar from 'sap/m/OverflowToolbar';
import { NestedQuickActionChild } from '@sap-ux-private/control-property-editor-common';

export const CREATE_TABLE_ACTION = 'create-table-action';
const SMART_TABLE_TYPE = 'sap.ui.comp.smarttable.SmartTable';
Expand All @@ -25,6 +27,25 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im
]);
}

async initialize(): Promise<void> {
const processChild = (child: NestedQuickActionChild, mapKey: string) => {
const table = this.tableMap[mapKey]?.table;
if (table) {
const headerToolbar = this.getHeaderToolbar(table);
if (!headerToolbar) {
child.enabled = false;
child.tooltip = this.context.resourceBundle.getText('NO_TABLE_HEADER_TOOLBAR');
}
}

child.children.forEach((nestedChild, idx) => processChild(nestedChild, `${mapKey}/${idx.toFixed(0)}`));
};

await super.initialize();

// disable nested actions based on conditions
this.children.forEach((nestedChild, idx) => processChild(nestedChild, `${idx.toFixed(0)}`));
}
async execute(path: string): Promise<FlexCommand[]> {
const { table, iconTabBarFilterKey, sectionInfo } = this.tableMap[path];
if (!table) {
Expand All @@ -45,12 +66,7 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im
this.iconTabBar.setSelectedKey(iconTabBarFilterKey);
}

let headerToolbar;
if (isA<SmartTable>(SMART_TABLE_TYPE, table)) {
headerToolbar = (table.getAggregation('items') as ManagedObject[])[0].getAggregation('headerToolbar');
} else if (isA<Table>(M_TABLE_TYPE, table)) {
headerToolbar = table.getAggregation('headerToolbar');
}
const headerToolbar = this.getHeaderToolbar(table);

// open dialogBox to add, and content is selected ByDefault
if (headerToolbar) {
Expand All @@ -62,4 +78,19 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im
}
return [];
}

getHeaderToolbar(table: UI5Element): ManagedObject | ManagedObject[] | OverflowToolbar | null | undefined {
let headerToolbar;
if (isA<SmartTable>(SMART_TABLE_TYPE, table)) {
headerToolbar = (table.getAggregation('items') as ManagedObject[]).find((item) => {
if (item.getAggregation('headerToolbar')) {
return true;
}
return isA<OverflowToolbar>('sap.m.OverflowToolbar', item);
});
} else if (isA<Table>(M_TABLE_TYPE, table)) {
headerToolbar = table.getAggregation('headerToolbar');
}
return headerToolbar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ EMPTY_ROW_MODE_IS_NOT_SUPPORTED=This action is disabled because empty row mode i
VARIANT_MANAGEMENT_FOR_PAGE_CONTROLS_IS_ALREADY_ENABLED=This option has been disabled because variant management is already enabled for tables and charts
VARIANT_MANAGEMENT_FOR_TABLE_CONTROLS_IS_ALREADY_ENABLED=This option has been disabled because variant management is already enabled for the ''{0}''
VARIANT_MANAGEMENT_FOR_CUSTOM_TABLES_NOT_SUPPORTED=Variant management cannot be set for custom table ''{0}''
NO_TABLE_HEADER_TOOLBAR=This option has been disabled because the table does not have a header toolbar.

ADD_ANNOTATION_FILE=Add Annotation File for ''{0}''
SHOW_ANNOTATION_FILE=Show Annotation File for ''{0}''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,19 @@ describe('FE V2 quick actions', () => {
});

describe('create table action', () => {
test('initialize and execute', async () => {
const testCases = [
{
tableType: M_TABLE_TYPE
},
{
tableType: SMART_TABLE_TYPE,
overflowTable: true,
headerToolbar: false
},
{ tableType: SMART_TABLE_TYPE, headerToolbar: true },
{ tableType: SMART_TABLE_TYPE, isTableWithoutToolbar: true }
];
test.each(testCases)('initialize and execute action (%s)', async (testCase) => {
const pageView = new XMLView();
const scrollIntoView = jest.fn();
sapCoreMock.byId.mockImplementation((id) => {
Expand All @@ -571,6 +583,51 @@ describe('FE V2 quick actions', () => {
}
};
}
if (id == 'smartTable') {
return {
isA: (type: string) => type === SMART_TABLE_TYPE,
getHeader: () => 'MyTable',
getId: () => id,
getDomRef: () => ({
scrollIntoView
}),

getAggregation: (aggregationName: string) => {
if (aggregationName === 'items') {
if (testCase.headerToolbar) {
return [
{
isA: (type: string) => type === testCase.tableType,
getAggregation: (aggregationName: string) => {
if (aggregationName === 'headerToolbar') {
return 'headerToolbar'; // Return a simple string for headerToolbar
}
}
}
];
} else if (testCase.overflowTable) {
return [
{
getAggregation: () => null,
isA: (type: string) => type === 'sap.m.OverflowToolbar'
}
];
} else {
return [
{
getAggregation: () => null,
isA: (type: string) => type === 'test'
}
];
}
}
return [];
},
getParent: () => pageView,
getBusy: () => false,
selectOverlay: () => ({})
};
}
if (id == 'NavContainer') {
const container = new NavContainer();
const component = new UIComponentMock();
Expand Down Expand Up @@ -615,69 +672,92 @@ describe('FE V2 quick actions', () => {
);
await service.init(sendActionMock, subscribeMock);

await service.reloadQuickActions({
'sap.m.Table': [
{
controlId: 'mTable'
} as any
],
'sap.m.NavContainer': [
{
controlId: 'NavContainer'
} as any
]
});
if (testCase.tableType === M_TABLE_TYPE) {
await service.reloadQuickActions({
'sap.m.Table': [
{
controlId: 'mTable'
} as any
],

'sap.m.NavContainer': [
{
controlId: 'NavContainer'
} as any
]
});
} else if (testCase.tableType === SMART_TABLE_TYPE) {
await service.reloadQuickActions({
'sap.ui.comp.smarttable.SmartTable': [
{
controlId: 'smartTable'
} as any
],

'sap.m.NavContainer': [
{
controlId: 'NavContainer'
} as any
]
});
}

expect(sendActionMock).toHaveBeenCalledWith(
quickActionListChanged([
{
title: 'LIST REPORT',
actions: [
{
'kind': 'nested',
kind: 'nested',
id: 'listReport0-create-table-action',
title: 'Add Custom Table Action',
enabled: true,
children: [
{
children: [],
enabled: true,
label: `'MyTable' table`
enabled: !testCase.isTableWithoutToolbar,
label: `'MyTable' table`,
...(testCase.isTableWithoutToolbar && {
tooltip:
'This option has been disabled because the table does not have a header toolbar.'
})
}
]
},
{
'children': [
children: [
{
'children': [],
children: [],
enabled: true,
'label': `'MyTable' table`
label: `'MyTable' table`
}
],
'enabled': true,
'id': 'listReport0-create-table-custom-column',
'kind': 'nested',
'title': 'Add Custom Table Column'
enabled: true,
id: 'listReport0-create-table-custom-column',
kind: 'nested',
title: 'Add Custom Table Column'
}
]
}
])
);

await subscribeMock.mock.calls[0][0](
executeQuickAction({ id: 'listReport0-create-table-action', kind: 'nested', path: '0' })
);
expect(DialogFactory.createDialog).toHaveBeenCalledTimes(testCase.isTableWithoutToolbar ? 0 : 1);

expect(DialogFactory.createDialog).toHaveBeenCalledWith(
mockOverlay,
rtaMock,
'AddFragment',
undefined,
{
aggregation: 'content',
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
}
);
if (!testCase.isTableWithoutToolbar) {
expect(DialogFactory.createDialog).toHaveBeenCalledWith(
mockOverlay,
rtaMock,
'AddFragment',
undefined,
{
aggregation: 'content',
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
}
);
}
});
});

Expand Down