From 09f0466f29c236e455507845cc019e26bcd26ccb Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Thu, 24 Aug 2023 23:51:11 +0800 Subject: [PATCH] Fixing missing handler delivery task description (#745) * Fixing missing handler delivery task description Signed-off-by: Aaron Chong * Fix lint Signed-off-by: Aaron Chong * Disabled delivery when either pickup or dropoff points are empty Signed-off-by: Aaron Chong --------- Signed-off-by: Aaron Chong --- packages/dashboard/src/components/appbar.tsx | 39 +++++++++++++----- packages/react-components/lib/place.ts | 41 ++++--------------- .../lib/tasks/create-task.tsx | 40 +++++++++++------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/packages/dashboard/src/components/appbar.tsx b/packages/dashboard/src/components/appbar.tsx index ba95a5856..b3c6d85e3 100644 --- a/packages/dashboard/src/components/appbar.tsx +++ b/packages/dashboard/src/components/appbar.tsx @@ -35,7 +35,7 @@ import { AppBarTab, CreateTaskForm, CreateTaskFormProps, - getNamedPlaces, + getPlaces, HeaderBar, LogoButton, NavigationBar, @@ -169,8 +169,8 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea const [openCreateTaskForm, setOpenCreateTaskForm] = React.useState(false); const [waypointNames, setWaypointNames] = React.useState([]); const [cleaningZoneNames, setCleaningZoneNames] = React.useState([]); - const [pickupPointNames, setPickupPointNames] = React.useState([]); - const [dropoffPointNames, setDropoffPointNames] = React.useState([]); + const [pickupPoints, setPickupPoints] = React.useState>({}); + const [dropoffPoints, setDropoffPoints] = React.useState>({}); const [favoritesTasks, setFavoritesTasks] = React.useState([]); const [refreshTaskAppCount, setRefreshTaskAppCount] = React.useState(0); const [username, setUsername] = React.useState(null); @@ -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 = {}; + const dropoffPoints: Record = {}; + 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( @@ -577,10 +594,10 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea {openCreateTaskForm && ( setOpenCreateTaskForm(false)} diff --git a/packages/react-components/lib/place.ts b/packages/react-components/lib/place.ts index 6afaba637..218372a0d 100644 --- a/packages/react-components/lib/place.ts +++ b/packages/react-components/lib/place.ts @@ -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(); - const pickupPoints = new Map(); - const dropoffPoints = new Map(); - const cleaningZones = new Map(); - for (const level of buildingMap.levels) { for (const graphs of level.nav_graphs) { for (const vertex of graphs.vertices) { @@ -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()); } diff --git a/packages/react-components/lib/tasks/create-task.tsx b/packages/react-components/lib/tasks/create-task.tsx index 271f8059a..eb9c689e0 100644 --- a/packages/react-components/lib/tasks/create-task.tsx +++ b/packages/react-components/lib/tasks/create-task.tsx @@ -45,6 +45,7 @@ import { PositiveIntField } from '../form-inputs'; interface DeliveryTaskDescription { pickup: { place: string; + handler: string; payload: { sku: string; quantity: number; @@ -52,6 +53,7 @@ interface DeliveryTaskDescription { }; dropoff: { place: string; + handler: string; payload: { sku: string; quantity: number; @@ -134,15 +136,15 @@ function FormToolbar({ onSelectFileClick }: FormToolbarProps) { interface DeliveryTaskFormProps { taskDesc: DeliveryTaskDescription; - pickupPoints: string[]; - dropoffPoints: string[]; + pickupPoints: Record; + dropoffPoints: Record; onChange(taskDesc: TaskDescription): void; } function DeliveryTaskForm({ taskDesc, - pickupPoints, - dropoffPoints, + pickupPoints = {}, + dropoffPoints = {}, onChange, }: DeliveryTaskFormProps) { const theme = useTheme(); @@ -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], }, }) } @@ -202,7 +208,7 @@ function DeliveryTaskForm({ onChange({ ...taskDesc, pickup: { - ...taskDesc.dropoff, + ...taskDesc.pickup, payload: { ...taskDesc.pickup.payload, sku: (ev.target as HTMLInputElement).value, @@ -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], }, }) } @@ -548,6 +558,7 @@ function defaultDeliveryTask(): DeliveryTaskDescription { return { pickup: { place: '', + handler: '', payload: { sku: '', quantity: 1, @@ -555,6 +566,7 @@ function defaultDeliveryTask(): DeliveryTaskDescription { }, dropoff: { place: '', + handler: '', payload: { sku: '', quantity: 1, @@ -665,8 +677,8 @@ export interface CreateTaskFormProps allowBatch?: boolean; cleaningZones?: string[]; patrolWaypoints?: string[]; - pickupPoints?: string[]; - dropoffPoints?: string[]; + pickupPoints?: Record; + dropoffPoints?: Record; favoritesTasks: TaskFavorite[]; submitTasks?(tasks: TaskRequest[], schedule: Schedule | null): Promise; tasksFromFile?(): Promise | TaskRequest[]; @@ -684,8 +696,8 @@ export function CreateTaskForm({ user, cleaningZones = [], patrolWaypoints = [], - pickupPoints = [], - dropoffPoints = [], + pickupPoints = {}, + dropoffPoints = {}, favoritesTasks = [], submitTasks, tasksFromFile, @@ -1012,10 +1024,8 @@ export function CreateTaskForm({ Delivery