Skip to content

Commit

Permalink
dashboard: better json schema (#992)
Browse files Browse the repository at this point in the history
Signed-off-by: Teo Koon Peng <teokoonpeng@gmail.com>
  • Loading branch information
koonpeng authored Aug 12, 2024
1 parent 3a6c952 commit 0fdcc8a
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 31 deletions.
92 changes: 66 additions & 26 deletions packages/dashboard/app-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"BuildConfig": {
"description": "These will be injected at build time, they CANNOT be changed after the bundle is built.",
"properties": {
"adminTab": {
"description": "Whether the admin tab should be enabled, defaults to false.",
"type": "boolean"
},
"authProvider": {
Expand All @@ -14,9 +16,11 @@
"type": "string"
},
"baseUrl": {
"description": "The base url that the app is served from, this MUST end with a slash.",
"type": "string"
},
"customTabs": {
"description": "Whether custom tabs should be enabled, defaults to false.",
"type": "boolean"
}
},
Expand All @@ -26,6 +30,17 @@
],
"type": "object"
},
"FleetResource": {
"properties": {
"default": {
"$ref": "#/definitions/RobotResource"
}
},
"required": [
"default"
],
"type": "object"
},
"KeycloakAuthConfig": {
"properties": {
"clientId": {
Expand All @@ -48,6 +63,7 @@
"LogoResource": {
"properties": {
"header": {
"description": "Path to an image to be used as the logo on the app bar.",
"type": "string"
}
},
Expand All @@ -56,27 +72,13 @@
],
"type": "object"
},
"Record<\"default\",Resources>": {
"properties": {
"default": {
"$ref": "#/definitions/Resources"
}
},
"required": [
"default"
],
"type": "object"
},
"Record<string,FleetResource>": {
"type": "object"
},
"Record<string,Resources>": {
"type": "object"
},
"Resources": {
"properties": {
"fleets": {
"$ref": "#/definitions/Record<string,FleetResource>"
"additionalProperties": {
"$ref": "#/definitions/FleetResource"
},
"type": "object"
},
"logos": {
"$ref": "#/definitions/LogoResource"
Expand All @@ -88,15 +90,37 @@
],
"type": "object"
},
"RobotResource": {
"properties": {
"icon": {
"description": "Path to an image to be used as the robot's icon.",
"type": "string"
},
"scale": {
"description": "Scale of the image to match the robot's dimensions.",
"type": "number"
}
},
"type": "object"
},
"StubAuthConfig": {
"type": "object"
},
"TaskResource": {
"description": "Configuration for task definitions.",
"properties": {
"displayName": {
"description": "Configure the display name for the task definition.",
"type": "string"
},
"taskDefinitionId": {
"description": "The task definition to configure.",
"enum": [
"compose-clean",
"custom_compose",
"delivery",
"patrol"
],
"type": "string"
}
},
Expand All @@ -108,12 +132,14 @@
},
"properties": {
"allowedTasks": {
"description": "List of allowed tasks that can be requested",
"items": {
"$ref": "#/definitions/TaskResource"
},
"type": "array"
},
"attributionPrefix": {
"description": "Branding to be shown on the corner of the map.",
"type": "string"
},
"authConfig": {
Expand All @@ -124,7 +150,8 @@
{
"$ref": "#/definitions/KeycloakAuthConfig"
}
]
],
"description": "Config for the authentication provider."
},
"buildConfig": {
"$ref": "#/definitions/BuildConfig"
Expand All @@ -136,40 +163,53 @@
"type": "array"
},
"defaultMapLevel": {
"description": "The default level to be selected when the map is initially loaded.",
"type": "string"
},
"defaultRobotZoom": {
"description": "The default zoom level when a robot is focused on the map.",
"type": "number"
},
"defaultZoom": {
"description": "The default zoom level when the map is initially loaded.",
"type": "number"
},
"helpLink": {
"description": "Url to be linked for the \"help\" button.",
"type": "string"
},
"pickupZones": {
"description": "List of available pickup zones used for delivery tasks.",
"items": {
"type": "string"
},
"type": "array"
},
"reportIssue": {
"description": "Url to be linked for the \"report issue\" button.",
"type": "string"
},
"resources": {
"allOf": [
{
"$ref": "#/definitions/Record<string,Resources>"
},
{
"$ref": "#/definitions/Record<\"default\",Resources>"
"additionalProperties": {
"$ref": "#/definitions/Resources"
},
"description": "Set various resources (icons, logo etc) used. Different resource can be used based on the theme, `default` is always required.",
"properties": {
"default": {
"$ref": "#/definitions/Resources"
}
]
},
"required": [
"default"
],
"type": "object"
},
"rmfServerUrl": {
"description": "Url of the RMF api server.",
"type": "string"
},
"trajectoryServerUrl": {
"description": "Url of the RMF trajectory server.",
"type": "string"
}
},
Expand Down
99 changes: 94 additions & 5 deletions packages/dashboard/src/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,47 @@ import testConfig from '../app-config.json';
import { Authenticator, KeycloakAuthenticator, StubAuthenticator } from './auth';

export interface RobotResource {
/**
* Path to an image to be used as the robot's icon.
*/
icon?: string;

/**
* Scale of the image to match the robot's dimensions.
*/
scale?: number;
}

export interface FleetResource {
// TODO(koonpeng): configure robot resources based on robot model, this will require https://github.com/open-rmf/rmf_api_msgs/blob/main/rmf_api_msgs/schemas/robot_state.json to expose the robot model.
// [robotModel: string]: RobotResource;
default: RobotResource;
}

export interface LogoResource {
/**
* Path to an image to be used as the logo on the app bar.
*/
header: string;
}

export interface Resources {
fleets: Record<string, FleetResource>;
fleets: { [fleetName: string]: FleetResource };
logos: LogoResource;
}

/**
* Configuration for task definitions.
*/
export interface TaskResource {
taskDefinitionId: string;
/**
* The task definition to configure.
*/
taskDefinitionId: 'patrol' | 'delivery' | 'compose-clean' | 'custom_compose';

/**
* Configure the display name for the task definition.
*/
displayName?: string;
}

Expand All @@ -35,29 +57,96 @@ export interface KeycloakAuthConfig {
clientId: string;
}

/**
* These config are exposed as a global variable. They can be changed after the bundle is built.
* To do so, use a placeholder value like `__RMF_SERVER_URL__` and do a search and replace on
* `index.html` before serving it.
*/
export interface RuntimeConfig {
/**
* Url of the RMF api server.
*/
rmfServerUrl: string;

/**
* Url of the RMF trajectory server.
*/
trajectoryServerUrl: string;

/**
* Config for the authentication provider.
*/
authConfig: KeycloakAuthConfig | StubAuthConfig;

/**
* Url to be linked for the "help" button.
*/
helpLink: string;

/**
* Url to be linked for the "report issue" button.
*/
reportIssue: string;
pickupZones: string[];

/**
* List of available pickup zones used for delivery tasks.
*/
pickupZones: string[]; // FIXME(koonpeng): Should be part of task definition

/**
* The default zoom level when the map is initially loaded.
*/
defaultZoom: number;

/**
* The default zoom level when a robot is focused on the map.
*/
defaultRobotZoom: number;

/**
* Branding to be shown on the corner of the map.
*/
attributionPrefix: string;

/**
* The default level to be selected when the map is initially loaded.
*/
defaultMapLevel: string;

/**
* List of allowed tasks that can be requested
*/
allowedTasks: TaskResource[];
resources: Record<string, Resources> & Record<'default', Resources>;

/**
* Set various resources (icons, logo etc) used. Different resource can be used based on the theme, `default` is always required.
*/
resources: { [theme: string]: Resources; default: Resources };

// FIXME(koonpeng): this is used for very specific tasks, should be removed when mission
// system is implemented.
cartIds: string[];
}

// these will be injected as defines and potentially be tree shaken out
/**
* These will be injected at build time, they CANNOT be changed after the bundle is built.
*/
export interface BuildConfig {
/**
* The base url that the app is served from, this MUST end with a slash.
*/
baseUrl: string;

authProvider: 'keycloak' | 'stub';

/**
* Whether custom tabs should be enabled, defaults to false.
*/
customTabs?: boolean;

/**
* Whether the admin tab should be enabled, defaults to false.
*/
adminTab?: boolean;
}

Expand Down

0 comments on commit 0fdcc8a

Please sign in to comment.