From 0f4897d0621309b3bb09b65f9f67110026b4cf75 Mon Sep 17 00:00:00 2001 From: Teo Koon Peng Date: Thu, 5 Sep 2024 01:58:37 +0000 Subject: [PATCH] fix after rebase Signed-off-by: Teo Koon Peng --- .../src/components/tasks/utils.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/rmf-dashboard-framework/src/components/tasks/utils.ts b/packages/rmf-dashboard-framework/src/components/tasks/utils.ts index 2a16e4c3b..d9694b094 100644 --- a/packages/rmf-dashboard-framework/src/components/tasks/utils.ts +++ b/packages/rmf-dashboard-framework/src/components/tasks/utils.ts @@ -1,4 +1,9 @@ -import { PostScheduledTaskRequest, TaskRequest, TaskStateOutput as TaskState } from 'api-client'; +import { + PostScheduledTaskRequest, + Priority, + TaskRequest, + TaskStateOutput as TaskState, +} from 'api-client'; import { Schedule } from './create-task'; import { getTaskBookingLabelFromTaskState } from './task-booking-label-utils'; @@ -117,3 +122,26 @@ export const toApiSchedule = ( schedules: apiSchedules, }; }; + +export function createTaskPriority(prioritize: boolean): Priority { + return { type: 'binary', value: prioritize ? 1 : 0 }; +} + +// FIXME(ac): This method of parsing is crude, and will be fixed using schemas +// when we migrate to jsonforms. +export function parseTaskPriority(priority: Priority | null | undefined): boolean { + if (!priority) { + return false; + } + + if ( + typeof priority == 'object' && + 'type' in priority && + priority['type'] === 'binary' && + 'value' in priority && + typeof priority['value'] == 'number' + ) { + return (priority['value'] as number) > 0; + } + return false; +}