-
Notifications
You must be signed in to change notification settings - Fork 22
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
Widgets: add support for Widget discovery from BlueOS #1499
base: master
Are you sure you want to change the base?
Widgets: add support for Widget discovery from BlueOS #1499
Conversation
requires bluerobotics/BlueOS#3028 |
6bcdf0c
to
ee714b6
Compare
|
dcfe920
to
37fdcc2
Compare
37fdcc2
to
31e4c49
Compare
31e4c49
to
4533efd
Compare
// first we gather all the extra jsons with the cockpit key | ||
const extraWidgets = await services.reduce( | ||
async (accPromise: Promise<BlueOsWidget[]>, service: Record<string, any>) => { | ||
const acc = await accPromise | ||
const worksInRelativePaths = service.metadata?.works_in_relative_paths | ||
if (service.metadata?.extras?.cockpit === undefined) { | ||
return acc | ||
} | ||
const baseUrl = worksInRelativePaths | ||
? `http://${vehicleStore.globalAddress}/extensionv2/${service.metadata.sanitized_name}` | ||
: `http://${vehicleStore.globalAddress}:${service.port}` | ||
const fullUrl = baseUrl + service.metadata?.extras?.cockpit | ||
|
||
const extraJson: ExtrasJson = await ky.get(fullUrl, options).json() | ||
const widgets: BlueOsWidget[] = extraJson.widgets.map((widget) => { | ||
return { | ||
...widget, | ||
iframe_url: baseUrl + widget.iframe_url, | ||
iframe_icon: baseUrl + widget.iframe_icon, | ||
} | ||
}) | ||
return acc.concat(widgets) | ||
}, | ||
Promise.resolve([] as BlueOsWidget[]) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this filtering code could live on the backend under an endpoint like get_extras(key: string) -> HttpResponse([json])
and the Cockpit would ask for the key "Cockpit".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides the overall naming suggestions, I just need to be able to test this PR.
/** | ||
* Widget configuration object as received from BlueOS | ||
*/ | ||
export interface BlueOsWidget { | ||
/** | ||
* Name of the widget, this is displayed on edit mode widget browser | ||
*/ | ||
name: string | ||
/** | ||
* The URL at which the widget is located | ||
* This is expected to be an absolute url | ||
*/ | ||
iframe_url: string | ||
|
||
/** | ||
* The icon of the widget, this is displayed on the widget browser | ||
*/ | ||
iframe_icon: string | ||
} | ||
|
||
/** | ||
* Widget type on steroids. This is the WidgetType with added Custom name and options | ||
*/ | ||
export interface ExtendedWidget { | ||
/** | ||
* Widget type | ||
*/ | ||
component: WidgetType | ||
/** | ||
* Widget name, this will be displayed on edit mode | ||
*/ | ||
name: string | ||
/** | ||
* Widget options, this is the configuration that will be passed to the widget when it is created | ||
*/ | ||
options: Record<string, unknown> | ||
/** | ||
* Widget icon, this is the icon that will be displayed on the widget browser | ||
*/ | ||
icon: string | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sugestion: to have a "BaseWidget" class, with just the name, and those two extend from it. Also, instead of "ExtendedWidget", I think "InternalWidget" would make it more clear what we are talking about.
Edit: actually, shouldn't we inherit from the "Widget" type? Maybe restrict it a little bit so the BlueOsWidget works fine?
const availableWidgetTypes = computed(() => | ||
Object.values(WidgetType).map((widgetType) => { | ||
return { | ||
component: widgetType, | ||
name: widgetType, | ||
icon: widgetImages[widgetType] as string, | ||
options: {}, | ||
} | ||
}) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are now returning "Widgets", and now "WidgetTypes" anymore, this computed should be renamed to "availableInternalWidgets".
Edit:
Current discovery method:
A new field "extras" is added to /register_service:
/cockpit_extras.json looks like this:
The consumer (in this case cockpit), should validate the file target_system and integration api version (in this case, cockpit's widget api). The rest of it is defined by the consumer.
In cockpit we need a name, an iframe url, and optionally an iframe for the configuration interface. The version can be used for (in)validating widget settings.