Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field config skeleton (frontend) #570

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 55 additions & 24 deletions frontend/package-lock.json

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

4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@tanstack/react-query-devtools": "^5.4.2",
"@webviz/subsurface-viewer": "^0.3.1",
"@webviz/well-completions-plot": "^0.0.1-alpha.1",
"ajv": "^8.12.0",
"animate.css": "^4.1.1",
"axios": "^1.6.5",
"culori": "^3.2.0",
Expand All @@ -37,6 +38,7 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@babel/plugin-syntax-import-attributes": "^7.23.3",
"@playwright/experimental-ct-react": "^1.39.0",
"@playwright/test": "^1.39.0",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
Expand Down Expand Up @@ -65,7 +67,7 @@
"prettier": "2.8.3",
"sass": "^1.62.0",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.3",
"typescript": "^5.3.3",
"vite": "^5.0.12",
"vite-plugin-checker": "^0.6.0",
"vitest": "^1.1.3"
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/assets/field-configs/DROGON.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"fieldIdentifier": "DROGON",
"range": [0, 25]
}
18 changes: 18 additions & 0 deletions frontend/src/framework/FieldConfigs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface FieldConfig {
fieldIdentifier: string;
range: [number, number];
}

export class FieldConfigSet {
private _configMap: Map<string, FieldConfig> = new Map();

constructor(configArray: FieldConfig[]) {
for (const config of configArray) {
this._configMap.set(config.fieldIdentifier, config);
}
}

getConfig(fieldIdentifier: string): FieldConfig | null {
return this._configMap.get(fieldIdentifier) || null;
}
}
23 changes: 21 additions & 2 deletions frontend/src/framework/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Template } from "./TemplateRegistry";
import { WorkbenchServices } from "./WorkbenchServices";
import { WorkbenchSession } from "./WorkbenchSession";
import { loadEnsembleSetMetadataFromBackend } from "./internal/EnsembleSetLoader";
import { loadFieldConfigs } from "./internal/FieldConfigSetLoader";
import { PrivateWorkbenchServices } from "./internal/PrivateWorkbenchServices";
import { PrivateWorkbenchSettings } from "./internal/PrivateWorkbenchSettings";
import { WorkbenchSessionPrivate } from "./internal/WorkbenchSessionPrivate";
Expand Down Expand Up @@ -204,7 +205,7 @@ export class Workbench {
queryClient: QueryClient,
specifiedEnsembleIdents: EnsembleIdent[]
): Promise<void> {
this.storeEnsembleSetInLocalStorage(specifiedEnsembleIdents);
this.storeSpecifiedEnsemblesInLocalStorage(specifiedEnsembleIdents);

const ensembleIdentsToLoad: EnsembleIdent[] = [];
for (const ensSpec of specifiedEnsembleIdents) {
Expand All @@ -217,14 +218,32 @@ export class Workbench {
console.debug("loadAndSetupEnsembleSetInSession - loading done");
console.debug("loadAndSetupEnsembleSetInSession - publishing");
this._workbenchSession.setEnsembleSetLoadingState(false);

return this._workbenchSession.setEnsembleSet(newEnsembleSet);
}

private storeEnsembleSetInLocalStorage(specifiedEnsembleIdents: EnsembleIdent[]): void {
async loadAndSetupFieldConfigSetInSession(fieldsToLoadConfigFor: string[]): Promise<void> {
this.storeFieldsToLoadConfigForInLocalStorage(fieldsToLoadConfigFor);

console.debug("loadAndSetupFieldConfigSetInSession - starting load");
this._workbenchSession.setFieldConfigSetLoadingState(true);
const newFieldConfigSet = await loadFieldConfigs(fieldsToLoadConfigFor);
console.debug("loadAndSetupFieldConfigSetInSession - loading done");
console.debug("loadAndSetupFieldConfigSetInSession - publishing");
this._workbenchSession.setFieldConfigSetLoadingState(false);

return this._workbenchSession.setFieldConfigSet(newFieldConfigSet);
}

private storeSpecifiedEnsemblesInLocalStorage(specifiedEnsembleIdents: EnsembleIdent[]): void {
const ensembleIdentsToStore = specifiedEnsembleIdents.map((el) => el.toString());
localStorage.setItem("ensembleIdents", JSON.stringify(ensembleIdentsToStore));
}

private storeFieldsToLoadConfigForInLocalStorage(fieldsToLoadConfigFor: string[]): void {
localStorage.setItem("fieldsToLoadConfigFor", JSON.stringify(fieldsToLoadConfigFor));
}

maybeLoadEnsembleSetFromLocalStorage(): EnsembleIdent[] | null {
const ensembleIdentsString = localStorage.getItem("ensembleIdents");
if (!ensembleIdentsString) return null;
Expand Down
57 changes: 57 additions & 0 deletions frontend/src/framework/WorkbenchSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@ import React from "react";

import { Ensemble } from "./Ensemble";
import { EnsembleSet } from "./EnsembleSet";
import { FieldConfigSet } from "./FieldConfigs";

export enum WorkbenchSessionEvent {
EnsembleSetChanged = "EnsembleSetChanged",
EnsembleSetLoadingStateChanged = "EnsembleSetLoadingStateChanged",
FieldConfigSetChanged = "FieldConfigSetChanged",
FieldConfigSetLoadingStateChanged = "FieldConfigSetLoadingStateChanged",
}

export type WorkbenchSessionPayloads = {
[WorkbenchSessionEvent.EnsembleSetLoadingStateChanged]: {
isLoading: boolean;
};
[WorkbenchSessionEvent.FieldConfigSetLoadingStateChanged]: {
isLoading: boolean;
};
};

export class WorkbenchSession {
private _subscribersMap: Map<keyof WorkbenchSessionEvent, Set<(payload: any) => void>> = new Map();
protected _ensembleSet: EnsembleSet = new EnsembleSet([]);
protected _fieldConfigSet: FieldConfigSet = new FieldConfigSet([]);

getEnsembleSet(): EnsembleSet {
return this._ensembleSet;
}

getFieldConfigSet(): FieldConfigSet {
return this._fieldConfigSet;
}

subscribe<T extends Exclude<WorkbenchSessionEvent, keyof WorkbenchSessionPayloads>>(
event: T,
cb: () => void
Expand Down Expand Up @@ -108,3 +119,49 @@ export function useIsEnsembleSetLoading(workbenchSession: WorkbenchSession): boo

return isLoading;
}

export function useFieldConfigSet(workbenchSession: WorkbenchSession): FieldConfigSet {
const [storedFieldConfigSet, setStoredFieldConfigSet] = React.useState<FieldConfigSet>(
workbenchSession.getFieldConfigSet()
);

React.useEffect(
function subscribeToFieldConfigSetChanges() {
function handleFieldConfigSetChanged() {
setStoredFieldConfigSet(workbenchSession.getFieldConfigSet());
}

const unsubFunc = workbenchSession.subscribe(
WorkbenchSessionEvent.FieldConfigSetChanged,
handleFieldConfigSetChanged
);
return unsubFunc;
},
[workbenchSession]
);

return storedFieldConfigSet;
}

export function useIsFieldConfigSetLoading(workbenchSession: WorkbenchSession): boolean {
const [isLoading, setIsLoading] = React.useState<boolean>(false);

React.useEffect(
function subscribeToFieldConfigSetLoadingStateChanges() {
function handleFieldConfigSetLoadingStateChanged(
payload: WorkbenchSessionPayloads[WorkbenchSessionEvent.FieldConfigSetLoadingStateChanged]
) {
setIsLoading(payload.isLoading);
}

const unsubFunc = workbenchSession.subscribe(
WorkbenchSessionEvent.FieldConfigSetLoadingStateChanged,
handleFieldConfigSetLoadingStateChanged
);
return unsubFunc;
},
[workbenchSession]
);

return isLoading;
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export class VectorSelection extends TreeNodeSelection {
}

containsWildcard(): boolean {
const reg = RegExp(`^(([^${super.delimiter}\\|]+\\|)+([^${super.delimiter}\\|]+){1})$`);
const reg = RegExp(`^(([^${this.delimiter}\\|]+\\|)+([^${this.delimiter}\\|]+){1})$`);
let level = 0;
for (const el of this.getNodePath()) {
if (
(el.includes("?") || el.includes("*") || (super.allowOrOperator && reg.test(el))) &&
level != super.getNumMetaNodes() - 1
(el.includes("?") || el.includes("*") || (this.allowOrOperator && reg.test(el))) &&
level !== super.getNumMetaNodes() - 1
) {
return true;
}
Expand All @@ -123,7 +123,7 @@ export class VectorSelection extends TreeNodeSelection {
getCompleteNodePathAsString(): string {
const result: string[] = [];
for (let i = 0; i < this.countLevel(); i++) {
if (i != super.getNumMetaNodes() - 1) {
if (i !== super.getNumMetaNodes() - 1) {
result.push(this.getNodeName(i) as string);
}
}
Expand All @@ -149,8 +149,8 @@ export class VectorSelection extends TreeNodeSelection {
delimiter: super.getDelimiter(),
numMetaNodes: super.getNumMetaNodes(),
treeData: this._myTreeData,
caseInsensitiveMatching: super.caseInsensitiveMatching,
allowOrOperator: super.allowOrOperator,
caseInsensitiveMatching: this.caseInsensitiveMatching,
allowOrOperator: this.allowOrOperator,
});
}
}
Loading
Loading