Skip to content

Commit

Permalink
Hammer/demo tasks (#925)
Browse files Browse the repository at this point in the history
* Moved custom deliveries to separate file naively and import naively

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Moved patrol

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Moved custom-compose

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Added clean and delivery

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Added delivery, renamed to SimpleDelivery

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Clean task added

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Moved delivery-custom tests, added return type for forms

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Configurable supported tasks and name remapping

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Changed directory to types, since it doesn't just handle descriptions

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Fix test imports

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Using temporary task definition

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Refactoring new rename changes

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Clean up

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Removed problematic and unsused component and test

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Lint

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Updating pnpm version in github workflow

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Reverting update to pnpm version

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Fix build now that we use key value strings for labels

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Refactored last parts of hard coding categories and rendering forms

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Refactor callback names and error handling for misconfigs

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Display error as well

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Fixed more checks and failures

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Split configuration and definition, only handle configurations in resource manager level

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Lint

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Not using object as a type

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Address feedback

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Render using validTasks instead

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Use useMemo

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Jun 26, 2024
1 parent d2e56f3 commit 105628b
Show file tree
Hide file tree
Showing 20 changed files with 2,049 additions and 1,300 deletions.
2 changes: 2 additions & 0 deletions packages/dashboard/src/components/appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
const location = useLocation();
const tabValue = React.useMemo(() => locationToTabValue(location.pathname), [location]);
const logoResourcesContext = React.useContext(ResourcesContext)?.logos;
const taskResourcesContext = React.useContext(ResourcesContext)?.tasks;
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null);
const { authenticator } = React.useContext(AppConfigContext);
const profile = React.useContext(UserProfileContext);
Expand Down Expand Up @@ -617,6 +618,7 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
{openCreateTaskForm && (
<CreateTaskForm
user={username ? username : 'unknown user'}
tasksToDisplay={taskResourcesContext?.tasks}
patrolWaypoints={waypointNames}
cleaningZones={cleaningZoneNames}
pickupZones={resourceManager?.pickupZones}
Expand Down
31 changes: 28 additions & 3 deletions packages/dashboard/src/components/tasks/task-schedule-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import {
nextWednesday,
startOfMinute,
} from 'date-fns';
import { getShortDescription, RecurringDays, Schedule } from 'react-components';
import {
getShortDescription,
getTaskBookingLabelFromTaskRequest,
RecurringDays,
Schedule,
TaskDefinition,
} from 'react-components';

/**
* Generates a list of ProcessedEvents to occur within the query start and end,
Expand Down Expand Up @@ -166,8 +172,27 @@ export const apiScheduleToSchedule = (scheduleTask: ApiSchedule[]): Schedule =>
};
};

export const getScheduledTaskTitle = (task: ScheduledTask): string => {
const shortDescription = getShortDescription(task.task_request);
export const getScheduledTaskTitle = (
task: ScheduledTask,
supportedTasks?: TaskDefinition[],
): string => {
const taskBookingLabel = getTaskBookingLabelFromTaskRequest(task.task_request);

let remappedTaskName: string | undefined = undefined;
if (
supportedTasks &&
taskBookingLabel &&
taskBookingLabel.description.task_definition_id &&
typeof taskBookingLabel.description.task_definition_id === 'string'
) {
for (const s of supportedTasks) {
if (s.taskDefinitionId === taskBookingLabel.description.task_definition_id) {
remappedTaskName = s.taskDisplayName;
}
}
}

const shortDescription = getShortDescription(task.task_request, remappedTaskName);
if (!task.task_request || !task.task_request.category || !shortDescription) {
return `[${task.id}] Unknown`;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/dashboard/src/components/tasks/task-schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from 'react-components';
import { useCreateTaskFormData } from '../../hooks/useCreateTaskForm';
import useGetUsername from '../../hooks/useFetchUser';
import { AppControllerContext } from '../app-contexts';
import { AppControllerContext, ResourcesContext } from '../app-contexts';
import { UserProfileContext } from 'rmf-auth';
import { AppEvents } from '../app-events';
import { RmfAppContext } from '../rmf-app';
Expand Down Expand Up @@ -69,6 +69,7 @@ const disablingCellsWithoutEvents = (

export const TaskSchedule = () => {
const rmf = React.useContext(RmfAppContext);
const taskResourcesContext = React.useContext(ResourcesContext)?.tasks;
const { showAlert } = React.useContext(AppControllerContext);
const profile = React.useContext(UserProfileContext);

Expand Down Expand Up @@ -136,7 +137,7 @@ export const TaskSchedule = () => {
return tasks.flatMap((t: ScheduledTask) =>
t.schedules.flatMap<ProcessedEvent>((s: ApiSchedule) => {
const events = scheduleToEvents(params.start, params.end, s, t, getEventId, () =>
getScheduledTaskTitle(t),
getScheduledTaskTitle(t, taskResourcesContext?.tasks),
);
events.forEach((ev) => {
eventsMap.current[Number(ev.event_id)] = t;
Expand All @@ -146,7 +147,7 @@ export const TaskSchedule = () => {
}),
);
},
[rmf],
[rmf, taskResourcesContext],
);

const CustomCalendarEditor = ({ scheduler, value, onChange }: CustomCalendarEditorProps) => {
Expand Down Expand Up @@ -319,6 +320,7 @@ export const TaskSchedule = () => {
{openCreateTaskForm && (
<CreateTaskForm
user={username ? username : 'unknown user'}
tasksToDisplay={taskResourcesContext?.tasks}
patrolWaypoints={waypointNames}
cleaningZones={cleaningZoneNames}
pickupPoints={pickupPoints}
Expand Down
32 changes: 32 additions & 0 deletions packages/dashboard/src/managers/resource-manager-tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getDefaultTaskDefinition, TaskDefinition } from 'react-components';

export interface TaskResource {
task_definition_id: string;
display_name?: string;
}

export class TaskResourceManager {
tasks: TaskDefinition[];

constructor(taskResources: TaskResource[]) {
this.tasks = [];
for (const taskResource of taskResources) {
const defaultTaskDefinition = getDefaultTaskDefinition(taskResource.task_definition_id);
if (!defaultTaskDefinition) {
console.error(
`Invalid tasks configured for dashboard: [${taskResource.task_definition_id}]`,
);
continue;
}

if (taskResource.display_name !== undefined) {
this.tasks.push({
...defaultTaskDefinition,
taskDisplayName: taskResource.display_name,
});
} else {
this.tasks.push(defaultTaskDefinition);
}
}
}
}
19 changes: 19 additions & 0 deletions packages/dashboard/src/managers/resource-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Debug from 'debug';
import { DispenserResourceManager, RawDispenserResource } from './resource-manager-dispensers';
import { LogoResource, LogoResourceManager } from './resource-manager-logos';
import { RobotResource, RobotResourceManager } from './resource-manager-robots';
import { TaskResource, TaskResourceManager } from './resource-manager-tasks';

const debug = Debug('ResourceManager');
const ResourceFile = 'resources/main.json';
Expand All @@ -18,6 +19,7 @@ export interface ResourceConfigurationsType {
attributionPrefix?: string;
cartIds?: string[];
loggedInDisplayLevel?: string;
allowedTasks?: TaskResource[];
}

export default class ResourceManager {
Expand All @@ -32,6 +34,7 @@ export default class ResourceManager {
attributionPrefix?: string;
cartIds?: string[];
loggedInDisplayLevel?: string;
tasks: TaskResourceManager;

/**
* Gets the default resource manager using the embedded resource file (aka "assets/resources/main.json").
Expand All @@ -53,6 +56,22 @@ export default class ResourceManager {
constructor(resources: ResourceConfigurationsType) {
this.robots = new RobotResourceManager(resources.robots || {});
this.logos = new LogoResourceManager(resources.logos || {});
this.tasks = new TaskResourceManager(
resources.allowedTasks || [
{
task_definition_id: 'patrol',
},
{
task_definition_id: 'delivery',
},
{
task_definition_id: 'compose-clean',
},
{
task_definition_id: 'custom_compose',
},
],
);
if (resources.dispensers) {
this.dispensers = new DispenserResourceManager(resources.dispensers);
}
Expand Down
1 change: 0 additions & 1 deletion packages/react-components/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export * from './map';
export * from './navigation-bar';
export * from './place';
export * from './robots';
export * from './simple-filter';
export * from './simple-info';
export * from './spotlight-accordion';
export * from './stack-navigator';
Expand Down
16 changes: 0 additions & 16 deletions packages/react-components/lib/simple-filter.spec.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions packages/react-components/lib/simple-filter.stories.tsx

This file was deleted.

49 changes: 0 additions & 49 deletions packages/react-components/lib/simple-filter.tsx

This file was deleted.

Loading

0 comments on commit 105628b

Please sign in to comment.