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: Modified indicators incorrectly displayed for some UI5 controls in Adaptation Project #2264

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0e58c1a
fix: incorrectly placed modified indicators
mmilko01 Aug 21, 2024
21d92fd
refacor: enhance types
mmilko01 Aug 27, 2024
0c74987
fix: type
mmilko01 Aug 27, 2024
3f485ce
refactor: get control instance based on App Component
mmilko01 Aug 28, 2024
8e35073
fix: check if change is available
mmilko01 Aug 28, 2024
5c8efed
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Aug 28, 2024
d67e8eb
refactor: dynamically import ChangeHandlerAPI
mmilko01 Aug 29, 2024
0035131
refactor: get control id via JsControlTreeModifier
mmilko01 Aug 29, 2024
5eefabb
refactor: use different FL API based on UI5 Version
mmilko01 Aug 30, 2024
92f9fb5
test: amend tests
mmilko01 Sep 11, 2024
c4aafd3
chore: merge with main
mmilko01 Sep 11, 2024
e9018da
chore: fix main merge conflicts
mmilko01 Sep 11, 2024
11bd958
chore: create changeset
mmilko01 Sep 11, 2024
2b73513
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Sep 11, 2024
130ba00
chore: fix lint error
mmilko01 Sep 11, 2024
dbc093f
Merge branch 'fix/2263/incorrect-modified-indicators' of https://gith…
mmilko01 Sep 11, 2024
0e6a23a
test: add tests
mmilko01 Sep 12, 2024
55b6b23
fix: sonar issue
mmilko01 Sep 12, 2024
b4f4ee6
test: improve coverage
mmilko01 Sep 12, 2024
4c99027
fix: lint issue
mmilko01 Sep 12, 2024
5dfca73
doc: fix JSDoc
mmilko01 Sep 12, 2024
1931d00
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Sep 13, 2024
9931f05
refactor: do not leak change files to UI
mmilko01 Sep 13, 2024
67f0abf
Merge branch 'fix/2263/incorrect-modified-indicators' of https://gith…
mmilko01 Sep 13, 2024
748bd9d
refactor: change Selector type
mmilko01 Sep 13, 2024
75d7ba3
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Sep 13, 2024
574c393
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Sep 16, 2024
809dc7f
refactor: change changeFiles type
mmilko01 Sep 16, 2024
21ab914
refactor: define changedFiles as object
mmilko01 Sep 16, 2024
64b1527
fix: resolve conflicts
mmilko01 Oct 15, 2024
5a86c0d
fix: correctly display control changes
mmilko01 Oct 17, 2024
729bc12
feat: add control change component
nikmace Oct 17, 2024
fa6bd6e
Merge branch 'main' into fix/2263/incorrect-modified-indicators
mmilko01 Oct 17, 2024
9c4030d
chore: return cap.ts to original state
mmilko01 Oct 17, 2024
65d7d2f
refactor: rename interface
nikmace Oct 18, 2024
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
2 changes: 0 additions & 2 deletions packages/control-property-editor-common/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export interface SavedPropertyChange<T extends PropertyValue = PropertyValue> ex
kind: 'valid';
fileName: string;
timestamp: number;
file: object;
}

