From 4962120db6eddcf04067f21bafedb2ed8d77ca31 Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Fri, 13 Dec 2024 15:21:08 +0800 Subject: [PATCH] task form, removed task details card, task logs app Signed-off-by: Aaron Chong --- .../components/tasks/task-details-card.tsx | 86 ------------------- .../src/components/tasks/task-form.test.tsx | 82 ++++++++++++++++++ .../src/components/tasks/task-logs-app.tsx | 48 ----------- 3 files changed, 82 insertions(+), 134 deletions(-) delete mode 100644 packages/rmf-dashboard-framework/src/components/tasks/task-details-card.tsx create mode 100644 packages/rmf-dashboard-framework/src/components/tasks/task-form.test.tsx delete mode 100644 packages/rmf-dashboard-framework/src/components/tasks/task-logs-app.tsx diff --git a/packages/rmf-dashboard-framework/src/components/tasks/task-details-card.tsx b/packages/rmf-dashboard-framework/src/components/tasks/task-details-card.tsx deleted file mode 100644 index 039f8b5c0..000000000 --- a/packages/rmf-dashboard-framework/src/components/tasks/task-details-card.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { Button, CardContent, Grid, Typography, useTheme } from '@mui/material'; -import { TaskStateOutput as TaskState } from 'api-client'; -import React from 'react'; -// import { UserProfileContext } from 'rmf-auth'; -import { of, switchMap } from 'rxjs'; - -import { useAppController, useRmfApi } from '../../hooks'; -import { AppEvents } from '../app-events'; -import { TaskInfo } from './task-info'; -// import { Enforcer } from '../permissions'; - -export const TaskDetailsCard = () => { - const theme = useTheme(); - const rmfApi = useRmfApi(); - const appController = useAppController(); - - const [taskState, setTaskState] = React.useState(null); - React.useEffect(() => { - const sub = AppEvents.taskSelect - .pipe( - switchMap((selectedTask) => - selectedTask ? rmfApi.getTaskStateObs(selectedTask.booking.id) : of(null), - ), - ) - .subscribe(setTaskState); - return () => sub.unsubscribe(); - }, [rmfApi]); - - // const profile = React.useContext(UserProfileContext); - const taskCancellable = - taskState && - // profile && - // Enforcer.canCancelTask(profile) && - taskState.status && - !['canceled', 'killed', 'completed', 'failed'].includes(taskState.status); - const handleCancelTaskClick = React.useCallback(async () => { - if (!taskState) { - return; - } - try { - await rmfApi.tasksApi?.postCancelTaskTasksCancelTaskPost({ - type: 'cancel_task_request', - task_id: taskState.booking.id, - }); - appController.showAlert('success', 'Successfully cancelled task'); - AppEvents.taskSelect.next(null); - } catch (e) { - appController.showAlert('error', `Failed to cancel task: ${(e as Error).message}`); - } - }, [appController, taskState, rmfApi]); - - return ( - - {taskState ? ( - <> - - - - - - - - ) : ( - - - - Click on a task to view more information - - - - )} - - ); -}; - -export default TaskDetailsCard; diff --git a/packages/rmf-dashboard-framework/src/components/tasks/task-form.test.tsx b/packages/rmf-dashboard-framework/src/components/tasks/task-form.test.tsx new file mode 100644 index 000000000..e97b50be4 --- /dev/null +++ b/packages/rmf-dashboard-framework/src/components/tasks/task-form.test.tsx @@ -0,0 +1,82 @@ +import { fireEvent, screen, within } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import { TaskForm } from './task-form'; + +import { RmfApiProvider } from '../../hooks'; +import { MockRmfApi, render, TestProviders } from '../../utils/test-utils.test'; + +const mockUser = 'mock_user'; +const mockFleets = { + fleet_1: ['robot_1'], + fleet_2: ['robot_2', 'robot_3'], +}; +const mockCleanZones = ['clean_zone_1', 'clean_zone_2']; +const mockWaypoints = ['waypoint_1', 'waypoint_2', 'waypoint_3']; +const mockPickupZones = ['pickup_zone_1', 'pickup_zone_2']; +const mockCartIds = ['cart_1', 'cart_2', 'cart_3']; +const mockPickupPoints = { + pickup_1: 'handler_1', + pickup_2: 'handler_2', +}; +const mockDropoffPoints = { + dropoff_1: 'handler_3', + dropoff_2: 'handler_4', +}; + +const onDispatchTask = vi.fn(); +const onScheduleTask = vi.fn(); +const onEditScheduleTask = vi.fn(); +const onSuccess = vi.fn(); +const onFail = vi.fn(); +const onSuccessFavoriteTask = vi.fn(); +const onFailFavoriteTask = vi.fn(); +const submitFavoriteTask = vi.fn(); +const deleteFavoriteTask = vi.fn(); +const onSuccessScheduling = vi.fn(); +const onFailScheduling = vi.fn(); + +describe('Task form', () => { + const rmfApi = new MockRmfApi(); + // mock out some api calls so they never resolves + rmfApi.doorsApi.postDoorRequestDoorsDoorNameRequestPost = () => new Promise(() => {}); + const Base = (props: React.PropsWithChildren<{}>) => { + return ( + + {props.children} + + ); + }; + + it('Task form renders', async () => { + render( + + + , + ); + }); +}); diff --git a/packages/rmf-dashboard-framework/src/components/tasks/task-logs-app.tsx b/packages/rmf-dashboard-framework/src/components/tasks/task-logs-app.tsx deleted file mode 100644 index 436333d82..000000000 --- a/packages/rmf-dashboard-framework/src/components/tasks/task-logs-app.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { CardContent } from '@mui/material'; -import { TaskEventLog, TaskStateOutput as TaskState } from 'api-client'; -import React from 'react'; - -import { useRmfApi } from '../../hooks'; -import { AppEvents } from '../app-events'; -import { TaskLogs } from './task-logs'; - -export const TaskLogsCard = () => { - const rmfApi = useRmfApi(); - const [taskState, setTaskState] = React.useState(null); - const [taskLogs, setTaskLogs] = React.useState(null); - React.useEffect(() => { - const sub = AppEvents.taskSelect.subscribe((task) => { - if (!task) { - setTaskState(null); - setTaskLogs(null); - return; - } - (async () => { - // TODO: Get full logs, then subscribe to log updates for new logs. - // Unlike with state events, we can't just subscribe to logs updates. - try { - const logs = ( - await rmfApi.tasksApi.getTaskLogTasksTaskIdLogGet( - task.booking.id, - `0,${Number.MAX_SAFE_INTEGER}`, - ) - ).data; - setTaskLogs(logs); - } catch { - console.log(`Failed to fetch task logs for ${task.booking.id}`); - setTaskLogs(null); - } - setTaskState(task); - })(); - }); - return () => sub.unsubscribe(); - }, [rmfApi]); - - return ( - - - - ); -}; - -export default TaskLogsCard;