From e00848148feece8f1bd1f8e6c257b8754307b686 Mon Sep 17 00:00:00 2001 From: Hunter Barclay Date: Wed, 4 Sep 2024 21:27:53 -0600 Subject: [PATCH] [BUG] Vite Server Crashing Chrome (#1108) * Isolated at least one issue to pickup interface * fix(vite-server)!: Vite server working with Chrome. Removed circular dependencies and isolated key structures into separate files. Cleanup still needed. * fix(vite-server)!: Readd panels and modals, fix imports, cleanup. * Formatted * Formatted --- .../theme-editor/AssignNewSchemeModal.tsx | 5 ++- .../theme-editor/NewInputSchemeModal.tsx | 5 ++- .../configuring/ChooseInputSchemePanel.tsx | 2 +- .../ConfigurationSavedEvent.ts | 16 +++++++ .../assembly-config/ConfigurationType.ts | 15 +++++++ .../assembly-config/ConfigurePanel.tsx | 42 +++---------------- .../ConfigureGamepiecePickupInterface.tsx | 2 +- .../ConfigureShotTrajectoryInterface.tsx | 2 +- .../ConfigureSubsystemsInterface.tsx | 2 +- .../SequentialBehaviorsInterface.tsx | 2 +- .../inputs/ConfigureInputsInterface.tsx | 2 +- .../inputs/ConfigureSchemeInterface.tsx | 2 +- .../ConfigureScoringZonesInterface.tsx | 2 +- .../scoring/ManageZonesInterface.tsx | 2 +- .../scoring/ZoneConfigInterface.tsx | 2 +- 15 files changed, 55 insertions(+), 48 deletions(-) create mode 100644 fission/src/ui/panels/configuring/assembly-config/ConfigurationSavedEvent.ts create mode 100644 fission/src/ui/panels/configuring/assembly-config/ConfigurationType.ts diff --git a/fission/src/ui/modals/configuring/theme-editor/AssignNewSchemeModal.tsx b/fission/src/ui/modals/configuring/theme-editor/AssignNewSchemeModal.tsx index 1f5c98bd2f..668590791b 100644 --- a/fission/src/ui/modals/configuring/theme-editor/AssignNewSchemeModal.tsx +++ b/fission/src/ui/modals/configuring/theme-editor/AssignNewSchemeModal.tsx @@ -6,8 +6,11 @@ import InputSystem from "@/systems/input/InputSystem" import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" import { SynthesisIcons } from "@/ui/components/StyledComponents" import { usePanelControlContext } from "@/ui/PanelContext" -import { ConfigurationType, setSelectedConfigurationType } from "@/ui/panels/configuring/assembly-config/ConfigurePanel" import { setSelectedScheme } from "@/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface" +import { + setSelectedConfigurationType, + ConfigurationType, +} from "@/ui/panels/configuring/assembly-config/ConfigurationType" const AssignNewSchemeModal: React.FC = ({ modalId }) => { const { openPanel } = usePanelControlContext() diff --git a/fission/src/ui/modals/configuring/theme-editor/NewInputSchemeModal.tsx b/fission/src/ui/modals/configuring/theme-editor/NewInputSchemeModal.tsx index 06b95d7a1f..acbce6b5e2 100644 --- a/fission/src/ui/modals/configuring/theme-editor/NewInputSchemeModal.tsx +++ b/fission/src/ui/modals/configuring/theme-editor/NewInputSchemeModal.tsx @@ -5,8 +5,11 @@ import InputSchemeManager from "@/systems/input/InputSchemeManager" import DefaultInputs from "@/systems/input/DefaultInputs" import { SynthesisIcons } from "@/ui/components/StyledComponents" import { usePanelControlContext } from "@/ui/PanelContext" -import { ConfigurationType, setSelectedConfigurationType } from "@/ui/panels/configuring/assembly-config/ConfigurePanel" import { setSelectedScheme } from "@/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface" +import { + ConfigurationType, + setSelectedConfigurationType, +} from "@/ui/panels/configuring/assembly-config/ConfigurationType" const NewInputSchemeModal: React.FC = ({ modalId }) => { const { openPanel } = usePanelControlContext() diff --git a/fission/src/ui/panels/configuring/ChooseInputSchemePanel.tsx b/fission/src/ui/panels/configuring/ChooseInputSchemePanel.tsx index 0d5b549f36..315be12ebb 100644 --- a/fission/src/ui/panels/configuring/ChooseInputSchemePanel.tsx +++ b/fission/src/ui/panels/configuring/ChooseInputSchemePanel.tsx @@ -18,8 +18,8 @@ import { useModalControlContext } from "@/ui/ModalContext" import { usePanelControlContext } from "@/ui/PanelContext" import { Box } from "@mui/material" import { useEffect, useReducer } from "react" -import { ConfigurationType, setSelectedConfigurationType } from "./assembly-config/ConfigurePanel" import { setSelectedScheme } from "./assembly-config/interfaces/inputs/ConfigureInputsInterface" +import { ConfigurationType, setSelectedConfigurationType } from "./assembly-config/ConfigurationType" /** We store the selected brain index globally to specify which robot the input scheme should be bound to. */ let selectedBrainIndexGlobal: number | undefined = undefined diff --git a/fission/src/ui/panels/configuring/assembly-config/ConfigurationSavedEvent.ts b/fission/src/ui/panels/configuring/assembly-config/ConfigurationSavedEvent.ts new file mode 100644 index 0000000000..9f240286f3 --- /dev/null +++ b/fission/src/ui/panels/configuring/assembly-config/ConfigurationSavedEvent.ts @@ -0,0 +1,16 @@ +/** An event to save whatever configuration interface is open when it is closed */ +export class ConfigurationSavedEvent extends Event { + public constructor() { + super("ConfigurationSaved") + + window.dispatchEvent(this) + } + + public static Listen(func: (e: Event) => void) { + window.addEventListener("ConfigurationSaved", func) + } + + public static RemoveListener(func: (e: Event) => void) { + window.removeEventListener("ConfigurationSaved", func) + } +} diff --git a/fission/src/ui/panels/configuring/assembly-config/ConfigurationType.ts b/fission/src/ui/panels/configuring/assembly-config/ConfigurationType.ts new file mode 100644 index 0000000000..927beac567 --- /dev/null +++ b/fission/src/ui/panels/configuring/assembly-config/ConfigurationType.ts @@ -0,0 +1,15 @@ +export enum ConfigurationType { + ROBOT, + FIELD, + INPUTS, +} + +let selectedConfigurationType: ConfigurationType = ConfigurationType.ROBOT + +export function setSelectedConfigurationType(type: ConfigurationType) { + selectedConfigurationType = type +} + +export function getConfigurationType() { + return selectedConfigurationType +} diff --git a/fission/src/ui/panels/configuring/assembly-config/ConfigurePanel.tsx b/fission/src/ui/panels/configuring/assembly-config/ConfigurePanel.tsx index 9dbdb7e076..0c261a96fa 100644 --- a/fission/src/ui/panels/configuring/assembly-config/ConfigurePanel.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/ConfigurePanel.tsx @@ -19,6 +19,8 @@ import ConfigureSubsystemsInterface from "./interfaces/ConfigureSubsystemsInterf import SequentialBehaviorsInterface from "./interfaces/SequentialBehaviorsInterface" import ConfigureShotTrajectoryInterface from "./interfaces/ConfigureShotTrajectoryInterface" import ConfigureGamepiecePickupInterface from "./interfaces/ConfigureGamepiecePickupInterface" +import { ConfigurationSavedEvent } from "./ConfigurationSavedEvent" +import { ConfigurationType, getConfigurationType, setSelectedConfigurationType } from "./ConfigurationType" enum ConfigMode { SUBSYSTEMS, @@ -29,23 +31,6 @@ enum ConfigMode { SCORING_ZONES, } -// eslint-disable-next-line react-refresh/only-export-components -export enum ConfigurationType { - ROBOT, - FIELD, - INPUTS, -} - -let selectedConfigurationType: ConfigurationType = ConfigurationType.ROBOT -// eslint-disable-next-line react-refresh/only-export-components -export function setSelectedConfigurationType(type: ConfigurationType) { - selectedConfigurationType = type -} - -function getConfigurationType() { - return selectedConfigurationType -} - /** Option for selecting a robot of field */ class AssemblySelectionOption extends SelectMenuOption { assemblyObject: MirabufSceneObject @@ -125,7 +110,7 @@ class ConfigModeSelectionOption extends SelectMenuOption { } } -const robotModes = [ +const robotModes: ConfigModeSelectionOption[] = [ new ConfigModeSelectionOption("Intake", ConfigMode.INTAKE), new ConfigModeSelectionOption("Ejector", ConfigMode.EJECTOR), new ConfigModeSelectionOption( @@ -140,7 +125,9 @@ const robotModes = [ ), new ConfigModeSelectionOption("Controls", ConfigMode.CONTROLS), ] -const fieldModes = [new ConfigModeSelectionOption("Scoring Zones", ConfigMode.SCORING_ZONES)] +const fieldModes: ConfigModeSelectionOption[] = [ + new ConfigModeSelectionOption("Scoring Zones", ConfigMode.SCORING_ZONES), +] interface ConfigModeSelectionProps { configurationType: ConfigurationType @@ -207,23 +194,6 @@ const ConfigInterface: React.FC = ({ configMode, assembly, } } -/** An event to save whatever configuration interface is open when it is closed */ -export class ConfigurationSavedEvent extends Event { - public constructor() { - super("ConfigurationSaved") - - window.dispatchEvent(this) - } - - public static Listen(func: (e: Event) => void) { - window.addEventListener("ConfigurationSaved", func) - } - - public static RemoveListener(func: (e: Event) => void) { - window.removeEventListener("ConfigurationSaved", func) - } -} - const ConfigurePanel: React.FC = ({ panelId }) => { const { openPanel, closePanel } = usePanelControlContext() const [configurationType, setConfigurationType] = useState(getConfigurationType()) diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureGamepiecePickupInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureGamepiecePickupInterface.tsx index 0e7dea833e..f15c2361a6 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureGamepiecePickupInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureGamepiecePickupInterface.tsx @@ -15,9 +15,9 @@ import { ThreeMatrix4_Array, } from "@/util/TypeConversions" import { useTheme } from "@/ui/ThemeContext" -import { ConfigurationSavedEvent } from "../ConfigurePanel" import Button from "@/ui/components/Button" import { Spacer } from "@/ui/components/StyledComponents" +import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent" // slider constants const MIN_ZONE_SIZE = 0.1 diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureShotTrajectoryInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureShotTrajectoryInterface.tsx index f5293e93cf..74bd39db7f 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureShotTrajectoryInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureShotTrajectoryInterface.tsx @@ -15,7 +15,7 @@ import { } from "@/util/TypeConversions" import { useTheme } from "@/ui/ThemeContext" import { RigidNodeId } from "@/mirabuf/MirabufParser" -import { ConfigurationSavedEvent } from "../ConfigurePanel" +import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent" import Button from "@/ui/components/Button" import { Spacer } from "@/ui/components/StyledComponents" diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureSubsystemsInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureSubsystemsInterface.tsx index d2e98e94d2..c034a446c4 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureSubsystemsInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/ConfigureSubsystemsInterface.tsx @@ -1,7 +1,7 @@ import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu" import React, { useMemo, useState } from "react" -import { ConfigurationSavedEvent } from "../ConfigurePanel" +import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent" import World from "@/systems/World" import SliderDriver from "@/systems/simulation/driver/SliderDriver" import HingeDriver from "@/systems/simulation/driver/HingeDriver" diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/SequentialBehaviorsInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/SequentialBehaviorsInterface.tsx index bec98015dd..575dc60db3 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/SequentialBehaviorsInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/SequentialBehaviorsInterface.tsx @@ -8,7 +8,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import SequenceableBehavior from "@/systems/simulation/behavior/synthesis/SequenceableBehavior" import GenericArmBehavior from "@/systems/simulation/behavior/synthesis/GenericArmBehavior" import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain" -import { ConfigurationSavedEvent } from "../ConfigurePanel" +import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent" import { SectionLabel, Spacer, SynthesisIcons } from "@/ui/components/StyledComponents" /** Grey label for a child behavior name */ diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface.tsx index 175bca83aa..defb467223 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureInputsInterface.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useState } from "react" -import { ConfigurationSavedEvent } from "../../ConfigurePanel" +import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent" import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu" import InputSystem from "@/systems/input/InputSystem" import InputSchemeManager, { InputScheme } from "@/systems/input/InputSchemeManager" diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureSchemeInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureSchemeInterface.tsx index 220191cab3..608aa1571e 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureSchemeInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/inputs/ConfigureSchemeInterface.tsx @@ -2,7 +2,7 @@ import InputSchemeManager, { InputScheme } from "@/systems/input/InputSchemeMana import Checkbox from "@/ui/components/Checkbox" import EditInputInterface from "./EditInputInterface" import { useCallback, useEffect, useRef, useState } from "react" -import { ConfigurationSavedEvent } from "../../ConfigurePanel" +import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent" import { SectionDivider } from "@/ui/components/StyledComponents" interface ConfigSchemeProps { diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ConfigureScoringZonesInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ConfigureScoringZonesInterface.tsx index 069c287f7d..12801b04ec 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ConfigureScoringZonesInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ConfigureScoringZonesInterface.tsx @@ -7,7 +7,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import { Box } from "@mui/material" import { ButtonIcon, SectionDivider, SectionLabel, SynthesisIcons } from "@/ui/components/StyledComponents" import { LabelSize } from "@/ui/components/Label" -import { ConfigurationSavedEvent } from "../../ConfigurePanel" +import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent" const saveZones = (zones: ScoringZonePreferences[] | undefined, field: MirabufSceneObject | undefined) => { if (!zones || !field) return diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ManageZonesInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ManageZonesInterface.tsx index a051cc1120..ab9f47d6b1 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ManageZonesInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ManageZonesInterface.tsx @@ -7,7 +7,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem" import World from "@/systems/World" import MirabufSceneObject from "@/mirabuf/MirabufSceneObject" import { Box } from "@mui/material" -import { ConfigurationSavedEvent } from "../../ConfigurePanel" +import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent" import { AddButtonInteractiveColor, DeleteButton, EditButton } from "@/ui/components/StyledComponents" const saveZones = (zones: ScoringZonePreferences[] | undefined, field: MirabufSceneObject | undefined) => { diff --git a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx index 409daeece8..b6a375caa4 100644 --- a/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx +++ b/fission/src/ui/panels/configuring/assembly-config/interfaces/scoring/ZoneConfigInterface.tsx @@ -16,7 +16,7 @@ import { ToggleButton, ToggleButtonGroup } from "@/ui/components/ToggleButtonGro import { Alliance, ScoringZonePreferences } from "@/systems/preferences/PreferenceTypes" import { RigidNodeId } from "@/mirabuf/MirabufParser" import { DeltaFieldTransforms_PhysicalProp as DeltaFieldTransforms_VisualProperties } from "@/util/threejs/MeshCreation" -import { ConfigurationSavedEvent } from "../../ConfigurePanel" +import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent" /** * Saves ejector configuration to selected field.