Skip to content

Commit

Permalink
Moved VectorDefinitions to assets and VectorSelector to framework (
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms authored Sep 26, 2023
1 parent 90b4ea7 commit df52ab4
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const vectorDefinitions = {
export type VectorDefinitionsType = {
[key: string]: { type: string; description: string };
};

export const vectorDefinitions: VectorDefinitionsType = {
FWIP: {
type: "field",
description: "Water In Place",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/framework/components/VectorSelector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { VectorSelector, addVectorToVectorSelectorData, createVectorSelectorDataFromVectors } from "./vectorSelector";
export type { VectorSelectorProps } from "./vectorSelector";
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import React from "react";

import aquifer from "./private-assets/images/aquifer.svg";
import block from "./private-assets/images/block.svg";
import calculated from "./private-assets/images/calculated.svg";
import field from "./private-assets/images/field.svg";
import group from "./private-assets/images/group.svg";
import misc from "./private-assets/images/misc.svg";
import network from "./private-assets/images/network.svg";
import others from "./private-assets/images/others.svg";
import region_region from "./private-assets/images/region-region.svg";
import region from "./private-assets/images/region.svg";
import segment from "./private-assets/images/segment.svg";
import well_completion from "./private-assets/images/well-completion.svg";
import well from "./private-assets/images/well.svg";
import { vectorDefinitions } from "./private-assets/vectorDefinitions";
import { VectorSelection } from "./private-utils/VectorSelection";

import { VectorDefinitionsType, vectorDefinitions } from "@assets/vectorDefinitions";
import {
Direction,
KeyEventType,
SmartNodeSelectorComponent,
SmartNodeSelectorProps,
TreeData,
TreeDataNode,
} from "../SmartNodeSelector";
} from "@lib/components/SmartNodeSelector";

type VectorDefinitionsType = {
[key: string]: { type: string; description: string };
};
import aquifer from "./private-assets/aquifer.svg";
import block from "./private-assets/block.svg";
import calculated from "./private-assets/calculated.svg";
import field from "./private-assets/field.svg";
import group from "./private-assets/group.svg";
import misc from "./private-assets/misc.svg";
import network from "./private-assets/network.svg";
import others from "./private-assets/others.svg";
import region_region from "./private-assets/region-region.svg";
import region from "./private-assets/region.svg";
import segment from "./private-assets/segment.svg";
import well_completion from "./private-assets/well-completion.svg";
import well from "./private-assets/well.svg";
import { VectorSelection } from "./private-utils/VectorSelection";

export type VectorSelectorProps = SmartNodeSelectorProps & {
customVectorDefinitions?: VectorDefinitionsType;
Expand All @@ -46,9 +42,7 @@ export class VectorSelectorComponent extends SmartNodeSelectorComponent {
this.vectorDefinitions = vectorDefinitions;
if (props.customVectorDefinitions) {
Object.keys(props.customVectorDefinitions).forEach((vectorName: string) => {
this.vectorDefinitions[vectorName] = (props.customVectorDefinitions as VectorDefinitionsType)[
vectorName
];
this.vectorDefinitions[vectorName] = props.customVectorDefinitions[vectorName];
});
}

Expand Down Expand Up @@ -299,3 +293,48 @@ export const VectorSelector: React.FC<VectorSelectorProps> = (props) => {

return <VectorSelectorComponent {...adjustedProps} />;
};

export function addVectorToVectorSelectorData(
vectorSelectorData: TreeDataNode[],
vector: string,
description?: string,
descriptionAtLastNode = false
): void {
const nodes = vector.split(":");
let currentChildList = vectorSelectorData;

nodes.forEach((node, index) => {
let foundNode = false;
for (const child of currentChildList) {
if (child.name === node) {
foundNode = true;
currentChildList = child.children ?? [];
break;
}
}
if (!foundNode) {
const doAddDescription =
description !== undefined &&
((descriptionAtLastNode && index === nodes.length - 1) || (!descriptionAtLastNode && index === 0));

const nodeData: TreeDataNode = {
name: node,
children: index < nodes.length - 1 ? [] : undefined,
description: doAddDescription ? description : undefined,
};

currentChildList.push(nodeData);
currentChildList = nodeData.children ?? [];
}
});
}

export function createVectorSelectorDataFromVectors(vectors: string[]): TreeDataNode[] {
const vectorSelectorData: TreeDataNode[] = [];

for (const vector of vectors) {
addVectorToVectorSelectorData(vectorSelectorData, vector);
}

return vectorSelectorData;
}
2 changes: 0 additions & 2 deletions frontend/src/lib/components/VectorSelector/index.ts

This file was deleted.

46 changes: 0 additions & 46 deletions frontend/src/lib/utils/vectorSelectorUtils.ts

This file was deleted.

3 changes: 1 addition & 2 deletions frontend/src/modules/SimulationTimeSeriesMatrix/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EnsembleSet } from "@framework/EnsembleSet";
import { ModuleFCProps } from "@framework/Module";
import { useEnsembleSet } from "@framework/WorkbenchSession";
import { MultiEnsembleSelect } from "@framework/components/MultiEnsembleSelect";
import { VectorSelector, createVectorSelectorDataFromVectors } from "@framework/components/VectorSelector";
import { fixupEnsembleIdents } from "@framework/utils/ensembleUiHelpers";
import { ApiStatesWrapper } from "@lib/components/ApiStatesWrapper";
import { Checkbox } from "@lib/components/Checkbox";
Expand All @@ -16,10 +17,8 @@ import { Dropdown } from "@lib/components/Dropdown";
import { Label } from "@lib/components/Label";
import { RadioGroup } from "@lib/components/RadioGroup";
import { SmartNodeSelectorSelection, TreeDataNode } from "@lib/components/SmartNodeSelector";
import { VectorSelector } from "@lib/components/VectorSelector";
import { useValidState } from "@lib/hooks/useValidState";
import { resolveClassNames } from "@lib/utils/resolveClassNames";
import { createVectorSelectorDataFromVectors } from "@lib/utils/vectorSelectorUtils";

import { isEqual } from "lodash";

Expand Down

0 comments on commit df52ab4

Please sign in to comment.