Skip to content

Commit

Permalink
feat(ui): scenario execution report - Flatten one iteration for strat…
Browse files Browse the repository at this point in the history
…egy steps (#42)
  • Loading branch information
boddissattva authored Dec 20, 2024
1 parent 89d6bf2 commit 40e2f72
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ export class ScenarioExecutionReport {
public contextVariables?: Map<string, Object>,
public dataset?: ExecutionDataset
) { }

static cleanReport(scenarioReport: ScenarioExecutionReport): ScenarioExecutionReport {
scenarioReport.report = StepExecutionReport.cleanReport(scenarioReport.report);
return scenarioReport;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2017-2024 Enedis
*
* SPDX-License-Identifier: Apache-2.0
*
*/

import { StepExecutionReport } from "./step-execution-report.model";

describe('StepExecutionReportTest', () => {
it('should flatten one iteration for strategy', () => {
var report = {
name: 'root step to be flatten',
steps: [
{
name: 'Step with one iteration - <i> - ${#dk}',
steps: [
{
name: 'Step with one iteration - 0 - one'
}
],
strategy: 'for'
},
{
name: 'Step with one iteration - <i> - ${#dk}',
steps: [
{
name: 'Step with one iteration - 0 - one',
steps: [
{
name: 'Child with one iteration - 0 - <j> - ${#dkk}',
steps: [
{
name: 'Child with one iteration - 0 - 0 - one'
}
],
strategy: 'for'
}
]
}
],
strategy: 'for'
}
]
} as StepExecutionReport;
let initialReport = Object.assign({}, report)
let cleanedReport = StepExecutionReport.cleanReport(report);
expect(cleanedReport).toBe(report);
expect(cleanedReport.name).toBe(initialReport.name);
expect(cleanedReport.steps).toHaveSize(2);
expect(cleanedReport.steps[0]).toBe(initialReport.steps[0].steps[0]);
expect(cleanedReport.steps[1].name).toBe(initialReport.steps[1].steps[0].name);
expect(cleanedReport.steps[1].steps[0]).toBe(initialReport.steps[1].steps[0].steps[0]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ export class StepExecutionReport {
public stepOutputs: Map<string, Object>,
public name?: string,
) {}

static cleanReport(stepReport: StepExecutionReport): StepExecutionReport {
if (stepReport?.steps) {
if (stepReport?.strategy === 'for' && stepReport.steps.length == 1) {
return StepExecutionReport.cleanReport(stepReport.steps[0]);
}
stepReport.steps = stepReport.steps.map(substep => StepExecutionReport.cleanReport(substep));
}
return stepReport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ export class ScenarioExecutionComponent implements OnInit, OnDestroy, AfterViewI
private renderer: Renderer2,
private offcanvasService: NgbOffcanvas,
private elementRef: ElementRef,
private datasetUtils: DatasetUtils,
private translateService: TranslateService) {
private datasetUtils: DatasetUtils) {
}

ngOnInit() {
if (this.scenario) {
this.loadScenarioExecution(this.execution.executionId);
} else {
this.scenarioExecutionReport = JSON.parse(this.execution.report);
this.scenarioExecutionReport = ScenarioExecutionReport.cleanReport(JSON.parse(this.execution.report));
this.afterReportUpdate();
}
}
Expand Down Expand Up @@ -170,7 +169,7 @@ export class ScenarioExecutionComponent implements OnInit, OnDestroy, AfterViewI
if (scenarioExecutionReport?.report?.status === ExecutionStatus.RUNNING) {
this.observeScenarioExecution(executionId);
} else {
this.scenarioExecutionReport = scenarioExecutionReport;
this.scenarioExecutionReport = ScenarioExecutionReport.cleanReport(scenarioExecutionReport);
if(scenarioExecutionReport?.report) {
this.afterReportUpdate();
}
Expand Down Expand Up @@ -283,7 +282,8 @@ export class ScenarioExecutionComponent implements OnInit, OnDestroy, AfterViewI
)
)
.subscribe({
next: (scenarioExecutionReport: ScenarioExecutionReport) => {
next: (ser: ScenarioExecutionReport) => {
var scenarioExecutionReport = ScenarioExecutionReport.cleanReport(ser);
executionStatus = ExecutionStatus[scenarioExecutionReport.report.status];
executionError = this.getExecutionError(scenarioExecutionReport);
if (this.scenarioExecutionReport) {
Expand Down

0 comments on commit 40e2f72

Please sign in to comment.