From c4658f97a005f5075786a9a46974b6c576cfa6c0 Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Tue, 28 Nov 2023 03:42:23 +0000 Subject: [PATCH] Parse automated charging task destination using task state Signed-off-by: Aaron Chong --- .../lib/tasks/task-table-datagrid.tsx | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/react-components/lib/tasks/task-table-datagrid.tsx b/packages/react-components/lib/tasks/task-table-datagrid.tsx index 5f7bbe66e..3dde1d024 100644 --- a/packages/react-components/lib/tasks/task-table-datagrid.tsx +++ b/packages/react-components/lib/tasks/task-table-datagrid.tsx @@ -136,7 +136,7 @@ export function TaskDataGridTable({ const getPickup = (state: TaskState): string => { const request: TaskRequest | undefined = tasks.requests[state.booking.id]; - if (request === undefined || request.category === 'patrol') { + if (request === undefined || request.category.toLowerCase() === 'patrol') { return 'n/a'; } @@ -162,13 +162,15 @@ export function TaskDataGridTable({ ]; switch (deliveryType) { - case 'delivery_pickup': + case 'delivery_pickup': { const pickup_lot: string = perform_action_description['pickup_lot']; return pickup_lot; + } case 'delivery_sequential_lot_pickup': - case 'delivery_area_pickup': + case 'delivery_area_pickup': { const pickup_zone: string = perform_action_description['pickup_zone']; return pickup_zone; + } default: return 'n/a'; } @@ -187,7 +189,7 @@ export function TaskDataGridTable({ // patrol if ( - request.category === 'patrol' && + request.category.toLowerCase() === 'patrol' && request.description['places'] !== undefined && request.description['places'].length > 0 ) { @@ -202,7 +204,7 @@ export function TaskDataGridTable({ ]; if ( !request.description['category'] || - !supportedDeliveries.includes(request.description['category']) + !supportedDeliveries.includes((request.description['category'] as string).toLowerCase()) ) { return 'n/a'; } @@ -216,6 +218,24 @@ export function TaskDataGridTable({ console.error(`Failed to parse destination from task request: ${(e as Error).message}`); } + // automated tasks that can only be parsed with state + if (state.category && state.category === 'Charge Battery') { + try { + const charge_phase = state['phases'] ? state['phases']['1'] : undefined; + const charge_events = charge_phase ? charge_phase.events : undefined; + const charge_event_name = charge_events ? charge_events['1'].name : undefined; + if (charge_event_name === undefined) { + console.error('Unable to parse charging event name.'); + return 'n/a'; + } + + const charging_place = charge_event_name?.split('[place:')[1].split(']')[0]; + return charging_place; + } catch (e) { + console.error(`Failed to parse charging point from task state: ${(e as Error).message}`); + } + } + return 'n/a'; };