-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Heavu refactoring on Control panel typing and component selection
- Loading branch information
Showing
9 changed files
with
94 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
react-client/src/views/mapView/ControlPanelComponents/ControlPanel.tsx
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
react-client/src/views/mapView/ControlPanelItems/ControlPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Stack, styled } from "@mui/material"; | ||
import { useAppSelector } from "@/hooks/useStoreHooks"; | ||
import SelectControlPanelDropdown from "@/views/mapView/ControlPanelItems/SelectControlPanelDropdown"; | ||
import { ComponentMap } from "@/views/mapView/ControlPanelItems/components/componentsConstants"; | ||
|
||
const PaddedStack = styled(Stack)(({ theme }) => ({ | ||
padding: theme.spacing(4), | ||
})); | ||
|
||
const ControlPanel = () => { | ||
const selectedControlViewComponent = useAppSelector( | ||
(s) => s.ui.selectedControlViewComponent | ||
); | ||
|
||
return ( | ||
<PaddedStack> | ||
<SelectControlPanelDropdown /> | ||
{ComponentMap[selectedControlViewComponent]} | ||
</PaddedStack> | ||
); | ||
}; | ||
|
||
export default ControlPanel; |
48 changes: 48 additions & 0 deletions
48
react-client/src/views/mapView/ControlPanelItems/SelectControlPanelDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
FormControl, | ||
MenuItem, | ||
Select, | ||
SelectChangeEvent, | ||
} from "@mui/material"; | ||
import { useAppDispatch, useAppSelector } from "@/hooks/useStoreHooks"; | ||
import { ControlPanelComponents } from "@/views/mapView/ControlPanelItems/components/componentsConstants"; | ||
import { | ||
ControlViewComponent, | ||
setControlViewComponent, | ||
} from "@/store/slices/generalUiSlice"; | ||
|
||
const SelectControlPanelDropdown = () => { | ||
const selectedComponent = useAppSelector( | ||
(s) => s.ui.selectedControlViewComponent | ||
); | ||
const dispatch = useAppDispatch(); | ||
|
||
const controlPanelComponentKeys = Object.values(ControlPanelComponents); | ||
|
||
const isComponentString = (input: string): input is ControlViewComponent => | ||
controlPanelComponentKeys.includes(input as ControlViewComponent); | ||
|
||
const handleChange = ({ target: { value } }: SelectChangeEvent) => { | ||
if (!isComponentString(value)) { | ||
throw new Error( | ||
`Component mapping fails in ControlPanel, unknown value ${value}` | ||
); | ||
} | ||
|
||
dispatch(setControlViewComponent(value)); | ||
}; | ||
|
||
return ( | ||
<FormControl> | ||
<Select onChange={handleChange} value={selectedComponent}> | ||
{controlPanelComponentKeys.map((component) => ( | ||
<MenuItem key={component} value={component}> | ||
{component} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default SelectControlPanelDropdown; |
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
react-client/src/views/mapView/ControlPanelItems/components/componentsConstants.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Typography } from "@mui/material"; | ||
import AddCompanyComponent from "./AddCompanyComponent"; | ||
|
||
export const ControlPanelComponents = { | ||
InitialView: "InitialView", | ||
AddCompany: "AddCompany", | ||
GetCompanies: "GetCompanies", | ||
} as const; | ||
|
||
const { AddCompany, GetCompanies, InitialView } = ControlPanelComponents; | ||
// eslint-disable-next-line react-refresh/only-export-components | ||
export const ComponentMap: Record<string, JSX.Element | null> = { | ||
[AddCompany]: <AddCompanyComponent />, | ||
[InitialView]: <Typography>Very good initial view</Typography>, | ||
[GetCompanies]: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters