microsoft / AzureTRE

An accelerator to help organizations build Trusted Research Environments on Azure.
https://microsoft.github.io/AzureTRE
MIT License
170 stars 134 forks source link

Support dynamic template properties #3899

Open m1p1h opened 3 months ago

m1p1h commented 3 months ago

I have a custom workspace template that (during initialisation via the TRE UI) requires a TRE admin to specify a string property value, that is an ID of a previously created TRE workspace . However, ideally I'd like to display a list of existing TRE workspace IDs in a dropdown, to avoid the user entering an ID of workspace that doesn't exist.

While it's possible to specify custom workspace template properties by including properties with an enum attribute to generate such a list of options. As far as I can tell its only possible to define an enum for a property statically in the template_schema.json file of the workspace template.

From looking at the code, one way to do this dynamically might be to define a property in template_schema.json that indicates that the property is dynamic and that the TRE UI app when rendering the workspace template form should make an additional API calls to populate the enum of the property with the relevant data e.g.

 "primary_workspace_id": {
      "type": "string",
      "title": "Primary Workspace Identifier",
      "description": "List of existing workspace IDs",
      "dynamic_enum": {
           "api_call":"api/workspaces",
           "property_name":"workspace_id"
      }
    }

I'm not a React developer but the rendering appears to happen here >> https://github.com/microsoft/AzureTRE/blob/de141651ad9fb9f58e7b78e383edf263eaa549d1/ui/app/src/components/shared/create-update-resource/ResourceForm.tsx#L31C2-L50C1

So once the chooen workspace template is returned from cosmosdb, the list of properties are processed and where a dynamic property is found an additional handler performs the nessasary API call to populate the enum before the form data is set. For my specific case I'm able to reuse the existing TRE API calls (i.e. api/workspaces) without modification.

Any thoughts on this or best approaches to supporting this feature in the TRE?

marrobi commented 3 months ago

The project use: https://github.com/rjsf-team/react-jsonschema-form/

Looks like others have had a similar need, and might be a valid implementation at the bottom of the page:

https://github.com/rjsf-team/react-jsonschema-form/issues/809

Would be good to have a widget like this in the Azure TRE code base to enable dynamic enum fields. We have had an ask to enable workspaces to deployed to different subscriptions, would be a similar use case.

Also worth noting we are on RJSF v4, might be worth upgrading to v5 before the work.