Skip to content

Commit

Permalink
Adjusted to main
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 4, 2023
1 parent e51cd64 commit 3f19b63
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
5 changes: 3 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";

import { DrawerContent, GuiState } from "@framework/GuiMessageBroker";
import { LayoutElement, Workbench } from "@framework/Workbench";
import { LayoutElement } from "@framework/ModuleInstanceManager";
import { Workbench } from "@framework/Workbench";
import { NavBar } from "@framework/internal/components/NavBar";
import { SettingsContentPanels } from "@framework/internal/components/SettingsContentPanels";
import { useQueryClient } from "@tanstack/react-query";
Expand All @@ -20,7 +21,7 @@ function App() {
workbench.current.getModuleInstanceManager().makeLayout(layout);
}

if (workbench.current.getLayout().length === 0) {
if (workbench.current.getModuleInstanceManager().getLayout().length === 0) {
workbench.current.getGuiMessageBroker().setState(GuiState.DrawerContent, DrawerContent.ModulesList);
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/src/framework/TemplateRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BroadcastChannelKeyCategory } from "./Broadcaster";
import { LayoutElement } from "./LayoutService";
import { LayoutElement } from "./ModuleInstanceManager";
import { SyncSettingKey } from "./SyncSettings";

export type DataChannelTemplate = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/framework/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryClient } from "@tanstack/react-query";
import { Broadcaster } from "./Broadcaster";
import { EnsembleIdent } from "./EnsembleIdent";
import { GuiMessageBroker } from "./GuiMessageBroker";
import { ModuleInstanceManager } from "./LayoutService";
import { ModuleInstanceManager } from "./ModuleInstanceManager";
import { WorkbenchServices } from "./WorkbenchServices";
import { WorkbenchSession } from "./WorkbenchSession";
import { loadEnsembleSetMetadataFromBackend } from "./internal/EnsembleSetLoader";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";

import { GuiEvent, GuiEventPayloads } from "@framework/GuiMessageBroker";
import { LayoutElement, Workbench } from "@framework/Workbench";
import { LayoutElement } from "@framework/ModuleInstanceManager";
import { Workbench } from "@framework/Workbench";
import { useModuleInstances } from "@framework/internal/hooks/workbenchHooks";
import { useElementSize } from "@lib/hooks/useElementSize";
import {
Expand Down Expand Up @@ -37,9 +38,11 @@ export const Layout: React.FC<LayoutProps> = (props) => {
const mainRef = React.useRef<HTMLDivElement>(null);
const size = useElementSize(ref);
const layoutBoxRef = React.useRef<LayoutBox | null>(null);
const moduleInstances = useModuleInstances(props.workbench);
const moduleInstanceManager = props.workbench.getModuleInstanceManager();
const guiMessageBroker = props.workbench.getGuiMessageBroker();

const moduleInstances = useModuleInstances(moduleInstanceManager);

const convertLayoutRectToRealRect = React.useCallback(
(element: LayoutElement): Rect => {
return {
Expand All @@ -61,9 +64,9 @@ export const Layout: React.FC<LayoutProps> = (props) => {
let dragging = false;
let moduleInstanceId: string | null = null;
let moduleName: string | null = null;
setLayout(layoutService.getLayout());
let originalLayout: LayoutElement[] = layoutService.getLayout();
let currentLayout: LayoutElement[] = layoutService.getLayout();
setLayout(moduleInstanceManager.getLayout());
let originalLayout: LayoutElement[] = moduleInstanceManager.getLayout();
let currentLayout: LayoutElement[] = moduleInstanceManager.getLayout();
let originalLayoutBox = makeLayoutBoxes(originalLayout);
let currentLayoutBox = originalLayoutBox;
layoutBoxRef.current = currentLayoutBox;
Expand Down Expand Up @@ -119,7 +122,7 @@ export const Layout: React.FC<LayoutProps> = (props) => {
if (isNewModule && moduleName) {
const layoutElement = currentLayout.find((el) => el.moduleInstanceId === pointerDownElementId);
if (layoutElement) {
const instance = layoutService.makeAndAddModuleInstance(moduleName, layoutElement);
const instance = moduleInstanceManager.makeAndAddModuleInstance(moduleName, layoutElement);
layoutElement.moduleInstanceId = instance.getId();
layoutElement.moduleName = instance.getName();
}
Expand All @@ -132,7 +135,7 @@ export const Layout: React.FC<LayoutProps> = (props) => {
originalLayoutBox = currentLayoutBox;
layoutBoxRef.current = currentLayoutBox;
setLayout(currentLayout);
layoutService.setLayout(currentLayout);
moduleInstanceManager.setLayout(currentLayout);
setPosition({ x: 0, y: 0 });
setPointer({ x: -1, y: -1 });
e.stopPropagation();
Expand Down Expand Up @@ -228,13 +231,13 @@ export const Layout: React.FC<LayoutProps> = (props) => {
if (dragging) {
return;
}
layoutService.removeModuleInstance(e.moduleInstanceId);
currentLayoutBox.removeLayoutElement(e.moduleInstanceId);
moduleInstanceManager.removeModuleInstance(payload.moduleInstanceId);
currentLayoutBox.removeLayoutElement(payload.moduleInstanceId);
currentLayout = currentLayoutBox.toLayout();
setLayout(currentLayout);
originalLayout = currentLayout;
originalLayoutBox = currentLayoutBox;
layoutService.setLayout(currentLayout);
moduleInstanceManager.setLayout(currentLayout);
};

const removeModuleHeaderPointerDownSubscriber = guiMessageBroker.subscribeToEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { LayoutElement } from "@framework/LayoutService";
import { LayoutElement } from "@framework/ModuleInstanceManager";
import { Point, Rect, Size, outerRectContainsInnerRect, rectContainsPoint, rectsAreEqual } from "@lib/utils/geometry";

function layoutElementToRect(layoutElement: LayoutElement): Rect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import WebvizLogo from "@assets/webviz.svg";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { DrawerContent, GuiState, useGuiState } from "@framework/GuiMessageBroker";
import { ModuleInstanceEvents } from "@framework/LayoutService";
import { ModuleInstanceEvents } from "@framework/ModuleInstanceManager";
import { Workbench } from "@framework/Workbench";
import { useEnsembleSet } from "@framework/WorkbenchSession";
import { LoginButton } from "@framework/internal/components/LoginButton";
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/framework/internal/hooks/workbenchHooks.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from "react";

import { ModuleInstanceEvents, ModuleInstanceManager } from "@framework/LayoutService";
import { ModuleInstance } from "@framework/ModuleInstance";
import { ModuleInstanceEvents, ModuleInstanceManager } from "@framework/ModuleInstanceManager";

export function useModuleInstances(layoutService: ModuleInstanceManager): ModuleInstance<any>[] {
export function useModuleInstances(moduleInstanceManager: ModuleInstanceManager): ModuleInstance<any>[] {
const [moduleInstances, setModuleInstances] = React.useState<ModuleInstance<any>[]>([]);

React.useEffect(() => {
function handleModuleInstancesChange() {
setModuleInstances(layoutService.getModuleInstances());
setModuleInstances(moduleInstanceManager.getModuleInstances());
}

const unsubscribeFunc = layoutService.subscribe(
const unsubscribeFunc = moduleInstanceManager.subscribe(
ModuleInstanceEvents.ModuleInstancesChanged,
handleModuleInstancesChange
);
Expand Down

0 comments on commit 3f19b63

Please sign in to comment.