From 55b6b23bb74cd1007235996b51364c4ba9be10dd Mon Sep 17 00:00:00 2001 From: Milkov Date: Thu, 12 Sep 2024 16:41:04 +0300 Subject: [PATCH] fix: sonar issue --- .../src/cpe/changes/service.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/preview-middleware-client/src/cpe/changes/service.ts b/packages/preview-middleware-client/src/cpe/changes/service.ts index 9e4ce02252..29ea2f7013 100644 --- a/packages/preview-middleware-client/src/cpe/changes/service.ts +++ b/packages/preview-middleware-client/src/cpe/changes/service.ts @@ -95,7 +95,7 @@ function modifyRTAErrorMessage(errorMessage: string, id: string, type: string): export class ChangeService { private savedChanges: SavedPropertyChange[] = []; private sendAction: (action: ExternalAction) => void; - private pendingChanges: PendingChange[]; + private pendingChanges: PendingChange[] = []; /** * * @param options ui5 adaptation options. @@ -278,39 +278,38 @@ export class ChangeService { const allCommands = stack.getCommands(); const executedCommands = stack.getAllExecutedCommands(); const inactiveCommandCount = allCommands.length - executedCommands.length; - let activeChanges: PendingChange[] = []; let i: number, command: FlexCommand; for ([i, command] of allCommands.entries()) { try { if (typeof command.getCommands === 'function') { const subCommands = command.getCommands(); for (const subCommand of subCommands) { - const pendingChange = await this.prepareChangeType(subCommand, inactiveCommandCount, i); - if (pendingChange) { - activeChanges.push(pendingChange); - } + await this.handleCommand(subCommand, inactiveCommandCount, i); } } else { - const pendingChange = await this.prepareChangeType(command, inactiveCommandCount, i); - if (pendingChange) { - activeChanges.push(pendingChange); - } + await this.handleCommand(command, inactiveCommandCount, i); } } catch (error) { Log.error('CPE: Change creation Failed', getError(error)); } } - activeChanges = activeChanges.filter((change): boolean => !!change); if (Array.isArray(allCommands) && allCommands.length === 0) { + this.pendingChanges = []; await this.fetchSavedChanges(); } - this.pendingChanges = activeChanges; this.updateStack(); handleStackChange(); }; } + private async handleCommand(command: FlexCommand, inactiveCommandCount: number, index: number): Promise { + const pendingChange = await this.prepareChangeType(command, inactiveCommandCount, index); + if (pendingChange) { + this.pendingChanges.push(pendingChange); + } + } + private async prepareChangeType( command: FlexCommand, inactiveCommandCount: number,