Skip to content

Commit

Permalink
Fixing missing handler delivery task description (#745)
Browse files Browse the repository at this point in the history
* Fixing missing handler delivery task description

Signed-off-by: Aaron Chong <[email protected]>

* Fix lint

Signed-off-by: Aaron Chong <[email protected]>

* Disabled delivery when either pickup or dropoff points are empty

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth authored Aug 24, 2023
1 parent 54c4d3a commit 09f0466
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
39 changes: 28 additions & 11 deletions packages/dashboard/src/components/appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
AppBarTab,
CreateTaskForm,
CreateTaskFormProps,
getNamedPlaces,
getPlaces,
HeaderBar,
LogoButton,
NavigationBar,
Expand Down Expand Up @@ -169,8 +169,8 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
const [openCreateTaskForm, setOpenCreateTaskForm] = React.useState(false);
const [waypointNames, setWaypointNames] = React.useState<string[]>([]);
const [cleaningZoneNames, setCleaningZoneNames] = React.useState<string[]>([]);
const [pickupPointNames, setPickupPointNames] = React.useState<string[]>([]);
const [dropoffPointNames, setDropoffPointNames] = React.useState<string[]>([]);
const [pickupPoints, setPickupPoints] = React.useState<Record<string, string>>({});
const [dropoffPoints, setDropoffPoints] = React.useState<Record<string, string>>({});
const [favoritesTasks, setFavoritesTasks] = React.useState<TaskFavorite[]>([]);
const [refreshTaskAppCount, setRefreshTaskAppCount] = React.useState(0);
const [username, setUsername] = React.useState<string | null>(null);
Expand Down Expand Up @@ -224,11 +224,28 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
const subs: Subscription[] = [];
subs.push(
rmf.buildingMapObs.subscribe((map) => {
const namedPlaces = getNamedPlaces(map);
setPickupPointNames(namedPlaces.pickupPoints.map((w) => w.vertex.name));
setDropoffPointNames(namedPlaces.dropoffPoints.map((w) => w.vertex.name));
setCleaningZoneNames(namedPlaces.cleaningZones.map((w) => w.vertex.name));
setWaypointNames(namedPlaces.places.map((w) => w.vertex.name));
const places = getPlaces(map);
const waypointNames: string[] = [];
const pickupPoints: Record<string, string> = {};
const dropoffPoints: Record<string, string> = {};
const cleaningZoneNames: string[] = [];
for (const p of places) {
if (p.pickupHandler !== undefined && p.pickupHandler.length !== 0) {
pickupPoints[p.vertex.name] = p.pickupHandler;
}
if (p.dropoffHandler !== undefined && p.dropoffHandler.length !== 0) {
dropoffPoints[p.vertex.name] = p.dropoffHandler;
}
if (p.cleaningZone !== undefined && p.cleaningZone === true) {
cleaningZoneNames.push(p.vertex.name);
}
waypointNames.push(p.vertex.name);
}

setPickupPoints(pickupPoints);
setDropoffPoints(dropoffPoints);
setCleaningZoneNames(cleaningZoneNames);
setWaypointNames(waypointNames);
}),
);
subs.push(
Expand Down Expand Up @@ -577,10 +594,10 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
{openCreateTaskForm && (
<CreateTaskForm
user={username ? username : 'unknown user'}
cleaningZones={cleaningZoneNames}
patrolWaypoints={waypointNames}
pickupPoints={pickupPointNames}
dropoffPoints={dropoffPointNames}
cleaningZones={cleaningZoneNames}
pickupPoints={pickupPoints}
dropoffPoints={dropoffPoints}
favoritesTasks={favoritesTasks}
open={openCreateTaskForm}
onClose={() => setOpenCreateTaskForm(false)}
Expand Down
41 changes: 7 additions & 34 deletions packages/react-components/lib/place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,13 @@ const DEFAULT_CLEANING_ZONE_PARAM_NAME = 'is_cleaning_zone';
export interface Place {
level: string;
vertex: GraphNode;
}

export interface NamedPlaces {
places: Place[];
pickupPoints: Place[];
dropoffPoints: Place[];
cleaningZones: Place[];
pickupHandler?: string;
dropoffHandler?: string;
cleaningZone?: boolean;
}

export function getPlaces(buildingMap: BuildingMap): Place[] {
const places: Place[] = [];
for (const level of buildingMap.levels) {
for (const graphs of level.nav_graphs) {
for (const vertex of graphs.vertices) {
if (vertex.name) {
places.push({ level: level.name, vertex });
}
}
}
}
return places;
}

export function getNamedPlaces(buildingMap: BuildingMap): NamedPlaces {
const places = new Map<string, Place>();
const pickupPoints = new Map<string, Place>();
const dropoffPoints = new Map<string, Place>();
const cleaningZones = new Map<string, Place>();

for (const level of buildingMap.levels) {
for (const graphs of level.nav_graphs) {
for (const vertex of graphs.vertices) {
Expand All @@ -45,23 +23,18 @@ export function getNamedPlaces(buildingMap: BuildingMap): NamedPlaces {
const place: Place = { level: level.name, vertex };
for (const p of vertex.params) {
if (p.name === DEFAULT_PICKUP_POINT_PARAM_NAME) {
pickupPoints.set(vertex.name, place);
place.pickupHandler = p.value_string;
}
if (p.name === DEFAULT_DROPOFF_POINT_PARAM_NAME) {
dropoffPoints.set(vertex.name, place);
place.dropoffHandler = p.value_string;
}
if (p.name === DEFAULT_CLEANING_ZONE_PARAM_NAME) {
cleaningZones.set(vertex.name, place);
place.cleaningZone = true;
}
}
places.set(vertex.name, place);
}
}
}
return {
places: Array.from(places.values()),
pickupPoints: Array.from(pickupPoints.values()),
dropoffPoints: Array.from(dropoffPoints.values()),
cleaningZones: Array.from(cleaningZones.values()),
};
return Array.from(places.values());
}
40 changes: 25 additions & 15 deletions packages/react-components/lib/tasks/create-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ import { PositiveIntField } from '../form-inputs';
interface DeliveryTaskDescription {
pickup: {
place: string;
handler: string;
payload: {
sku: string;
quantity: number;
};
};
dropoff: {
place: string;
handler: string;
payload: {
sku: string;
quantity: number;
Expand Down Expand Up @@ -134,15 +136,15 @@ function FormToolbar({ onSelectFileClick }: FormToolbarProps) {

interface DeliveryTaskFormProps {
taskDesc: DeliveryTaskDescription;
pickupPoints: string[];
dropoffPoints: string[];
pickupPoints: Record<string, string>;
dropoffPoints: Record<string, string>;
onChange(taskDesc: TaskDescription): void;
}

function DeliveryTaskForm({
taskDesc,
pickupPoints,
dropoffPoints,
pickupPoints = {},
dropoffPoints = {},
onChange,
}: DeliveryTaskFormProps) {
const theme = useTheme();
Expand All @@ -154,24 +156,28 @@ function DeliveryTaskForm({
id="pickup-location"
freeSolo
fullWidth
options={pickupPoints}
options={Object.keys(pickupPoints)}
value={taskDesc.pickup.place}
onChange={(_ev, newValue) =>
newValue !== null &&
pickupPoints[newValue] &&
onChange({
...taskDesc,
pickup: {
...taskDesc.pickup,
place: newValue,
handler: pickupPoints[newValue],
},
})
}
onBlur={(ev) =>
pickupPoints[(ev.target as HTMLInputElement).value] &&
onChange({
...taskDesc,
pickup: {
...taskDesc.pickup,
place: (ev.target as HTMLInputElement).value,
handler: pickupPoints[(ev.target as HTMLInputElement).value],
},
})
}
Expand Down Expand Up @@ -202,7 +208,7 @@ function DeliveryTaskForm({
onChange({
...taskDesc,
pickup: {
...taskDesc.dropoff,
...taskDesc.pickup,
payload: {
...taskDesc.pickup.payload,
sku: (ev.target as HTMLInputElement).value,
Expand Down Expand Up @@ -253,24 +259,28 @@ function DeliveryTaskForm({
id="dropoff-location"
freeSolo
fullWidth
options={dropoffPoints}
options={Object.keys(dropoffPoints)}
value={taskDesc.dropoff.place}
onChange={(_ev, newValue) =>
newValue !== null &&
dropoffPoints[newValue] &&
onChange({
...taskDesc,
dropoff: {
...taskDesc.dropoff,
place: newValue,
handler: dropoffPoints[newValue],
},
})
}
onBlur={(ev) =>
dropoffPoints[(ev.target as HTMLInputElement).value] &&
onChange({
...taskDesc,
dropoff: {
...taskDesc.dropoff,
place: (ev.target as HTMLInputElement).value,
handler: dropoffPoints[(ev.target as HTMLInputElement).value],
},
})
}
Expand Down Expand Up @@ -548,13 +558,15 @@ function defaultDeliveryTask(): DeliveryTaskDescription {
return {
pickup: {
place: '',
handler: '',
payload: {
sku: '',
quantity: 1,
},
},
dropoff: {
place: '',
handler: '',
payload: {
sku: '',
quantity: 1,
Expand Down Expand Up @@ -665,8 +677,8 @@ export interface CreateTaskFormProps
allowBatch?: boolean;
cleaningZones?: string[];
patrolWaypoints?: string[];
pickupPoints?: string[];
dropoffPoints?: string[];
pickupPoints?: Record<string, string>;
dropoffPoints?: Record<string, string>;
favoritesTasks: TaskFavorite[];
submitTasks?(tasks: TaskRequest[], schedule: Schedule | null): Promise<void>;
tasksFromFile?(): Promise<TaskRequest[]> | TaskRequest[];
Expand All @@ -684,8 +696,8 @@ export function CreateTaskForm({
user,
cleaningZones = [],
patrolWaypoints = [],
pickupPoints = [],
dropoffPoints = [],
pickupPoints = {},
dropoffPoints = {},
favoritesTasks = [],
submitTasks,
tasksFromFile,
Expand Down Expand Up @@ -1012,10 +1024,8 @@ export function CreateTaskForm({
<MenuItem
value="delivery"
disabled={
!pickupPoints ||
pickupPoints.length === 0 ||
!dropoffPoints ||
dropoffPoints.length === 0
Object.keys(pickupPoints).length === 0 ||
Object.keys(dropoffPoints).length === 0
}
>
Delivery
Expand Down

0 comments on commit 09f0466

Please sign in to comment.