Skip to content

Commit

Permalink
Parse and display pickup and dropoff
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 b630b08 commit e9101f0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 13 deletions.
21 changes: 13 additions & 8 deletions packages/dashboard/src/components/tasks/tasks-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,25 @@ export const TasksApp = React.memo(
const results = resp.data as TaskState[];
const newTasks = results.slice(0, GET_LIMIT);

let taskIdsQuery = '';
for (const newTask of newTasks) {
taskIdsQuery += `${newTask.booking.id},`;
}
if (taskIdsQuery.length !== 0) {
taskIdsQuery = taskIdsQuery.slice(0, -1);
const taskIds: string[] = newTasks.map((task) => task.booking.id);
const taskIdsQuery = taskIds.join(',');
const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery))
.data;

const taskRequestMap: Record<string, TaskRequest> = {};
let requestIndex = 0;
for (const id of taskIds) {
if (requestIndex < taskRequests.length && taskRequests[requestIndex]) {
taskRequestMap[id] = taskRequests[requestIndex];
}
++requestIndex;
}
const taskRequests = await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery);

setTasksState((old) => ({
...old,
isLoading: false,
data: newTasks,
requests: {},
requests: taskRequestMap,
total:
results.length === GET_LIMIT
? tasksState.page * GET_LIMIT + 1
Expand Down
89 changes: 84 additions & 5 deletions packages/react-components/lib/tasks/task-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,88 @@ export function TaskDataGridTable({
);

const getPickup = (state: TaskState): string => {
// console.log(state);
return 'N/A';
const request: TaskRequest | undefined = tasks.requests[state.booking.id];
if (request === undefined || request.category === 'patrol') {
return 'n/a';
}

// custom deliveries
const supportedDeliveries = [
'delivery_pickup',
'delivery_sequential_lot_pickup',
'delivery_area_pickup',
];
if (
!request.description['category'] ||
!supportedDeliveries.includes(request.description['category'])
) {
return 'n/a';
}

// TODO(ac): use schemas
try {
const deliveryType: string = request.description['category'];
const perform_action_description =
request.description['phases'][0]['activity']['description']['activities'][1]['description'][
'description'
];

switch (deliveryType) {
case 'delivery_pickup':
const pickup_lot: string = perform_action_description['pickup_lot'];

Check failure on line 166 in packages/react-components/lib/tasks/task-table-datagrid.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

Unexpected lexical declaration in case block
return pickup_lot;
case 'delivery_sequential_lot_pickup':
case 'delivery_area_pickup':
const pickup_zone: string = perform_action_description['pickup_zone'];

Check failure on line 170 in packages/react-components/lib/tasks/task-table-datagrid.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

Unexpected lexical declaration in case block
return pickup_zone;
default:
return 'n/a';
}
} catch (e) {
console.error(`Failed to parse pickup lot/zone from task request: ${(e as Error).message}`);
}

return 'n/a';
};

const getDestination = (state: TaskState): string => {
const request: TaskRequest | undefined = tasks.requests[state.booking.id];
if (request === undefined) {
return 'n/a';
}

// patrol
if (
request.category === 'patrol' &&
request.description['places'] !== undefined &&
request.description['places'].length > 0
) {
return request.description['places'].at(-1);
}

// custom deliveries
const supportedDeliveries = [
'delivery_pickup',
'delivery_sequential_lot_pickup',
'delivery_area_pickup',
];
if (
!request.description['category'] ||
!supportedDeliveries.includes(request.description['category'])
) {
return 'n/a';
}

// TODO(ac): use schemas
try {
const destination =
request.description['phases'][0]['activity']['description']['activities'][2]['description'];
return destination;
} catch (e) {
console.error(`Failed to parse destination from task request: ${(e as Error).message}`);
}

return 'n/a';
};

const getMinimalDateOperators = getGridDateOperators(true).filter(
Expand All @@ -158,7 +238,7 @@ export function TaskDataGridTable({
<TextField
variant="standard"
value={
cellValues.row.booking.unix_millis_request_time ? `${day} ${month} ${year}` : 'N/A'
cellValues.row.booking.unix_millis_request_time ? `${day} ${month} ${year}` : 'n/a'
}
InputProps={{ disableUnderline: true }}
multiline
Expand Down Expand Up @@ -193,8 +273,7 @@ export function TaskDataGridTable({
headerName: 'Destination',
width: 150,
editable: false,
valueGetter: (params: GridValueGetterParams) =>
params.row.category ? params.row.category : 'unknown',
valueGetter: (params: GridValueGetterParams) => getDestination(params.row),
flex: 1,
filterOperators: getMinimalStringFilterOperators,
filterable: true,
Expand Down

0 comments on commit e9101f0

Please sign in to comment.