Skip to content

Commit

Permalink
Merge pull request #34 from Exabyte-io/fix/SOF-6563
Browse files Browse the repository at this point in the history
Fix/sof 6563
  • Loading branch information
timurbazhirov authored May 16, 2023
2 parents 06413da + 5e20de2 commit 0f25c34
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 12 deletions.
121 changes: 114 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"underscore.string": "^3.3.4"
},
"devDependencies": {
"@exabyte-io/ade.js": "2022.11.16-0",
"@exabyte-io/ade.js": "2023.4.26-0",
"@exabyte-io/code.js": "2022.11.11-0",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/ide.js": "2022.7.28-1",
Expand Down
17 changes: 15 additions & 2 deletions src/subworkflows/subworkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,25 @@ export class Subworkflow extends BaseSubworkflow {
setApplication(application) {
// TODO: adjust the logic above to take into account whether units need re-rendering after version change etc.
// reset units if application name changes
if (this.application.name !== application.name) this.setUnits([]);
const previousApplicationName = this.application.name;
this._application = application;

if (previousApplicationName !== application.name) {
// TODO: figure out how to set a default unit per new application instead of removing all
this.setUnits([]);
} else {
// propagate new application version to all units
this.units
.filter((unit) => typeof unit.setApplication === "function")
.forEach((unit) => unit.setApplication(application, true));
}

this.setProp("application", application.toJSON());
// set model to the default one for the application selected
this.setModel(
this._ModelFactory.createFromApplication({ application: this.prop("application") }),
this._ModelFactory.createFromApplication({
application: this.prop("application"),
}),
);
}

Expand Down
10 changes: 8 additions & 2 deletions src/units/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ export class ExecutionUnit extends mix(BaseUnit).with(HashedInputArrayMixin) {
return this.input.map((i) => new this.constructor.Template(i));
}

setApplication(application) {
setApplication(application, omitSettingExecutable = false) {
this._application = application;
this.setProp("application", application.toJSON());
this.setExecutable(this.application.defaultExecutable);
if (!omitSettingExecutable) {
this.setExecutable(this.application.defaultExecutable);
}
}

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

setInput(input) {
this.setProp("input", input);
}

get defaultResults() {
return this.flavor.results;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/subworkflow.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Application } from "@exabyte-io/ade.js";
import { expect } from "chai";

import { createSubworkflowByName } from "../src/subworkflows";
Expand Down Expand Up @@ -85,4 +86,32 @@ describe("subworkflows", () => {
expect(subworkflow.units[1]._json.type).to.be.equal("condition");
expect(subworkflow.units[2]._json.type).to.be.equal("assignment");
});
it("can update application", () => {
const subworkflow = createSubworkflowByName({
appName: "espresso",
swfName: "total_energy",
});

const assignementUnit = new AssignmentUnit(assignmentUnitData);
subworkflow.addUnit(assignementUnit, -1);

expect(subworkflow.units.length).to.be.equal(2);
expect(subworkflow.units[0]._json.type).to.be.equal("execution");
expect(subworkflow.units[1]._json.type).to.be.equal("assignment");
expect(subworkflow.units[0].application.version).to.be.equal("5.4.0");
expect(subworkflow.units[1].application?.version).to.be.equal(undefined);

const newApplication = Application.createFromNameVersionBuild({
name: "espresso",
version: "6.7.0",
});

expect(newApplication.version).to.be.equal("6.7.0");

subworkflow.setApplication(newApplication);

expect(subworkflow.application.version).to.be.equal("6.7.0");
expect(subworkflow.units[0].application?.version).to.be.equal("6.7.0");
expect(subworkflow.units[1].application?.version).to.be.equal(undefined);
});
});

0 comments on commit 0f25c34

Please sign in to comment.