Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct dispatch to fleet or robot #1004

Merged
merged 23 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3213eea
Basic implementation of priority based on legacy implementation
aaronchongth Aug 15, 2024
caa8fd7
Use icons for favorite
aaronchongth Aug 16, 2024
f9b2efa
Fix warning time, use switch and made buttons nicer
aaronchongth Aug 16, 2024
2bdd4d3
To display priority
aaronchongth Aug 16, 2024
77950be
Lint
aaronchongth Aug 19, 2024
09d6e57
Merge branch 'main' into feat/labels-priority-schedule
aaronchongth Aug 19, 2024
a6a4e41
Helper function to handle null and undefined priority, clean up creation
aaronchongth Aug 20, 2024
0703b77
Use switch for priority, flip low priority icon
aaronchongth Aug 20, 2024
6a5ff5a
Remove getDefaultTaskPriorty
aaronchongth Aug 20, 2024
ce848a2
Basic implementation working, still with frontend errors
aaronchongth Aug 22, 2024
ca9ecf9
Fix component render sequence issues
aaronchongth Aug 30, 2024
a29954b
Lint
aaronchongth Aug 30, 2024
a310646
Merge branch 'main' into feature/fleet-robot-selection
aaronchongth Sep 3, 2024
cdf7fba
Fix capitalization, disable scheuling for robot dispatch, allow edit …
aaronchongth Sep 4, 2024
35f92a8
Comments and consolidate logs
aaronchongth Sep 4, 2024
d9c8fba
Slight tree view for robots, change dropdown size, use const enum
aaronchongth Sep 4, 2024
7ba2064
Refactor dispatch and schedule callbacks, fix edit schedule event, ad…
aaronchongth Sep 5, 2024
bfd018a
Merge branch 'main' into feature/fleet-robot-selection
aaronchongth Sep 5, 2024
ad263a0
Remove stale print
aaronchongth Sep 5, 2024
3692aa7
lint
aaronchongth Sep 5, 2024
4dece1e
Make task form more generically named, new callback for schedule editing
aaronchongth Sep 14, 2024
adb317f
Merge branch 'main' into feature/fleet-robot-selection
aaronchongth Sep 17, 2024
9c592af
Document props
aaronchongth Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/dashboard/src/components/appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ import {
import { AlertRequest, FireAlarmTriggerState, TaskFavorite } from 'api-client';
import { formatDistance } from 'date-fns';
import React from 'react';
import { ConfirmationDialog, CreateTaskForm, CreateTaskFormProps } from 'react-components';
import { ConfirmationDialog, TaskForm, TaskFormProps } from 'react-components';
import { Subscription } from 'rxjs';

import { useAppController } from '../hooks/use-app-controller';
import { useAuthenticator } from '../hooks/use-authenticator';
import { useCreateTaskFormData } from '../hooks/use-create-task-form';
import { useTaskFormData } from '../hooks/use-create-task-form';
import { useResources } from '../hooks/use-resources';
import { useRmfApi } from '../hooks/use-rmf-api';
import { useSettings } from '../hooks/use-settings';
Expand Down Expand Up @@ -117,7 +117,7 @@ export const AppBar = React.memo(
>(undefined);

const { waypointNames, pickupPoints, dropoffPoints, cleaningZoneNames, fleets } =
useCreateTaskFormData(rmfApi);
useTaskFormData(rmfApi);
const username = profile.user.username;

async function handleLogout(): Promise<void> {
Expand Down Expand Up @@ -147,7 +147,7 @@ export const AppBar = React.memo(
return () => subs.forEach((s) => s.unsubscribe());
}, [rmfApi]);

const dispatchTaskCallback = React.useCallback<Required<CreateTaskFormProps>['onDispatchTask']>(
const dispatchTaskCallback = React.useCallback<Required<TaskFormProps>['onDispatchTask']>(
async (taskRequest, robotDispatchTarget) => {
if (!rmfApi) {
throw new Error('tasks api not available');
Expand All @@ -158,7 +158,7 @@ export const AppBar = React.memo(
[rmfApi],
);

const scheduleTaskCallback = React.useCallback<Required<CreateTaskFormProps>['onScheduleTask']>(
const scheduleTaskCallback = React.useCallback<Required<TaskFormProps>['onScheduleTask']>(
async (taskRequest, schedule) => {
if (!rmfApi) {
throw new Error('tasks api not available');
Expand All @@ -182,19 +182,15 @@ export const AppBar = React.memo(
return () => sub.unsubscribe();
}, [rmfApi]);

const submitFavoriteTask = React.useCallback<
Required<CreateTaskFormProps>['submitFavoriteTask']
>(
const submitFavoriteTask = React.useCallback<Required<TaskFormProps>['submitFavoriteTask']>(
async (taskFavoriteRequest) => {
await rmfApi.tasksApi.postFavoriteTaskFavoriteTasksPost(taskFavoriteRequest);
AppEvents.refreshFavoriteTasks.next();
},
[rmfApi],
);

const deleteFavoriteTask = React.useCallback<
Required<CreateTaskFormProps>['deleteFavoriteTask']
>(
const deleteFavoriteTask = React.useCallback<Required<TaskFormProps>['deleteFavoriteTask']>(
async (favoriteTask) => {
if (!favoriteTask.id) {
throw new Error('Id is needed');
Expand Down Expand Up @@ -457,7 +453,7 @@ export const AppBar = React.memo(
</Menu>

{openCreateTaskForm && (
<CreateTaskForm
<TaskForm
user={username ? username : 'unknown user'}
fleets={fleets}
tasksToDisplay={taskRegistry.taskDefinitions}
Expand All @@ -472,6 +468,7 @@ export const AppBar = React.memo(
onClose={() => setOpenCreateTaskForm(false)}
onDispatchTask={dispatchTaskCallback}
onScheduleTask={scheduleTaskCallback}
onEditScheduleTask={undefined}
submitFavoriteTask={submitFavoriteTask}
deleteFavoriteTask={deleteFavoriteTask}
onSuccess={() => {
Expand Down
24 changes: 14 additions & 10 deletions packages/dashboard/src/components/tasks/task-schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { ScheduledTask, ScheduledTaskScheduleOutput as ApiSchedule } from 'api-c
import React from 'react';
import {
ConfirmationDialog,
CreateTaskForm,
CreateTaskFormProps,
EventEditDeletePopup,
Schedule,
TaskForm,
TaskFormProps,
} from 'react-components';

import { useAppController } from '../../hooks/use-app-controller';
import { useCreateTaskFormData } from '../../hooks/use-create-task-form';
import { useTaskFormData } from '../../hooks/use-create-task-form';
import { useRmfApi } from '../../hooks/use-rmf-api';
import { useTaskRegistry } from '../../hooks/use-task-registry';
import { useUserProfile } from '../../hooks/use-user-profile';
Expand Down Expand Up @@ -72,7 +72,7 @@ export const TaskSchedule = () => {
const { showAlert } = useAppController();

const { waypointNames, pickupPoints, dropoffPoints, cleaningZoneNames, fleets } =
useCreateTaskFormData(rmfApi);
useTaskFormData(rmfApi);
const username = useUserProfile().user.username;
const taskRegistry = useTaskRegistry();
const [eventScope, setEventScope] = React.useState<string>(EventScopes.CURRENT);
Expand Down Expand Up @@ -191,7 +191,7 @@ export const TaskSchedule = () => {
);
};

const dispatchTaskCallback = React.useCallback<Required<CreateTaskFormProps>['onDispatchTask']>(
const dispatchTaskCallback = React.useCallback<Required<TaskFormProps>['onDispatchTask']>(
async (taskRequest, robotDispatchTarget) => {
if (!rmfApi) {
throw new Error('tasks api not available');
Expand All @@ -203,7 +203,7 @@ export const TaskSchedule = () => {
);

const editScheduledTaskCallback = React.useCallback<
Required<CreateTaskFormProps>['onScheduleTask']
Required<TaskFormProps>['onEditScheduleTask']
>(
async (taskRequest, schedule) => {
if (!rmfApi) {
Expand All @@ -220,6 +220,9 @@ export const TaskSchedule = () => {
`Editing schedule id [${currentScheduleTask.id}] with new schedule: ${schedule}`,
);
await editScheduledTaskSchedule(rmfApi, taskRequest, schedule, currentScheduleTask.id);

setEventScope(EventScopes.CURRENT);
AppEvents.refreshTaskSchedule.next();
return;
}

Expand Down Expand Up @@ -334,7 +337,7 @@ export const TaskSchedule = () => {
onSelectedDateChange={setSelectedDate}
/>
{openCreateTaskForm && (
<CreateTaskForm
<TaskForm
user={username ? username : 'unknown user'}
fleets={fleets}
tasksToDisplay={taskRegistry.taskDefinitions}
Expand All @@ -343,15 +346,16 @@ export const TaskSchedule = () => {
pickupPoints={pickupPoints}
dropoffPoints={dropoffPoints}
open={openCreateTaskForm}
scheduleToEdit={scheduleToEdit}
requestTask={currentScheduleTask?.task_request}
schedule={scheduleToEdit}
taskRequest={currentScheduleTask?.task_request}
onClose={() => {
setOpenCreateTaskForm(false);
setEventScope(EventScopes.CURRENT);
AppEvents.refreshTaskSchedule.next();
}}
onDispatchTask={dispatchTaskCallback}
onScheduleTask={editScheduledTaskCallback}
onScheduleTask={undefined}
onEditScheduleTask={editScheduledTaskCallback}
onSuccess={() => {
setOpenCreateTaskForm(false);
showAlert('success', 'Successfully created task');
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/hooks/use-create-task-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Subscription } from 'rxjs';

import { RmfApi } from '../services/rmf-api';

export const useCreateTaskFormData = (rmfApi: RmfApi | undefined) => {
export const useTaskFormData = (rmfApi: RmfApi | undefined) => {
const [waypointNames, setWaypointNames] = React.useState<string[]>([]);
const [cleaningZoneNames, setCleaningZoneNames] = React.useState<string[]>([]);
const [pickupPoints, setPickupPoints] = React.useState<Record<string, string>>({});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/lib/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './booking-label';
export * from './create-task';
export * from './task-booking-label-utils';
export * from './task-form';
export * from './task-info';
export * from './task-logs';
export * from './task-schedule-event-edit-delete-popup';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Meta, StoryObj } from '@storybook/react';

import { CreateTaskForm } from './create-task';
import { TaskForm } from './task-form';

export default {
title: 'Tasks/Create Task',
component: CreateTaskForm,
component: TaskForm,
} satisfies Meta;

type Story = StoryObj<typeof CreateTaskForm>;
type Story = StoryObj<typeof TaskForm>;

export const CreateTask: Story = {
export const OpenTaskForm: Story = {
args: {
onDispatchTask: async () => new Promise((res) => setTimeout(res, 500)),
onScheduleTask: async () => new Promise((res) => setTimeout(res, 500)),
Expand All @@ -19,6 +19,6 @@ export const CreateTask: Story = {
dropoffPoints: { test_waypoint_1: 'test_waypoint_1' },
},
render: (args) => {
return <CreateTaskForm {...args} open></CreateTaskForm>;
return <TaskForm {...args} open></TaskForm>;
},
};
Loading
Loading