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: default aggregation index #2933

Merged
merged 8 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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/forty-toys-punch.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: Default aggregation array index to 1 for create page action and create table action
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type AddFragmentModel = JSONModel & {
export interface AddFragmentOptions {
title: string;
aggregation?: string;
defaultAggregationArrayIndex?: number;
}

/**
Expand Down Expand Up @@ -203,6 +204,10 @@ export default class AddFragment extends BaseDialog<AddFragmentModel> {
this.model.setProperty('/selectedIndex', indexArray.length - 1);
this.model.setProperty('/targetAggregation', controlAggregation);
this.model.setProperty('/index', indexArray);
const defaultIndex = Number(this.options.defaultAggregationArrayIndex);
if (defaultIndex >= 0) {
this.model.setProperty('/selectedIndex', indexArray.length - 1 > 0 ? defaultIndex : 0);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export class DialogFactory {
case DialogNames.ADD_FRAGMENT:
controller = new AddFragment(`open.ux.preview.client.adp.controllers.${dialogName}`, overlay, rta, {
...('aggregation' in options && { aggregation: options.aggregation }),
...('defaultAggregationArrayIndex' in options && {
defaultAggregationArrayIndex: options.defaultAggregationArrayIndex
}),
title: resources.getText(options.title ?? 'ADP_ADD_FRAGMENT_DIALOG_TITLE')
});
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FlexCommand from 'sap/ui/rta/command/FlexCommand';
import { DialogFactory, DialogNames } from '../../dialog-factory';
import { QuickActionContext, SimpleQuickActionDefinition } from '../../../cpe/quick-actions/quick-action-definition';
import { SimpleQuickActionDefinitionBase } from '../simple-quick-action-base';
import { getApplicationType } from '../../../utils/application';
import { ApplicationType, getApplicationType } from '../../../utils/application';
import { getUi5Version, isLowerThanMinimalUi5Version } from '../../../utils/version';
import { DIALOG_ENABLEMENT_VALIDATOR } from '../dialog-enablement-validator';

Expand All @@ -15,16 +15,17 @@ const CONTROL_TYPES = ['sap.f.DynamicPageTitle', 'sap.uxap.ObjectPageHeader', 's
* Quick Action for adding a custom page action.
*/
export class AddPageActionQuickAction extends SimpleQuickActionDefinitionBase implements SimpleQuickActionDefinition {
private readonly appType: ApplicationType;
constructor(context: QuickActionContext) {
super(ADD_PAGE_ACTION, CONTROL_TYPES, 'QUICK_ACTION_ADD_CUSTOM_PAGE_ACTION', context, [
DIALOG_ENABLEMENT_VALIDATOR
]);
this.appType = getApplicationType(this.context.rta.getRootControlInstance().getManifest());
}

async initialize(): Promise<void> {
const appType = getApplicationType(this.context.rta.getRootControlInstance().getManifest());
const version = await getUi5Version();
if (appType === 'fe-v4' && isLowerThanMinimalUi5Version(version, { major: 1, minor: 130 })) {
if (this.appType === 'fe-v4' && isLowerThanMinimalUi5Version(version, { major: 1, minor: 130 })) {
return;
}
await super.initialize();
Expand All @@ -35,7 +36,8 @@ export class AddPageActionQuickAction extends SimpleQuickActionDefinitionBase im
const overlay = OverlayRegistry.getOverlay(this.control) || [];
await DialogFactory.createDialog(overlay, this.context.rta, DialogNames.ADD_FRAGMENT, undefined, {
aggregation: 'actions',
title: 'QUICK_ACTION_ADD_CUSTOM_PAGE_ACTION'
title: 'QUICK_ACTION_ADD_CUSTOM_PAGE_ACTION',
defaultAggregationArrayIndex: 1
});
}
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im
const overlay = OverlayRegistry.getOverlay(headerToolbar as UI5Element) || [];
await DialogFactory.createDialog(overlay, this.context.rta, DialogNames.ADD_FRAGMENT, undefined, {
aggregation: 'content',
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION',
defaultAggregationArrayIndex: 1
});
}
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AddTableActionQuickAction extends TableQuickActionDefinitionBase im

await DialogFactory.createDialog(controlOverlay, this.context.rta, DialogNames.ADD_FRAGMENT, undefined, {
aggregation: 'actions',
defaultAggregationArrayIndex: 0,
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,80 @@ describe('AddFragment', () => {

expect(openSpy).toHaveBeenCalledTimes(1);
});

test('fills json model with data and defaultAggregationArrayIndex', async () => {
const overlays = {
getId: jest.fn().mockReturnValue('some-id')
};

ControlUtils.getRuntimeControl = jest.fn().mockReturnValue({
getMetadata: jest.fn().mockReturnValue({
getAllAggregations: jest.fn().mockReturnValue({
'tooltip': {},
'customData': {},
'layoutData': {},
'dependents': {},
'dragDropConfig': {},
'content': {}
}),
getDefaultAggregationName: jest.fn().mockReturnValue('content'),
getName: jest.fn().mockReturnValue('Toolbar')
})
});

ControlUtils.getControlAggregationByName = jest
.fn()
.mockReturnValue({ 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {} });

const overlayControl = {
getDesignTimeMetadata: jest.fn().mockReturnValue({
getData: jest.fn().mockReturnValue({
aggregations: { content: { actions: { move: null }, domRef: ':sap-domref' } }
})
})
};
sapCoreMock.byId.mockReturnValue(overlayControl);

OverlayRegistry.getOverlay = jest.fn().mockReturnValue({
getDesignTimeMetadata: jest.fn().mockReturnValue({
getData: jest.fn().mockReturnValue({
aggregations: {}
})
})
});

const addFragment = new AddFragment(
'adp.extension.controllers.AddFragment',
overlays as unknown as UI5Element,
{} as unknown as RuntimeAuthoring,
{
title: 'ADP_ADD_FRAGMENT_DIALOG_TITLE',
defaultAggregationArrayIndex: 1
}
);

const openSpy = jest.fn();
const setPropertySpy = jest.fn();
addFragment.model = {
setProperty: setPropertySpy
} as unknown as JSONModel;
await addFragment.setup({
setEscapeHandler: jest.fn(),
destroy: jest.fn(),
setModel: jest.fn(),
open: openSpy,
close: jest.fn()
} as unknown as Dialog);

const escapeHandlerCb = (addFragment.dialog.setEscapeHandler as jest.Mock).mock.calls[0][0];

escapeHandlerCb({ resolve: jest.fn() });

expect(openSpy).toHaveBeenCalledTimes(1);
const lastCall = setPropertySpy.mock.calls[setPropertySpy.mock.calls.length - 1];
expect(lastCall[0]).toBe('/selectedIndex');
expect(lastCall[1]).toBe(1);
});
});

describe('onAggregationChanged', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ describe('DialogFactory', () => {
await DialogFactory.createDialog(
{} as unknown as UI5Element,
rtaMock as unknown as RuntimeAuthoring,
DialogNames.ADD_FRAGMENT
DialogNames.ADD_FRAGMENT,
undefined,
{
aggregation: 'actions',
defaultAggregationArrayIndex: 1
}
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(Fragment.load.mock.calls[0][0].name).toStrictEqual('open.ux.preview.client.adp.ui.AddFragment');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ describe('FE V2 quick actions', () => {
undefined,
{
aggregation: 'content',
defaultAggregationArrayIndex: 1,
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
}
);
Expand Down Expand Up @@ -805,6 +806,7 @@ describe('FE V2 quick actions', () => {
undefined,
{
aggregation: 'actions',
'defaultAggregationArrayIndex': 1,
title: 'QUICK_ACTION_ADD_CUSTOM_PAGE_ACTION'
}
);
Expand Down Expand Up @@ -2227,6 +2229,7 @@ describe('FE V2 quick actions', () => {
undefined,
{
aggregation: 'content',
defaultAggregationArrayIndex: 1,
title: 'QUICK_ACTION_ADD_CUSTOM_TABLE_ACTION'
}
);
Expand Down