Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/warm-ants-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/fe-fpm-writer': patch
---

feat: Action Menu generator added to the FE fpm-writer
60 changes: 60 additions & 0 deletions packages/fe-fpm-writer/src/action-menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { create as createStorage } from 'mem-fs';
import type { Editor } from 'mem-fs-editor';
import { create } from 'mem-fs-editor';
import { render } from 'ejs';
import { validateVersion, validateBasePath } from '../common/validate';
import { getTemplatePath } from '../templates';
import { getJsonSpace } from '../common/file';
import { getManifest } from '../common/utils';
import { enhanceManifestAndGetActionsElementReference } from '../action';
import type { ActionMenu } from './types';

/**
* Enhances the provided custom action configuration with default data.
*
* @param {ActionMenu} data - a custom action configuration object
* @returns enhanced configuration
*/
// function enhanceConfig(data: ActionMenu): ActionMenu {
// // clone input
// const config: ActionMenu = {
// ...data,
// target: { ...data.target },
// settings: { ...data.settings }
// };

// // set default values for visibility and enabled
// config.settings.enabled = config.settings.enabled || true;
// config.settings.visible = config.settings.visible || true;

// return config as ActionMenu;
// }
/**
* Add a custom page to an existing UI5 application.
*
* @param {string} basePath - the base path
* @param {ActionMenu} actionMenuConfig - the custom action configuration
* @param {Editor} [fs] - the memfs editor instance
* @returns {Promise<Editor>} the updated memfs editor instance
*/
export async function generateActionMenu(basePath: string, actionMenuConfig: ActionMenu, fs?: Editor): Promise<Editor> {
validateVersion(actionMenuConfig.minUI5Version);
if (!fs) {
fs = create(createStorage());
}
await validateBasePath(basePath, fs);

const { path: manifestPath, content: manifest } = await getManifest(basePath, fs);

// const config = enhanceConfig(actionMenuConfig);

// enhance manifest with action menu definition
const actionsContainer = enhanceManifestAndGetActionsElementReference(manifest, actionMenuConfig.target);
Object.assign(
actionsContainer,
JSON.parse(render(fs.read(getTemplatePath(`action/manifest.action-menu.json`)), actionMenuConfig, {}))
);
fs.writeJSON(manifestPath, manifest, undefined, getJsonSpace(fs, manifestPath, actionMenuConfig.tabInfo));

return fs;
}
26 changes: 26 additions & 0 deletions packages/fe-fpm-writer/src/action-menu/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { CustomElement, Position } from '../common/types';

export enum TargetControl {
header = 'header',
body = 'body',
// footer = 'footer',
section = '@com.sap.vocabularies.UI.v1.FieldGroup',
table = '@com.sap.vocabularies.UI.v1.LineItem'
}

export interface ActionMenuTarget {
page: string;
control: TargetControl;
customSectionKey?: string;
navProperty?: string;
qualifier?: string;
}

export interface ActionMenu extends CustomElement {
target: ActionMenuTarget;
settings: {
text: string;
actions: string[];
position?: Position;
};
}
3 changes: 3 additions & 0 deletions packages/fe-fpm-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export { generateCustomPage, generateObjectPage, generateListReport } from './pa
export { CustomAction, TargetControl } from './action/types';
export { generateCustomAction } from './action';

export { ActionMenu, TargetControl as ActionMenuTargetControl } from './action-menu/types';
export { generateActionMenu } from './action-menu';

export { CustomTableColumn } from './column/types';
export { generateCustomColumn } from './column';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"<%- name %>": {
"text": "<%- settings.text %>",
"menu": <%- JSON.stringify(settings.actions) %><%if (settings.position) {%>,
"position": {
"placement": "<%- settings.position.placement %>"<%if (settings.position.anchor !== undefined) {%>,
"anchor": "<%- settings.position.anchor %>"<% } %>
}<% } %>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`CustomAction generateActionMenu Test 'position' property. Create with anchor 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"content": Object {
"header": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"position": Object {
"anchor": "Dummy",
"placement": "Before",
},
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
}
`;

exports[`CustomAction generateActionMenu Test 'position' property. Create without anchor 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"content": Object {
"header": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"position": Object {
"placement": "Before",
},
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
}
`;

exports[`CustomAction generateActionMenu Test 'position' property. Create without position 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"content": Object {
"header": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
}
`;

exports[`CustomAction generateActionMenu basic case 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"content": Object {
"header": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
}
`;

exports[`CustomAction generateActionMenu custom section as target 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"content": Object {
"body": Object {
"sections": Object {
"CustomSectionOne": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
},
},
}
`;

exports[`CustomAction generateActionMenu specific control as target 1`] = `
Object {
"sap.app": Object {
"id": "my.test.App",
},
"sap.ui5": Object {
"dependencies": Object {
"libs": Object {
"sap.fe.templates": Object {},
},
},
"routing": Object {
"targets": Object {
"TestObjectPage": Object {
"name": "sap.fe.templates.ListReport",
"options": Object {
"settings": Object {
"controlConfiguration": Object {
"TestItems/@com.sap.vocabularies.UI.v1.LineItem#MyQualifier": Object {
"actions": Object {
"MyCustomActionMenu": Object {
"menu": Array [
"Action1",
"Action2",
],
"text": "My custom action menu text",
},
},
},
},
},
},
},
},
},
},
}
`;
Loading
Loading