Skip to content

Commit

Permalink
Parse automated charging task destination using task state
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Nov 28, 2023
1 parent e9101f0 commit c4658f9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions packages/react-components/lib/tasks/task-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -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';
}
Expand All @@ -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
) {
Expand All @@ -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';
}
Expand All @@ -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';
};

Expand Down

0 comments on commit c4658f9

Please sign in to comment.