export interface UnknownSavedChange {
Expand All @@ -148,7 +147,6 @@ export interface UnknownSavedChange {
fileName: string;
controlId?: string;
timestamp?: number;
file: object;
}
export type ValidChange = PendingPropertyChange | SavedPropertyChange;
export type Change = ValidChange | UnknownSavedChange;
Expand Down
28 changes: 18 additions & 10 deletions packages/preview-middleware-client/src/cpe/changes/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface Change {

type SavedChangesResponse = Record<string, Change>;

type ChangeFiles = {
fileName: string;
};

type Properties<T extends object> = { [K in keyof T]-?: K extends string ? K : never }[keyof T];
/**
* Assert change for its validity. Throws error if no value found in saved changes.
Expand Down Expand Up @@ -96,6 +100,7 @@ export class ChangeService {
private savedChanges: SavedPropertyChange[] = [];
private sendAction: (action: ExternalAction) => void;
private pendingChanges: PendingChange[] = [];
private changedFiles: ChangeFiles[] = [];
voicis marked this conversation as resolved.
Show resolved Hide resolved
/**
*
* @param options ui5 adaptation options.
Expand Down Expand Up @@ -171,6 +176,7 @@ export class ChangeService {
* Fetches saved changes from the workspace and sorts them.
*/
private async fetchSavedChanges(): Promise<void> {
this.changedFiles = [];
const savedChangesResponse = await fetch(FlexChangesEndPoints.changes + `?_=${Date.now()}`);
const savedChanges = (await savedChangesResponse.json()) as SavedChangesResponse;
const changes = (
Expand All @@ -197,6 +203,7 @@ export class ChangeService {
) {
throw new Error('Unknown Change Type');
}
this.changedFiles.push(change);
return {
type: 'saved',
kind: 'valid',
Expand All @@ -208,18 +215,17 @@ export class ChangeService {
controlName: change.selector.type
? (change.selector.type.split('.').pop() as string)
: '',
changeType: change.changeType,
file: change
changeType: change.changeType
};
} catch (error) {
// Gracefully handle change files with invalid content
if (change.fileName) {
this.changedFiles.push(change);
const unknownChange: UnknownSavedChange = {
type: 'saved',
kind: 'unknown',
fileName: change.fileName,
controlId: selectorId, // some changes may not have selector
file: change
controlId: selectorId // some changes may not have selector
};
if (change.creation) {
unknownChange.timestamp = new Date(change.creation).getTime();
Expand Down Expand Up @@ -271,7 +277,7 @@ export class ChangeService {
* @param sendAction send action method
* @returns (event: sap.ui.base.Event) => Promise<void>
*/
private createOnStackChangeHandler():(event: Event) => Promise<void> {
private createOnStackChangeHandler(): (event: Event) => Promise<void> {
const handleStackChange = modeAndStackChangeHandler(this.sendAction, this.options.rta);
return async (): Promise<void> => {
const stack = this.options.rta.getCommandStack();
Expand Down Expand Up @@ -303,7 +309,7 @@ export class ChangeService {
};
}

private async handleCommand(command: FlexCommand, inactiveCommandCount: number, index: number): Promise<void> {
private async handleCommand(command: FlexCommand, inactiveCommandCount: number, index: number): Promise<void> {
const pendingChange = await this.prepareChangeType(command, inactiveCommandCount, index);
if (pendingChange) {
this.pendingChanges.push(pendingChange);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an issue with pending changes duplicating on each event. It is probably because pendingChanges field is not reset and we always process all the changes in the stack.

Expand Down Expand Up @@ -404,7 +410,6 @@ export class ChangeService {
* Get element id by change.
*
* @param change to be executed for creating change
* @param changeSelector selector of the change
* @returns element id or empty string
*/
private async getControlIdByChange(change: FlexChange): Promise<string> {
Expand Down Expand Up @@ -452,9 +457,12 @@ export class ChangeService {
* @returns void
*/
public async syncOutlineChanges(): Promise<void> {
for (const change of this.savedChanges) {
const flexObject = await this.getFlexObject(change.file);
change.controlId = await this.getControlIdByChange(flexObject);
for (const file of this.changedFiles) {
const flexObject = await this.getFlexObject(file);
const savedChange = this.savedChanges.find((change) => change.fileName === file.fileName);
if (savedChange) {
savedChange.controlId = await this.getControlIdByChange(flexObject);
}
}
this.updateStack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { fetchMock } from 'mock/window';
import JsControlTreeModifier from 'sap/ui/core/util/reflection/JsControlTreeModifier';
import Control from 'sap/ui/core/Control';
import * as Utils from '../../../../src/utils/version';
import { get } from 'http';

describe('SelectionService', () => {
const applyChangeSpy = jest.spyOn(flexChange, 'applyChange').mockImplementation(() => {
Expand Down Expand Up @@ -118,17 +117,15 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: '{i18n>CREATE_OBJECT2}',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
type: 'saved',
kind: 'unknown',
controlId:
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
fileName: 'id_1640106755570_204_propertyChange',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
changeType: 'propertyChange',
Expand All @@ -140,8 +137,7 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: true,
timestamp: 1640106757301,
file: expect.any(Object) as Object
timestamp: 1640106757301
}
]
}
Expand Down Expand Up @@ -220,17 +216,15 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: '{i18n>CREATE_OBJECT2}',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
type: 'saved',
kind: 'unknown',
controlId:
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
fileName: 'id_1640106755570_204_propertyChange',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
changeType: 'propertyChange',
Expand All @@ -242,8 +236,7 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: true,
timestamp: 1640106757301,
file: expect.any(Object) as Object
timestamp: 1640106757301
}
]
}
Expand Down Expand Up @@ -280,17 +273,15 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: '{i18n>CREATE_OBJECT2}',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
type: 'saved',
kind: 'unknown',
controlId:
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
fileName: 'id_1640106755570_204_propertyChange',
timestamp: 1640106817301,
file: expect.any(Object) as Object
timestamp: 1640106817301
},
{
changeType: 'propertyChange',
Expand All @@ -302,8 +293,7 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: true,
timestamp: 1640106757301,
file: expect.any(Object) as Object
timestamp: 1640106757301
}
]
}
Expand Down Expand Up @@ -359,8 +349,7 @@ describe('SelectionService', () => {
kind: 'unknown',
fileName: 'unknown',
timestamp: 1640106877301,
controlId: 'SEPMRA_C_PD_Product--template::ListReport::TableToolbar',
file: expect.any(Object) as object
controlId: 'SEPMRA_C_PD_Product--template::ListReport::TableToolbar'
},
{
type: 'saved',
Expand All @@ -372,8 +361,7 @@ describe('SelectionService', () => {
'v2flex::sap.suite.ui.generic.template.ListReport.view.ListReport::SEPMRA_C_PD_Product--addEntry',
propertyName: 'enabled',
value: '{i18n>CREATE_OBJECT2}',
timestamp: 1640106817301,
file: expect.any(Object) as object
timestamp: 1640106817301
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions packages/preview-middleware-client/types/sap.ui.core.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
declare module 'sap/ui/core/util/reflection/JsControlTreeModifier' {
import ChangeSelector from 'sap/ui/fl/ChangeSelector';
import type Selector from 'sap/ui/fl/Selector';
import Control from 'sap/ui/core/Control';
import Component from 'sap.ui.core.UIComponent';
import type { Component } from 'sap/ui/core/UIComponent';
interface JsControlTreeModifier {
bySelector(selector: ChangeSelector, oAppComponent: Component): Control;
bySelector(selector: Selector, oAppComponent: Component): Control;
getControlIdBySelector(selector: ChangeSelector | sting, oAppComponent: Component): string;
}

Expand Down
19 changes: 10 additions & 9 deletions packages/preview-middleware-client/types/sap.ui.fl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ declare module 'sap/ui/fl' {
export type Layer = 'USER' | 'PUBLIC' | 'CUSTOMER' | 'CUSTOMER_BASE' | 'PARTNER' | 'VENDOR' | 'BASE';
}

declare module 'sap/ui/fl/Selector' {
export default interface Selector {
id: string;
idIsLocal: boolean;
}
}
declare module 'sap/ui/fl/Layer' {
const Layer = {
CUSTOMER_BASE: 'CUSTOMER_BASE',
Expand All @@ -13,15 +19,10 @@ declare module 'sap/ui/fl/Layer' {

declare module 'sap/ui/fl/Change' {
import type { Layer } from 'sap/ui/fl';

export interface ChangeSelector {
id: string;
idIsLocal: boolean;
}

import type Selector from 'sap/ui/fl/Selector';
export interface ChangeDefinition {
service: string;
selector: ChangeSelector
selector: Selector;
layer: Layer;
changeType: string;
packageName: string;
Expand All @@ -33,7 +34,7 @@ declare module 'sap/ui/fl/Change' {
class Change {
constructor(oFile: object): void;
getDefinition: () => ChangeDefinition;
getSelector: () => ChangeSelector;
getSelector: () => Selector;
getChangeType: () => string;
getLayer: () => Layer;
}
Expand Down Expand Up @@ -136,4 +137,4 @@ declare module 'sap/ui/fl/apply/_internal/flexObjects/FlexObjectFactory' {

const FlexObjectFactory: FlexObjectFactory;
export default FlexObjectFactory;
}
}
Loading