Skip to content

Commit 0f25c34

Browse files
Merge pull request #34 from Exabyte-io/fix/SOF-6563
Fix/sof 6563
2 parents 06413da + 5e20de2 commit 0f25c34

File tree

5 files changed

+167
-12
lines changed

5 files changed

+167
-12
lines changed

package-lock.json

Lines changed: 114 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"underscore.string": "^3.3.4"
4747
},
4848
"devDependencies": {
49-
"@exabyte-io/ade.js": "2022.11.16-0",
49+
"@exabyte-io/ade.js": "2023.4.26-0",
5050
"@exabyte-io/code.js": "2022.11.11-0",
5151
"@exabyte-io/eslint-config": "^2022.11.17-0",
5252
"@exabyte-io/ide.js": "2022.7.28-1",

src/subworkflows/subworkflow.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,25 @@ export class Subworkflow extends BaseSubworkflow {
106106
setApplication(application) {
107107
// TODO: adjust the logic above to take into account whether units need re-rendering after version change etc.
108108
// reset units if application name changes
109-
if (this.application.name !== application.name) this.setUnits([]);
109+
const previousApplicationName = this.application.name;
110110
this._application = application;
111+
112+
if (previousApplicationName !== application.name) {
113+
// TODO: figure out how to set a default unit per new application instead of removing all
114+
this.setUnits([]);
115+
} else {
116+
// propagate new application version to all units
117+
this.units
118+
.filter((unit) => typeof unit.setApplication === "function")
119+
.forEach((unit) => unit.setApplication(application, true));
120+
}
121+
111122
this.setProp("application", application.toJSON());
112123
// set model to the default one for the application selected
113124
this.setModel(
114-
this._ModelFactory.createFromApplication({ application: this.prop("application") }),
125+
this._ModelFactory.createFromApplication({
126+
application: this.prop("application"),
127+
}),
115128
);
116129
}
117130

src/units/execution.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ export class ExecutionUnit extends mix(BaseUnit).with(HashedInputArrayMixin) {
5858
return this.input.map((i) => new this.constructor.Template(i));
5959
}
6060

61-
setApplication(application) {
61+
setApplication(application, omitSettingExecutable = false) {
6262
this._application = application;
6363
this.setProp("application", application.toJSON());
64-
this.setExecutable(this.application.defaultExecutable);
64+
if (!omitSettingExecutable) {
65+
this.setExecutable(this.application.defaultExecutable);
66+
}
6567
}
6668

6769
setExecutable(executable) {
@@ -82,6 +84,10 @@ export class ExecutionUnit extends mix(BaseUnit).with(HashedInputArrayMixin) {
8284
this.render(this.context, true);
8385
}
8486

87+
setInput(input) {
88+
this.setProp("input", input);
89+
}
90+
8591
get defaultResults() {
8692
return this.flavor.results;
8793
}

tests/subworkflow.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Application } from "@exabyte-io/ade.js";
12
import { expect } from "chai";
23

34
import { createSubworkflowByName } from "../src/subworkflows";
@@ -85,4 +86,32 @@ describe("subworkflows", () => {
8586
expect(subworkflow.units[1]._json.type).to.be.equal("condition");
8687
expect(subworkflow.units[2]._json.type).to.be.equal("assignment");
8788
});
89+
it("can update application", () => {
90+
const subworkflow = createSubworkflowByName({
91+
appName: "espresso",
92+
swfName: "total_energy",
93+
});
94+
95+
const assignementUnit = new AssignmentUnit(assignmentUnitData);
96+
subworkflow.addUnit(assignementUnit, -1);
97+
98+
expect(subworkflow.units.length).to.be.equal(2);
99+
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
100+
expect(subworkflow.units[1]._json.type).to.be.equal("assignment");
101+
expect(subworkflow.units[0].application.version).to.be.equal("5.4.0");
102+
expect(subworkflow.units[1].application?.version).to.be.equal(undefined);
103+
104+
const newApplication = Application.createFromNameVersionBuild({
105+
name: "espresso",
106+
version: "6.7.0",
107+
});
108+
109+
expect(newApplication.version).to.be.equal("6.7.0");
110+
111+
subworkflow.setApplication(newApplication);
112+
113+
expect(subworkflow.application.version).to.be.equal("6.7.0");
114+
expect(subworkflow.units[0].application?.version).to.be.equal("6.7.0");
115+
expect(subworkflow.units[1].application?.version).to.be.equal(undefined);
116+
});
88117
});

0 commit comments

Comments
 (0)