Skip to content

Commit

Permalink
remove location to multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
erasta committed Dec 17, 2024
1 parent 05825e4 commit ae2d36f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/src/DeviceTable/DeviceTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const DeviceTableSmall = ({ shownDevices }) => {
<DeviceItemLocationButton
deviceType={deviceType}
deviceItem={deviceItem}
surroundingDevices={shownDevices}
/>
</Stack>
</Paper>
Expand Down
1 change: 1 addition & 0 deletions client/src/Experiment/DeviceItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const DeviceItem = ({ data, setData, deviceType, showAttributes, devicesE
deviceType={deviceType}
deviceItem={data}
hasLocation={hasLocation}
surroundingDevices={devicesEnclosingList}
/>
</>
}
Expand Down
43 changes: 33 additions & 10 deletions client/src/Experiment/DeviceItemLocationButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { ButtonTooltip } from "../Utils/ButtonTooltip"
import { useContext } from "react";
import { experimentContext } from "../Context/ExperimentProvider";
import { RealMapName } from "../constants/constants";
import { ContextMenu } from "../Utils/ContextMenu";

export const DeviceItemLocationButton = ({ deviceType, deviceItem, hasLocation }) => {
export const DeviceItemLocationButton = ({ deviceType, deviceItem, hasLocation, surroundingDevices, }) => {
const { currTrial, setLocationsToDevices } = useContext(experimentContext);
let hasLocationCalced = hasLocation;
if (hasLocation === undefined) {
Expand All @@ -15,17 +16,39 @@ export const DeviceItemLocationButton = ({ deviceType, deviceItem, hasLocation }
hasLocationCalced = deviceTrial && deviceTrial.location && deviceTrial.location.coordinates;
}

const removeLocation = () => {
setLocationsToDevices([{ deviceTypeName: deviceType.name, deviceItemName: deviceItem.name }], [undefined]);
}

const menuItems = [
{ label: 'Remove location', callback: removeLocation },
];

if (surroundingDevices) {
menuItems.push({
label: 'Remove locations to all devices in list', callback: () => {
const devicesToRemove = surroundingDevices.map(d => {
return { deviceTypeName: d.deviceType.name, deviceItemName: d.deviceItem.name };
});
const locationsEmpty = devicesToRemove.map(() => undefined);
setLocationsToDevices(devicesToRemove, locationsEmpty);
}
})
}

return (
<>
{currTrial.trial &&
<ButtonTooltip
tooltip={hasLocationCalced ? "Remove location" : "Has no location"}
onClick={() => setLocationsToDevices([{ deviceTypeName: deviceType.name, deviceItemName: deviceItem.name }], [undefined])}
disabled={!hasLocationCalced}
>
{hasLocationCalced ? <LocationOff /> : <LocationOffOutlined />}
</ButtonTooltip>
}
{currTrial.trial && (
<ContextMenu menuItems={menuItems}>
<ButtonTooltip
tooltip={hasLocationCalced ? "Remove location" : "Has no location"}
onClick={removeLocation}
disabled={!hasLocationCalced}
>
{hasLocationCalced ? <LocationOff /> : <LocationOffOutlined />}
</ButtonTooltip>
</ContextMenu>
)}
</>
)
}

0 comments on commit ae2d36f

Please sign in to comment.