Skip to content

Commit 9187046

Browse files
authored
Merge pull request #94 from Exabyte-io/chore/SOF-7644
SOF-7644: move context providers from ade/code
2 parents de0d88c + d4bebdb commit 9187046

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3466
-2339
lines changed

.eslintrc.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
{
2-
"extends": ["@exabyte-io/eslint-config"]
2+
"extends": [
3+
"@exabyte-io/eslint-config"
4+
],
5+
"ignorePatterns": [
6+
"dist/",
7+
"src/workflows/workflows.js"
8+
],
9+
"settings": {
10+
"import/resolver": {
11+
"node": {
12+
"extensions": [
13+
".js",
14+
".jsx",
15+
".ts",
16+
".tsx"
17+
]
18+
}
19+
}
20+
}
321
}
4-

package-lock.json

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

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"@babel/preset-react": "7.16.7",
4040
"@babel/register": "^7.16.0",
4141
"@babel/runtime-corejs3": "7.16.8",
42+
"@exabyte-io/periodic-table.js": "2022.6.8-0",
43+
"crypto-js": "^4.2.0",
4244
"js-yaml": "^4.1.0",
4345
"lodash": "^4.17.21",
4446
"mixwith": "^0.1.1",
@@ -47,14 +49,14 @@
4749
"v20": "^0.1.0"
4850
},
4951
"devDependencies": {
50-
"@exabyte-io/ade.js": "2025.5.5-0",
52+
"@exabyte-io/ade.js": "2025.7.15-1",
5153
"@exabyte-io/application-flavors.js": "2025.7.8-0",
52-
"@exabyte-io/eslint-config": "^2022.11.17-0",
54+
"@exabyte-io/eslint-config": "2025.5.13-0",
5355
"@exabyte-io/ide.js": "2024.3.26-0",
5456
"@exabyte-io/mode.js": "2024.4.28-0",
55-
"@mat3ra/code": "2025.4.27-0",
56-
"@mat3ra/esse": "2025.4.26-0",
57-
"@mat3ra/made": "2025.4.30-0",
57+
"@mat3ra/code": "2025.7.15-0",
58+
"@mat3ra/esse": "2025.7.15-0",
59+
"@mat3ra/made": "2025.7.15-0",
5860
"chai": "^4.3.4",
5961
"eslint": "7.32.0",
6062
"eslint-config-airbnb": "19.0.2",

src/context/context.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { BoundaryConditionsFormDataProvider } from "./providers/BoundaryConditionsFormDataProvider";
2+
import QENEBContextProvider from "./providers/by_application/espresso/QENEBContextProvider";
3+
import QEPWXContextProvider from "./providers/by_application/espresso/QEPWXContextProvider";
4+
import NWChemTotalEnergyContextProvider from "./providers/by_application/nwchem/NWChemTotalEnergyContextProvider";
5+
import VASPContextProvider from "./providers/by_application/vasp/VASPContextProvider";
6+
import VASPNEBContextProvider from "./providers/by_application/vasp/VASPNEBContextProvider";
27
import { CollinearMagnetizationContextProvider } from "./providers/CollinearMagnetizationContextProvider";
38
import { HubbardContextProviderLegacy } from "./providers/HubbardContextProviderLegacy";
49
import { HubbardJContextProvider } from "./providers/HubbardJContextProvider";
@@ -34,4 +39,9 @@ export default {
3439
IonDynamicsContextProvider,
3540
CollinearMagnetizationContextProvider,
3641
NonCollinearMagnetizationContextProvider,
42+
VASPContextProvider,
43+
VASPNEBContextProvider,
44+
QEPWXContextProvider,
45+
QENEBContextProvider,
46+
NWChemTotalEnergyContextProvider,
3747
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { globalSettings } from "../providers/settings";
2+
3+
export function applicationContextMixin(item) {
4+
const properties = {
5+
_application: undefined,
6+
7+
initApplicationContextMixin() {
8+
this._application =
9+
(this.config.context && this.config.context.application) ||
10+
globalSettings.Application.createDefault();
11+
},
12+
13+
get application() {
14+
return this._application;
15+
},
16+
};
17+
18+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
19+
}

src/context/mixins/JobContextMixin.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const defaultJob = {
2+
workflow: {
3+
subworkflows: [],
4+
units: [],
5+
},
6+
status: "pre-submission",
7+
compute: {
8+
queue: "D",
9+
nodes: 1,
10+
ppn: 1,
11+
timeLimit: "3600",
12+
},
13+
_project: {
14+
_id: "",
15+
},
16+
};
17+
18+
export function jobContextMixin(item) {
19+
const properties = {
20+
isEdited: false,
21+
22+
_job: defaultJob,
23+
24+
get job() {
25+
return this._job;
26+
},
27+
28+
initJobContextMixin() {
29+
const { config } = this;
30+
this._job = (config.context && config.context.job) || defaultJob;
31+
this.isEdited = false; // we always get the `defaultData` (recalculated from scratch, not persistent)
32+
},
33+
};
34+
35+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { globalSettings } from "../providers/settings";
2+
3+
export function materialContextMixin(item) {
4+
const properties = {
5+
_material: undefined,
6+
7+
updateMaterialHash() {
8+
if (this.isEditedIsSetToFalseOnMaterialUpdate) this.isEdited = false;
9+
this.extraData = { materialHash: this.material.hash };
10+
},
11+
12+
// Workaround: Material.createDefault() used to initiate workflow reducer and hence here too
13+
// does not have an id. Here we catch when such material is used and avoid resetting isEdited
14+
get isMaterialCreatedDefault() {
15+
return !this.material.id;
16+
},
17+
18+
get isMaterialUpdated() {
19+
return Boolean(this.extraData && this.extraData.materialHash !== this.material.hash);
20+
},
21+
22+
get material() {
23+
if (!this._material) {
24+
throw new Error("Material is not set");
25+
}
26+
return this._material;
27+
},
28+
29+
initMaterialContextMixin() {
30+
this._material = this.config.context && this.config.context.material;
31+
32+
if (!this._material) {
33+
this._material = globalSettings.Material.createDefault();
34+
}
35+
36+
this.updateMaterialHash();
37+
},
38+
};
39+
40+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { globalSettings } from "../providers/settings";
2+
3+
export function materialsContextMixin(item) {
4+
const properties = {
5+
get materials() {
6+
return this._materials;
7+
},
8+
initMaterialsContextMixin() {
9+
const materials = this.config.context?.materials;
10+
this._materials =
11+
materials && materials.length
12+
? materials
13+
: [globalSettings.Material.createDefault()];
14+
},
15+
};
16+
17+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { compareEntitiesInOrderedSetForSorting } from "@mat3ra/code/dist/js/entity/set/ordered/utils";
2+
3+
export function materialsSetContextMixin(item) {
4+
const properties = {
5+
_materialsSet: undefined,
6+
7+
get materialsSet() {
8+
return this._materialsSet;
9+
},
10+
11+
initMaterialsSetContextMixin() {
12+
this._materialsSet = this.config.context?.materialsSet;
13+
},
14+
15+
sortMaterialsByIndexInSet(materials = []) {
16+
// DO NOT SORT IN PLACE AS IT CHANGES THE ORDER IN `this.materials` AND HAS SIDE EFFECTS (MaterialViewer).
17+
return materials.concat().sort((a, b) => {
18+
return compareEntitiesInOrderedSetForSorting(a, b, this.materialsSet._id, false);
19+
});
20+
},
21+
};
22+
23+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
24+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import CryptoJS from "crypto-js";
2+
3+
export function methodDataContextMixin(item) {
4+
const properties = {
5+
_methodData: undefined,
6+
7+
isEdited: false,
8+
9+
methodDataHash: undefined,
10+
11+
extraData: undefined,
12+
13+
initMethodDataContextMixin() {
14+
this._methodData = (this.config.context && this.config.context.methodData) || {};
15+
this.isEdited = Boolean(this.config.isEdited);
16+
},
17+
18+
/* @summary Replace the logic in constructor with this in order to enable passing `methodDataHash` between
19+
* subsequent initializations of the derived class. Not used at present and kept for the record.
20+
*/
21+
_initMethodDataHash() {
22+
this.methodDataHash = CryptoJS.MD5(JSON.stringify(this.methodData)).toString();
23+
this.extraData = { methodDataHash: this.methodDataHash };
24+
if (!this._methodData) {
25+
this._methodData = {};
26+
this.isEdited = false;
27+
// Commented out to reduce effect on performance. Uncomment for debugging purposes.
28+
// TODO: remove on next refactoring or convert to log
29+
// console.warn("MethodDataContextMixin: methodData is undefined or null");
30+
} else if (this.isMethodDataUpdated) {
31+
this.isEdited = false;
32+
} else {
33+
// eslint-disable-next-line no-undef
34+
this.isEdited = config.isEdited;
35+
}
36+
},
37+
38+
get methodData() {
39+
return this._methodData;
40+
},
41+
42+
get isMethodDataUpdated() {
43+
return Boolean(this.extraData && this.extraData.methodDataHash !== this.methodDataHash);
44+
},
45+
};
46+
47+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
48+
}

0 commit comments

Comments
 (0)