Skip to content

Commit

Permalink
feat(ui): Move map-related features to map management page
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Jan 15, 2022
1 parent 4a6c9fa commit ea45f01
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 176 deletions.
8 changes: 6 additions & 2 deletions frontend/src/components/ValetudoAppBar.tsx
Expand Up @@ -145,10 +145,14 @@ const menuTree: Array<MenuEntry | MenuSubEntry | MenuSubheader> = [
menuText: "Map Management",
requiredCapabilities: {
capabilities: [
Capability.CombinedVirtualRestrictions,
Capability.PersistentMapControl,
Capability.MappingPass,
Capability.MapReset,

Capability.MapSegmentEdit,
Capability.MapSegmentRename
Capability.MapSegmentRename,

Capability.CombinedVirtualRestrictions
],
type: "anyof"
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/robot/capabilities/Capabilities.tsx
@@ -1,5 +1,4 @@
import React from "react";
import MapDataManagement from "./MapDataManagement";
import Speaker from "./Speaker";
import Switches from "./Switches";
import VoicePackManagement from "./VoicePackManagement";
Expand All @@ -18,7 +17,6 @@ const Capabilities = (): JSX.Element => {
VoicePackManagement,
DoNotDisturb,
Wifi,
MapDataManagement
];
const [quirksSupported] = useCapabilitiesSupported(Capability.Quirks);

Expand Down
74 changes: 0 additions & 74 deletions frontend/src/robot/capabilities/MapDataManagement.tsx

This file was deleted.

55 changes: 0 additions & 55 deletions frontend/src/robot/capabilities/Switches.tsx
Expand Up @@ -8,62 +8,10 @@ import {
useCarpetModeStateQuery,
useKeyLockStateMutation,
useKeyLockStateQuery,
usePersistentDataMutation,
usePersistentDataQuery
} from "../../api";
import ConfirmationDialog from "../../components/ConfirmationDialog";
import {useCapabilitiesSupported} from "../../CapabilitiesProvider";
import {CapabilityItem} from "./CapabilityLayout";

const PersistentDataSwitch = () => {
const [dialogOpen, setDialogOpen] = React.useState(false);
const {
data: persistentData,
isFetching: persistentDataLoading,
isError: persistentDataError,
} = usePersistentDataQuery();

const {mutate: mutatePersistentData, isLoading: persistentDataChanging} = usePersistentDataMutation();
const loading = persistentDataLoading || persistentDataChanging;
const disabled = loading || persistentDataChanging || persistentDataError;

if (persistentDataError) {
return (
<Typography variant="body2" color="error">
Error loading persistent data state
</Typography>
);
}

return (
<>
<FormControlLabel control={
<Switch disabled={disabled}
checked={persistentData?.enabled ?? false}
onChange={(e) => {
if (e.target.checked) {
mutatePersistentData(true);
} else {
setDialogOpen(true);
}
}}/>
}
label="Persistent data"/>
<Typography variant="body2" sx={{mb: 1}}>
Persistent data is a feature of some robots which allows to save no-go areas and virtual walls. It
also allows the robot to drive back to the dock wherever it is and keeps the map from being rotated.
</Typography>
<ConfirmationDialog title="Delete persistent data?"
text="Do you really want to disable persistent data? This deletes the current map, all no-go zones and virtual walls."
open={dialogOpen} onClose={() => {
setDialogOpen(false);
}} onAccept={() => {
mutatePersistentData(false);
}}/>
</>
);
};

const renderSwitch = (
isError: boolean,
loading: boolean,
Expand Down Expand Up @@ -149,20 +97,17 @@ const AutoEmptyDockAutoEmptySwitch = () => {

const Switches: FunctionComponent = () => {
const [
persistentMapControl,
keyLockControl,
carpetModeControl,
autoEmptyDockAutoEmptyControl
] = useCapabilitiesSupported(
Capability.PersistentMapControl,
Capability.KeyLock,
Capability.CarpetModeControl,
Capability.AutoEmptyDockAutoEmptyControl
);

return (
<CapabilityItem title={"Switches"}>
{persistentMapControl && <PersistentDataSwitch/>}
{keyLockControl && <KeyLockSwitch/>}
{carpetModeControl && <CarpetModeSwitch/>}
{autoEmptyDockAutoEmptyControl && <AutoEmptyDockAutoEmptySwitch/>}
Expand Down

0 comments on commit ea45f01

Please sign in to comment.