Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
97665ad
feat: consume AddXMLPlugin
mmilko01 Apr 2, 2025
a2277eb
fix: set default plugins
mmilko01 Apr 2, 2025
2dff258
fix: set default plugins
mmilko01 Apr 2, 2025
9d10560
feat: consume ExtendController plugin
mmilko01 Apr 3, 2025
41e992f
fix: types
mmilko01 Apr 3, 2025
4025d6a
fix: controller extension handler function
mmilko01 Apr 7, 2025
6f72c67
merge: main
mmilko01 Apr 7, 2025
60b2855
chore: temporary disabled unit tests
mmilko01 Apr 7, 2025
ae4f88d
feat: consume addXMLPlugin
mmilko01 Apr 7, 2025
655f913
fix: add removed empty line
mmilko01 Apr 7, 2025
71e1edd
fix: change required ui5 version
mmilko01 Apr 7, 2025
e6aab39
Linting auto fix commit
github-actions[bot] Apr 7, 2025
0c7cb38
chore: create changeset
mmilko01 Apr 7, 2025
1aacc4d
test: add missing rta method
mmilko01 Apr 7, 2025
c82a24a
test: enabled table columns tests
mmilko01 Apr 7, 2025
21e9b3e
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 7, 2025
564535f
fix: remove unneeded subscribe function
mmilko01 Apr 8, 2025
db9f1ae
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 8, 2025
1477915
fix: remove unneeded imports
mmilko01 Apr 8, 2025
bce4294
fix: wrong return type
mmilko01 Apr 8, 2025
48efacc
refactor: static methods in AddFragmentService class
mmilko01 Apr 8, 2025
a3b2d71
fix: remove unneeded action
mmilko01 Apr 8, 2025
035c512
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 8, 2025
4bba6c7
test: stabilize current tests
mmilko01 Apr 8, 2025
19e7759
test: add tests for add-fragment
mmilko01 Apr 8, 2025
c0f78c3
test: enhance init-dialogs tests
mmilko01 Apr 8, 2025
b1f18be
fix: ehnahce AddFragment controlle tests
mmilko01 Apr 8, 2025
bf5064f
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 8, 2025
5b6f399
test: uncovered branches
mmilko01 Apr 8, 2025
52b93e8
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 8, 2025
a877d91
chore: remove changeset module
mmilko01 Apr 8, 2025
765d2c8
chore: update changeset description
mmilko01 Apr 8, 2025
1848f0a
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 8, 2025
3255ea8
fix: pass templateName to plugin
mmilko01 Apr 8, 2025
244d68d
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 8, 2025
32fb34e
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 9, 2025
2fa7058
refactor: simplify add-fragment
mmilko01 Apr 9, 2025
d95d85d
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 9, 2025
273a1d7
fix: remove unneeded variable
mmilko01 Apr 9, 2025
c071ceb
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 9, 2025
4a99e67
fix: cycling dependency
mmilko01 Apr 9, 2025
43cce02
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 9, 2025
dca61de
refactor: create extended change object and set it in Session Storage
mmilko01 Apr 14, 2025
becdeeb
fix: return type
mmilko01 Apr 15, 2025
c6eefb8
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 16, 2025
f778721
refacor: move additional info in utils
mmilko01 Apr 16, 2025
b9be108
fix: return type
mmilko01 Apr 17, 2025
84d2a86
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 17, 2025
8e000e1
fix: rename parameters
mmilko01 Apr 17, 2025
2e0f591
test: stabilize current tests
mmilko01 Apr 17, 2025
3f975fc
fix: lint issues
mmilko01 Apr 17, 2025
2354d41
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 17, 2025
2dbaf94
fix: get additional change info in connector service
mmilko01 Apr 17, 2025
1556072
fix: lint issues
mmilko01 Apr 17, 2025
8874cb2
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 17, 2025
3f6e999
refactor: use map instead of sessionStorage
mmilko01 Apr 17, 2025
108c227
test: fix tests
mmilko01 Apr 17, 2025
c3aaa62
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 22, 2025
b6c6a5f
test: add coverage
mmilko01 Apr 22, 2025
62e57b8
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 22, 2025
d9bf6ac
fix: sonar issue
mmilko01 Apr 22, 2025
3abe3e5
fix: review comments
mmilko01 Apr 22, 2025
c70e392
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 22, 2025
bac4f26
chore: update patchset
mmilko01 Apr 22, 2025
2544692
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 22, 2025
2ef86d9
fix: address review comments
mmilko01 Apr 23, 2025
a523c61
fix: wrong class name
mmilko01 Apr 23, 2025
b1269eb
test: fix mock
mmilko01 Apr 24, 2025
cc95acd
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 24, 2025
5ca415e
fix: address review comments
mmilko01 Apr 24, 2025
dc54e19
Merge branch 'feat/consume-addxml-plugin' of https://github.com/SAP/o…
mmilko01 Apr 24, 2025
d124ee9
test: remove unneeded mocks
mmilko01 Apr 24, 2025
506d8ca
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 25, 2025
998384e
Merge branch 'main' into feat/consume-addxml-plugin
mmilko01 Apr 25, 2025
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
7 changes: 7 additions & 0 deletions .changeset/stupid-clouds-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@sap-ux/adp-tooling": patch
"@sap-ux-private/preview-middleware-client": patch
"@sap-ux/preview-middleware": patch
---

refactor: Enhance XML Fragment context menu control with addXMLPlugin Integration
14 changes: 11 additions & 3 deletions packages/adp-tooling/src/preview/adp-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { createAbapServiceProvider } from '@sap-ux/system-access';
import type { LayeredRepositoryService, MergedAppDescriptor } from '@sap-ux/axios-extension';

import RoutesHandler from './routes-handler';
import type { AdpPreviewConfig, CommonChangeProperties, DescriptorVariant, OperationType } from '../types';
import type {
AdpPreviewConfig,
CommonChangeProperties,
DescriptorVariant,
OperationType,
CommonAdditionalChangeInfoProperties
} from '../types';
import type { Editor } from 'mem-fs-editor';
import {
addAnnotationFile,
Expand Down Expand Up @@ -233,13 +239,15 @@ export class AdpPreview {
* @param {CommonChangeProperties} change - An object containing properties common to all change types.
* @param {Editor} fs - An instance of an editor interface for file system operations.
* @param {Logger} logger - An instance of a logging interface for message logging.
* @param {CommonAdditionalChangeInfoProperties} [additionalChangeInfo] - An optional object containing extended change properties.
* @returns {Promise<void>} A promise that resolves when the change request has been processed.
*/
async onChangeRequest(
type: OperationType,
change: CommonChangeProperties,
fs: Editor,
logger: Logger
logger: Logger,
additionalChangeInfo?: CommonAdditionalChangeInfoProperties
): Promise<void> {
switch (type) {
case 'read':
Expand All @@ -249,7 +257,7 @@ export class AdpPreview {
break;
case 'write':
if (isAddXMLChange(change)) {
addXmlFragment(this.util.getProject().getSourcePath(), change, fs, logger);
addXmlFragment(this.util.getProject().getSourcePath(), change, fs, logger, additionalChangeInfo);
}
if (isAddAnnotationChange(change)) {
await addAnnotationFile(
Expand Down
19 changes: 16 additions & 3 deletions packages/adp-tooling/src/preview/change-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Editor } from 'mem-fs-editor';
import type { AddXMLChange, CommonChangeProperties, CodeExtChange, AnnotationFileChange } from '../types';
import type {
AddXMLChange,
CommonChangeProperties,
CodeExtChange,
AnnotationFileChange,
CommonAdditionalChangeInfoProperties
} from '../types';
import { ChangeType } from '../types';
import { basename, join } from 'path';
import { DirName, FileName } from '@sap-ux/project-access';
Expand Down Expand Up @@ -211,11 +217,18 @@ export function isAddAnnotationChange(change: CommonChangeProperties): change is
* @param {AddXMLChange} change - The change data, including the fragment path.
* @param {Editor} fs - The mem-fs-editor instance.
* @param {Logger} logger - The logging instance.
* @param {CommonAdditionalChangeInfoProperties} additionalChangeInfo - Optional extended change properties.
*/
export function addXmlFragment(basePath: string, change: AddXMLChange, fs: Editor, logger: Logger): void {
export function addXmlFragment(
basePath: string,
change: AddXMLChange,
fs: Editor,
logger: Logger,
additionalChangeInfo?: CommonAdditionalChangeInfoProperties
): void {
const { fragmentPath } = change.content;
const fullPath = join(basePath, DirName.Changes, fragmentPath);
const templateConfig = fragmentTemplateDefinitions[change.content?.templateName ?? ''];
const templateConfig = fragmentTemplateDefinitions[additionalChangeInfo?.templateName ?? ''];
try {
if (templateConfig) {
const fragmentTemplatePath = join(__dirname, '../../templates/rta', templateConfig.path);
Expand Down
4 changes: 4 additions & 0 deletions packages/adp-tooling/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export interface CommonChangeProperties {
texts: Record<string, unknown>;
}

export interface CommonAdditionalChangeInfoProperties {
templateName?: string;
}

export interface ManifestChangeProperties {
fileName: string;
fileType: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,13 @@ describe('AdaptationProject', () => {
it('should add an XML fragment if type is "write" and change is AddXMLChange', async () => {
await adp.onChangeRequest('write', addXMLChange, mockFs, mockLogger);

expect(addXmlFragmentMock).toHaveBeenCalledWith('/adp.project/webapp', addXMLChange, mockFs, mockLogger);
expect(addXmlFragmentMock).toHaveBeenCalledWith(
'/adp.project/webapp',
addXMLChange,
mockFs,
mockLogger,
undefined
);
});

it('should not perform any action if type is "delete"', async () => {
Expand Down
76 changes: 24 additions & 52 deletions packages/adp-tooling/test/unit/preview/change-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,13 @@ describe('change-handler', () => {
});
it('should create Object Page custom section fragment', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `OBJECT_PAGE_CUSTOM_SECTION`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.objectPageSection %>"
id="<%- ids.objectPageSubSection %>"
id="<%- ids.hBox %>"`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `OBJECT_PAGE_CUSTOM_SECTION`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -226,17 +221,12 @@ id="<%- ids.hBox %>"`);

it('should create Object Page header field fragment', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `OBJECT_PAGE_HEADER_FIELD`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.vBoxContainer %>"
id="<%- ids.label %>"`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `OBJECT_PAGE_HEADER_FIELD`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -260,16 +250,11 @@ id="<%- ids.label %>"`);

it('should create custom action fragment', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `CUSTOM_ACTION`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.toolbarActionButton %>`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `CUSTOM_ACTION`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -296,7 +281,6 @@ id="<%- ids.toolbarActionButton %>`);
...change,
content: {
...change.content,
templateName: `V2_SMART_TABLE_COLUMN`,
index: 1
}
} as unknown as AddXMLChange;
Expand All @@ -306,7 +290,9 @@ id="<%- ids.columnTitle %>
id="<%- ids.customData %>
id="<%- ids.index %>
`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `V2_SMART_TABLE_COLUMN`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -333,17 +319,12 @@ id="<%- ids.index %>

it('should create custom table cell fragment (V2 smart table)', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `V2_SMART_TABLE_CELL`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.text %>
`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `V2_SMART_TABLE_CELL`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -367,18 +348,13 @@ id="<%- ids.text %>

it('should create custom table column fragment (V4 smart table)', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `V4_MDC_TABLE_COLUMN`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.column %>
id="<%- ids.text %>
`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `V4_MDC_TABLE_COLUMN`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand Down Expand Up @@ -420,7 +396,6 @@ id="<%- ids.text %>
...change,
content: {
...change.content,
templateName: testCase.tableType,
index: 1
}
} as unknown as AddXMLChange;
Expand All @@ -431,7 +406,9 @@ id="<%- ids.text %>
id="<%- ids.customData %>
id="<%- ids.index %>
`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: testCase.tableType
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand All @@ -457,17 +434,12 @@ id="<%- ids.index %>

it('should create custom page action', () => {
mockFs.exists.mockReturnValue(false);
const updatedChange = {
...change,
content: {
...change.content,
templateName: `TABLE_ACTION`
}
} as unknown as AddXMLChange;
mockFs.read.mockReturnValue(`
id="<%- ids.customToolbarAction %>"
id="<%- ids.customActionButton %>"`);
addXmlFragment(path, updatedChange, mockFs as unknown as Editor, mockLogger as unknown as Logger);
addXmlFragment(path, change, mockFs as unknown as Editor, mockLogger as unknown as Logger, {
templateName: `TABLE_ACTION`
});

expect(mockFs.read).toHaveBeenCalled();
expect(
Expand Down
51 changes: 51 additions & 0 deletions packages/preview-middleware-client/src/adp/add-fragment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring';
import type UI5Element from 'sap/ui/core/Element';
import CommandFactory from 'sap/ui/rta/command/CommandFactory';
import { Deferred, createDeferred } from './utils';
import { DialogFactory, DialogNames } from './dialog-factory';
import AddXMLPlugin from 'sap/ui/rta/plugin/AddXMLPlugin';

export interface AddFragmentData {
deferred: Deferred<DeferredXmlFragmentData>;
}

export type DeferredXmlFragmentData = {
fragment: string;
fragmentPath: string;
targetAggregation: string;
index: number;
};

/**
* Initializes the AddXMLPlugin and includes it in the Runtime Authoring (RTA) plugins.
*
* @param rta Runtime Authoring instance
*/
export function initAddXMLPlugin(rta: RuntimeAuthoring): void {
const flexSettings = rta.getFlexSettings();
const commandFactory = new CommandFactory({ flexSettings });

const plugin = new AddXMLPlugin({
commandFactory,
fragmentHandler: async (overlay: UI5Element) => await handleFragmentCreation(rta, overlay)
});

const plugins = rta.getPlugins();
plugins.addXMLPlugin = plugin;
rta.setPlugins(plugins);
}

/**
* Handles the creation of a fragment by opening a dialog and resolving the deferred data.
*
* @param rta Runtime Authoring instance
* @param overlay UI5 Element overlay
* @returns A promise that resolves with DeferredXmlFragmentData
*/
async function handleFragmentCreation(rta: RuntimeAuthoring, overlay: UI5Element): Promise<DeferredXmlFragmentData> {
const deferred = createDeferred<DeferredXmlFragmentData>();

await DialogFactory.createDialog(overlay, rta, DialogNames.ADD_FRAGMENT, { deferred });

return deferred.promise;
}
4 changes: 2 additions & 2 deletions packages/preview-middleware-client/src/adp/api-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface AnnotationFileDetails {
}

export interface AnnotationDataSourceMap {
[key: string]: { serviceUrl: string; annotationDetails: AnnotationFileDetails, metadataReadErrorMsg: string };
[key: string]: { serviceUrl: string; annotationDetails: AnnotationFileDetails; metadataReadErrorMsg: string };
}

export interface AnnotationDataSourceResponse {
Expand Down Expand Up @@ -181,5 +181,5 @@ export async function getExistingController(controllerName: string): Promise<Cod
* @returns Generic Promise<T>
*/
export async function writeChange<T>(data: T): Promise<T> {
return request<T>(ApiEndpoints.CHANGES, RequestMethod.POST, data);
return request<T>(ApiEndpoints.CHANGES, RequestMethod.POST, { change: data });
}
Loading