Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/nx_updates_v2' into nx_updates_v2
Browse files Browse the repository at this point in the history
* origin/nx_updates_v2:
  chore: apply latest changesets
  fix: Handle higher layer changes (#2536)
  • Loading branch information
devinea committed Nov 15, 2024
2 parents cb62880 + 9fe9b57 commit 34b52ab
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 7 deletions.
8 changes: 8 additions & 0 deletions packages/create/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @sap-ux/create

## 0.8.78

### Patch Changes

- Updated dependencies [1f7827c]
- @sap-ux/preview-middleware@0.16.118
- @sap-ux/app-config-writer@0.4.52

## 0.8.77

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sap-ux/create",
"description": "SAP Fiori tools module to add or remove features",
"version": "0.8.77",
"version": "0.8.78",
"repository": {
"type": "git",
"url": "https://github.com/SAP/open-ux-tools.git",
Expand Down
6 changes: 6 additions & 0 deletions packages/preview-middleware-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sap-ux-private/preview-middleware-client

## 0.11.31

### Patch Changes

- 1f7827c: handle higher layer changes

## 0.11.30

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/preview-middleware-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sap-ux-private/preview-middleware-client",
"version": "0.11.30",
"version": "0.11.31",
"description": "Client-side coding hosted by the preview middleware",
"repository": {
"type": "git",
Expand Down
39 changes: 35 additions & 4 deletions packages/preview-middleware-client/src/flp/init.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import Log from 'sap/base/Log';
import type AppLifeCycle from 'sap/ushell/services/AppLifeCycle';
import type { InitRtaScript, RTAPlugin, StartAdaptation } from 'sap/ui/rta/api/startAdaptation';
import { SCENARIO, type Scenario } from '@sap-ux-private/control-property-editor-common';
import { SCENARIO, showMessage, type Scenario } from '@sap-ux-private/control-property-editor-common';
import type { FlexSettings, RTAOptions } from 'sap/ui/rta/RuntimeAuthoring';
import IconPool from 'sap/ui/core/IconPool';
import ResourceBundle from 'sap/base/i18n/ResourceBundle';
import AppState from 'sap/ushell/services/AppState';
import { getManifestAppdescr } from '../adp/api-handler';
import { getError } from '../utils/error';
import initConnectors from './initConnectors';
import { getUi5Version, isLowerThanMinimalUi5Version } from '../utils/version';
import { getUi5Version, isLowerThanMinimalUi5Version, Ui5VersionInfo } from '../utils/version';
import { CommunicationService } from '../cpe/communication-service';
import { getTextBundle } from '../i18n';

/**
* SAPUI5 delivered namespaces from https://ui5.sap.com/#/api/sap
Expand Down Expand Up @@ -304,7 +306,11 @@ export async function init({
libs,
// eslint-disable-next-line no-shadow
async function (startAdaptation: StartAdaptation | InitRtaScript, pluginScript: RTAPlugin) {
await startAdaptation(options, pluginScript);
try {
await startAdaptation(options, pluginScript);
} catch (error) {
await handleHigherLayerChanges(error, ui5VersionInfo);
}
}
);
});
Expand All @@ -318,7 +324,7 @@ export async function init({

// Load custom library paths if configured
if (appUrls) {
await registerComponentDependencyPaths(JSON.parse(appUrls) as string[] ?? [], urlParams);
await registerComponentDependencyPaths((JSON.parse(appUrls) as string[]) ?? [], urlParams);
}

// Load rta connector
Expand Down Expand Up @@ -351,3 +357,28 @@ if (bootstrapConfig) {
Log.error('Sandbox initialization failed: ' + error.message);
});
}

/**
* Handle higher layer changes when starting UI Adaptation.
* When RTA detects higher layer changes an error with Reload triggered text is thrown, the RTA instance is destroyed and the application is reloaded.
* For UI5 version lower than 1.84.0 RTA is showing a popup with notification text about the detection of higher layer changes.
*
* @param error the error thrown when there are higher layer changes when starting UI Adaptation.
* @param ui5VersionInfo ui5 version info
*/
export async function handleHigherLayerChanges(error: unknown, ui5VersionInfo: Ui5VersionInfo): Promise<void> {
const err = getError(error);
if (err.message.includes('Reload triggered')) {
if (!isLowerThanMinimalUi5Version(ui5VersionInfo, { major: 1, minor: 84 })) {
const bundle = await getTextBundle();
const action = showMessage({
message: bundle.getText('HIGHER_LAYER_CHANGES_INFO_MESSAGE'),
shouldHideIframe: false
});
CommunicationService.sendAction(action);
}

// eslint-disable-next-line fiori-custom/sap-no-location-reload
window.location.reload();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ ADP_REUSE_COMPONENTS_MESSAGE = Reuse components are detected for some views in t
CPE_CHANGES_VISIBLE_AFTER_SAVE_AND_RELOAD_MESSAGE = Note: The change will be visible after save and reload.

TABLE_ROWS_NEEDED_TO_CREATE_CUSTOM_COLUMN=At least one table row is required to create new custom column. Make sure the table data is loaded and try again.

HIGHER_LAYER_CHANGES_INFO_MESSAGE=The preview of the project was reloaded due to detected changes in higher layer than the one used in your project.
79 changes: 79 additions & 0 deletions packages/preview-middleware-client/test/unit/flp/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ import { fetchMock, sapMock } from 'mock/window';
import type { InitRtaScript, RTAPlugin, StartAdaptation } from 'sap/ui/rta/api/startAdaptation';
import type { Scenario } from '@sap-ux-private/control-property-editor-common';
import VersionInfo from 'mock/sap/ui/VersionInfo';
import { CommunicationService } from '../../../src/cpe/communication-service';

jest.mock('../../../src/i18n', () => {
return {
...jest.requireActual('../../../src/i18n'),
getTextBundle: async () => {
return {
hasText: jest.fn().mockReturnValueOnce(true),
getText: jest
.fn()
.mockReturnValueOnce('The application was reloaded because of changes in a higher layer.')
};
}
};
});

Object.defineProperty(window, 'location', {
value: {
...window.location,
reload: jest.fn()
},
writable: true
});

describe('flp/init', () => {
test('registerSAPFonts', () => {
Expand Down Expand Up @@ -190,10 +213,24 @@ describe('flp/init', () => {
});

describe('init', () => {
const reloadSpy = jest.fn();
const location = window.location;
beforeEach(() => {
sapMock.ushell.Container.attachRendererCreatedEvent.mockReset();
sapMock.ui.require.mockReset();
jest.clearAllMocks();

Object.defineProperty(window, 'location', {
value: {
reload: reloadSpy
}
});
});

afterEach(() => {
Object.defineProperty(window, 'location', {
value: location
});
});

test('nothing configured', async () => {
Expand Down Expand Up @@ -298,5 +335,47 @@ describe('flp/init', () => {

expect(sapMock.ui.require).toBeCalledWith([customInit]);
});

test('handle higher layer changes', async () => {
const flexSettings = {
layer: 'VENDOR',
pluginScript: 'my/script'
};

VersionInfo.load.mockResolvedValueOnce({ name: 'sap.ui.core', version: '1.84.50' });

// Mocking `sap.ui.require` to throw the correct error structure
sapMock.ui.require.mockImplementationOnce((libs, callback) => {
callback(async () => {
throw 'Reload triggered';
}, {});
});

const sendActionSpy = jest.spyOn(CommunicationService, 'sendAction');
await init({ flex: JSON.stringify(flexSettings) });
const rendererCb = sapMock.ushell.Container.attachRendererCreatedEvent.mock
.calls[0][0] as () => Promise<void>;
const mockService = {
attachAppLoaded: jest.fn().mockImplementation((callback) => {
callback({ getParameter: jest.fn() });
})
};
sapMock.ushell.Container.getServiceAsync.mockResolvedValueOnce(mockService);

await rendererCb();

const loadedCb = mockService.attachAppLoaded.mock.calls[0][0] as (event: unknown) => Promise<void>;
await loadedCb({ getParameter: () => {} });

expect(sendActionSpy).toHaveBeenCalled();
expect(sendActionSpy).toHaveBeenNthCalledWith(1, {
type: '[ext] show-dialog-message',
payload: {
message: 'The application was reloaded because of changes in a higher layer.',
shouldHideIframe: false
}
});
expect(reloadSpy).toHaveBeenCalled();
});
});
});
6 changes: 6 additions & 0 deletions packages/preview-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sap-ux/preview-middleware

## 0.16.118

### Patch Changes

- 1f7827c: handle higher layer changes

## 0.16.117

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/preview-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bugs": {
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
},
"version": "0.16.117",
"version": "0.16.118",
"license": "Apache-2.0",
"author": "@SAP/ux-tools-team",
"main": "dist/index.js",
Expand Down

0 comments on commit 34b52ab

Please sign in to comment.