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

Hammer/demo tasks #925

Merged
merged 32 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
11f27ab
Moved custom deliveries to separate file naively and import naively
aaronchongth Mar 26, 2024
6eae244
Moved patrol
aaronchongth Mar 27, 2024
9bda508
Moved custom-compose
aaronchongth Mar 27, 2024
e0d07f8
Added clean and delivery
aaronchongth Mar 27, 2024
9947d87
Added delivery, renamed to SimpleDelivery
aaronchongth Mar 27, 2024
c780d63
Clean task added
aaronchongth Mar 27, 2024
ec851b7
Moved delivery-custom tests, added return type for forms
aaronchongth Mar 27, 2024
25fe0f3
Configurable supported tasks and name remapping
aaronchongth Mar 28, 2024
b5a8b76
Changed directory to types, since it doesn't just handle descriptions
aaronchongth Mar 28, 2024
2c52928
Fix test imports
aaronchongth Mar 28, 2024
eb9aeda
Using temporary task definition
aaronchongth Apr 2, 2024
ebd5f19
Merge branch 'deploy/hammer' into hammer/demo-tasks
aaronchongth Jun 3, 2024
01139aa
Refactoring new rename changes
aaronchongth Jun 3, 2024
1069946
Clean up
aaronchongth Jun 4, 2024
1edb5e9
Removed problematic and unsused component and test
aaronchongth Jun 4, 2024
d51646e
Lint
aaronchongth Jun 6, 2024
963ec12
Merge branch 'deploy/hammer' into hammer/demo-tasks
aaronchongth Jun 6, 2024
1901697
Updating pnpm version in github workflow
aaronchongth Jun 6, 2024
a1d3140
Reverting update to pnpm version
aaronchongth Jun 6, 2024
114631e
Fix build now that we use key value strings for labels
aaronchongth Jun 6, 2024
c421aa3
Refactored last parts of hard coding categories and rendering forms
aaronchongth Jun 6, 2024
5b102cb
Merge branch 'deploy/hammer' into hammer/demo-tasks
aaronchongth Jun 12, 2024
bce846f
Refactor callback names and error handling for misconfigs
aaronchongth Jun 19, 2024
bde2649
Display error as well
aaronchongth Jun 19, 2024
d452aff
Fixed more checks and failures
aaronchongth Jun 19, 2024
7f7eb62
Split configuration and definition, only handle configurations in res…
aaronchongth Jun 19, 2024
3573c59
Lint
aaronchongth Jun 19, 2024
2f3a1a7
Not using object as a type
aaronchongth Jun 19, 2024
ba6be30
Address feedback
aaronchongth Jun 25, 2024
0e803cb
Render using validTasks instead
aaronchongth Jun 25, 2024
f2c0b08
Use useMemo
aaronchongth Jun 25, 2024
ce58404
Merge branch 'deploy/hammer' into hammer/demo-tasks
aaronchongth Jun 26, 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
3 changes: 2 additions & 1 deletion 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,7 +618,7 @@ export const AppBar = React.memo(({ extraToolbarItems }: AppBarProps): React.Rea
{openCreateTaskForm && (
<CreateTaskForm
user={username ? username : 'unknown user'}
supportedTasks={resourceManager?.supportedTasks}
tasksToDisplay={taskResourcesContext?.tasks}
patrolWaypoints={waypointNames}
cleaningZones={cleaningZoneNames}
pickupZones={resourceManager?.pickupZones}
Expand Down
19 changes: 16 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, TaskDefinition } 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 @@ -170,10 +176,17 @@ export const getScheduledTaskTitle = (
task: ScheduledTask,
supportedTasks?: TaskDefinition[],
): string => {
const taskBookingLabel = getTaskBookingLabelFromTaskRequest(task.task_request);

let remappedTaskName: string | undefined = undefined;
if (supportedTasks) {
if (
supportedTasks &&
taskBookingLabel &&
taskBookingLabel.description.task_definition_id &&
typeof taskBookingLabel.description.task_definition_id === 'string'
) {
for (const s of supportedTasks) {
if (s.taskDefinitionId === task.task_request.category) {
if (s.taskDefinitionId === taskBookingLabel.description.task_definition_id) {
remappedTaskName = s.taskDisplayName;
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/dashboard/src/components/tasks/task-schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const disablingCellsWithoutEvents = (

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

Expand Down Expand Up @@ -137,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, resourceManager?.supportedTasks),
getScheduledTaskTitle(t, taskResourcesContext?.tasks),
);
events.forEach((ev) => {
eventsMap.current[Number(ev.event_id)] = t;
Expand All @@ -147,7 +147,7 @@ export const TaskSchedule = () => {
}),
);
},
[rmf, resourceManager],
[rmf, taskResourcesContext],
);

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

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

export class TaskResourceManager {
supportedTasks: Record<string, TaskDefinition>;
tasks: TaskDefinition[];

constructor(supportedTasks: TaskDefinition[] | undefined) {
this.supportedTasks = {};
if (supportedTasks) {
for (const t of supportedTasks) {
this.supportedTasks[t.taskDefinitionId] = t;
constructor(taskResources: TaskResource[]) {
this.tasks = [];
for (const taskResource of taskResources) {
const definition = getTaskDefinition(taskResource.task_definition_id);
if (!definition) {
console.error(
`Invalid tasks configured for dashboard: [${taskResource.task_definition_id}]`,
);
continue;
}

if (taskResource.display_name !== undefined) {
definition.taskDisplayName = taskResource.display_name;
}
aaronchongth marked this conversation as resolved.
Show resolved Hide resolved

this.tasks.push(definition);
}
}
}
34 changes: 19 additions & 15 deletions packages/dashboard/src/managers/resource-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +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 {
DefaultPatrolTaskDefinition,
DefaultDeliveryTaskDefinition,
DefaultComposeCleanTaskDefinition,
TaskDefinition,
DefaultCustomComposeTaskDefinition,
} from 'react-components';
import { TaskResource, TaskResourceManager } from './resource-manager-tasks';

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

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

/**
* Gets the default resource manager using the embedded resource file (aka "assets/resources/main.json").
Expand All @@ -62,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 All @@ -80,12 +90,6 @@ export default class ResourceManager {
this.attributionPrefix = resources.attributionPrefix || 'OSRC-SG';
this.cartIds = resources.cartIds || [];
this.loggedInDisplayLevel = resources.loggedInDisplayLevel;
this.supportedTasks = resources.supportedTasks || [
DefaultPatrolTaskDefinition,
DefaultDeliveryTaskDefinition,
DefaultComposeCleanTaskDefinition,
DefaultCustomComposeTaskDefinition,
];
}
}

Expand Down
Loading
Loading