From df52ab477e686d0e933220d8dfaccedafe504ecf Mon Sep 17 00:00:00 2001 From: Ruben Thoms <69145689+rubenthoms@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:22:01 +0200 Subject: [PATCH] Moved `VectorDefinitions` to assets and `VectorSelector` to framework (#359) --- .../vectorDefinitions.ts | 6 +- .../components/VectorSelector/index.ts | 2 + .../private-assets}/aquifer.svg | 0 .../VectorSelector/private-assets}/block.svg | 0 .../private-assets}/calculated.svg | 0 .../private-assets}/duplicate.svg | 0 .../VectorSelector/private-assets}/field.svg | 0 .../VectorSelector/private-assets}/group.svg | 0 .../private-assets}/invalid.svg | 0 .../VectorSelector/private-assets}/misc.svg | 0 .../private-assets}/network.svg | 0 .../VectorSelector/private-assets}/others.svg | 0 .../private-assets}/region-region.svg | 0 .../VectorSelector/private-assets}/region.svg | 0 .../private-assets}/segment.svg | 0 .../private-assets}/unknown.svg | 0 .../private-assets}/well-completion.svg | 0 .../VectorSelector/private-assets}/well.svg | 0 .../private-utils/VectorSelection.ts | 0 .../VectorSelector/vectorSelector.tsx | 85 ++++++++++++++----- .../lib/components/VectorSelector/index.ts | 2 - frontend/src/lib/utils/vectorSelectorUtils.ts | 46 ---------- .../SimulationTimeSeriesMatrix/settings.tsx | 3 +- 23 files changed, 70 insertions(+), 74 deletions(-) rename frontend/src/{lib/components/VectorSelector/private-assets => assets}/vectorDefinitions.ts (99%) create mode 100644 frontend/src/framework/components/VectorSelector/index.ts rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/aquifer.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/block.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/calculated.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/duplicate.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/field.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/group.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/invalid.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/misc.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/network.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/others.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/region-region.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/region.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/segment.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/unknown.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/well-completion.svg (100%) rename frontend/src/{lib/components/VectorSelector/private-assets/images => framework/components/VectorSelector/private-assets}/well.svg (100%) rename frontend/src/{lib => framework}/components/VectorSelector/private-utils/VectorSelection.ts (100%) rename frontend/src/{lib => framework}/components/VectorSelector/vectorSelector.tsx (82%) delete mode 100644 frontend/src/lib/components/VectorSelector/index.ts delete mode 100644 frontend/src/lib/utils/vectorSelectorUtils.ts diff --git a/frontend/src/lib/components/VectorSelector/private-assets/vectorDefinitions.ts b/frontend/src/assets/vectorDefinitions.ts similarity index 99% rename from frontend/src/lib/components/VectorSelector/private-assets/vectorDefinitions.ts rename to frontend/src/assets/vectorDefinitions.ts index a187a0a1a..3b1c7a7ac 100644 --- a/frontend/src/lib/components/VectorSelector/private-assets/vectorDefinitions.ts +++ b/frontend/src/assets/vectorDefinitions.ts @@ -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", diff --git a/frontend/src/framework/components/VectorSelector/index.ts b/frontend/src/framework/components/VectorSelector/index.ts new file mode 100644 index 000000000..61c175df1 --- /dev/null +++ b/frontend/src/framework/components/VectorSelector/index.ts @@ -0,0 +1,2 @@ +export { VectorSelector, addVectorToVectorSelectorData, createVectorSelectorDataFromVectors } from "./vectorSelector"; +export type { VectorSelectorProps } from "./vectorSelector"; diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/aquifer.svg b/frontend/src/framework/components/VectorSelector/private-assets/aquifer.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/aquifer.svg rename to frontend/src/framework/components/VectorSelector/private-assets/aquifer.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/block.svg b/frontend/src/framework/components/VectorSelector/private-assets/block.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/block.svg rename to frontend/src/framework/components/VectorSelector/private-assets/block.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/calculated.svg b/frontend/src/framework/components/VectorSelector/private-assets/calculated.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/calculated.svg rename to frontend/src/framework/components/VectorSelector/private-assets/calculated.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/duplicate.svg b/frontend/src/framework/components/VectorSelector/private-assets/duplicate.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/duplicate.svg rename to frontend/src/framework/components/VectorSelector/private-assets/duplicate.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/field.svg b/frontend/src/framework/components/VectorSelector/private-assets/field.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/field.svg rename to frontend/src/framework/components/VectorSelector/private-assets/field.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/group.svg b/frontend/src/framework/components/VectorSelector/private-assets/group.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/group.svg rename to frontend/src/framework/components/VectorSelector/private-assets/group.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/invalid.svg b/frontend/src/framework/components/VectorSelector/private-assets/invalid.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/invalid.svg rename to frontend/src/framework/components/VectorSelector/private-assets/invalid.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/misc.svg b/frontend/src/framework/components/VectorSelector/private-assets/misc.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/misc.svg rename to frontend/src/framework/components/VectorSelector/private-assets/misc.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/network.svg b/frontend/src/framework/components/VectorSelector/private-assets/network.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/network.svg rename to frontend/src/framework/components/VectorSelector/private-assets/network.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/others.svg b/frontend/src/framework/components/VectorSelector/private-assets/others.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/others.svg rename to frontend/src/framework/components/VectorSelector/private-assets/others.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/region-region.svg b/frontend/src/framework/components/VectorSelector/private-assets/region-region.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/region-region.svg rename to frontend/src/framework/components/VectorSelector/private-assets/region-region.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/region.svg b/frontend/src/framework/components/VectorSelector/private-assets/region.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/region.svg rename to frontend/src/framework/components/VectorSelector/private-assets/region.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/segment.svg b/frontend/src/framework/components/VectorSelector/private-assets/segment.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/segment.svg rename to frontend/src/framework/components/VectorSelector/private-assets/segment.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/unknown.svg b/frontend/src/framework/components/VectorSelector/private-assets/unknown.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/unknown.svg rename to frontend/src/framework/components/VectorSelector/private-assets/unknown.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/well-completion.svg b/frontend/src/framework/components/VectorSelector/private-assets/well-completion.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/well-completion.svg rename to frontend/src/framework/components/VectorSelector/private-assets/well-completion.svg diff --git a/frontend/src/lib/components/VectorSelector/private-assets/images/well.svg b/frontend/src/framework/components/VectorSelector/private-assets/well.svg similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-assets/images/well.svg rename to frontend/src/framework/components/VectorSelector/private-assets/well.svg diff --git a/frontend/src/lib/components/VectorSelector/private-utils/VectorSelection.ts b/frontend/src/framework/components/VectorSelector/private-utils/VectorSelection.ts similarity index 100% rename from frontend/src/lib/components/VectorSelector/private-utils/VectorSelection.ts rename to frontend/src/framework/components/VectorSelector/private-utils/VectorSelection.ts diff --git a/frontend/src/lib/components/VectorSelector/vectorSelector.tsx b/frontend/src/framework/components/VectorSelector/vectorSelector.tsx similarity index 82% rename from frontend/src/lib/components/VectorSelector/vectorSelector.tsx rename to frontend/src/framework/components/VectorSelector/vectorSelector.tsx index 71c3b69e7..b5ab4bb41 100644 --- a/frontend/src/lib/components/VectorSelector/vectorSelector.tsx +++ b/frontend/src/framework/components/VectorSelector/vectorSelector.tsx @@ -1,21 +1,6 @@ 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, @@ -23,11 +8,22 @@ import { 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; @@ -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]; }); } @@ -299,3 +293,48 @@ export const VectorSelector: React.FC = (props) => { return ; }; + +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; +} diff --git a/frontend/src/lib/components/VectorSelector/index.ts b/frontend/src/lib/components/VectorSelector/index.ts deleted file mode 100644 index c453ae83c..000000000 --- a/frontend/src/lib/components/VectorSelector/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { VectorSelector } from "./vectorSelector"; -export type { VectorSelectorProps } from "./vectorSelector"; diff --git a/frontend/src/lib/utils/vectorSelectorUtils.ts b/frontend/src/lib/utils/vectorSelectorUtils.ts deleted file mode 100644 index 45bb3cfc1..000000000 --- a/frontend/src/lib/utils/vectorSelectorUtils.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { TreeDataNode } from "@lib/components/SmartNodeSelector"; - -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; -} diff --git a/frontend/src/modules/SimulationTimeSeriesMatrix/settings.tsx b/frontend/src/modules/SimulationTimeSeriesMatrix/settings.tsx index 7bd8d34b0..1c86d9969 100644 --- a/frontend/src/modules/SimulationTimeSeriesMatrix/settings.tsx +++ b/frontend/src/modules/SimulationTimeSeriesMatrix/settings.tsx @@ -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"; @@ -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";