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

Add dependsOn to the ENUM-type inputs to allow one input to depend on the chosen value from another input #3610

Open
anna-geller opened this issue Apr 24, 2024 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@anna-geller
Copy link
Member

Feature description

Dynamic inputs help manage complex use cases where one input may depend on the chosen value from another input. 

Example

Imagine that you want your end user to select the cloud provider first. Then, based on the chosen cloud provider, you want to show the services available for that cloud provider. The new dependsOn attribute in all ENUM-type inputs helps accomplish that:

inputs:
  - id: cloud
    type: ENUM
    values:
      - AWS
      - GCP
      - AZURE

  - id: services
    type: ENUM
    dependsOn: cloud
    values:
      AWS:
        - S3
        - EC2
        - RDS
      GCP:
        - GKE
        - GCS
        - BigQuery
      AZURE:
        - Azure VM
        - Azure Blob Storage
        - Azure SQL Database

The services input will be dynamically rendered based on the chosen cloud provider.

UI behavior

When you execute this flow, the services input will be disabled until you select a value for the cloud input.

Once you select a value for the cloud input, the services input will show only the services available for the selected cloud provider. This dynamic rendering of dependent inputs allows you to select the correct service matching the previously chosen cloud provider.

Backend behavior

Under the hood, Kestra will use a JSON schema with oneOf in the backend:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "cloud": {
      "type": "string",
      "enum": ["AWS", "GCP", "AZURE"]
    },
    "services": {
      "type": "string",
      "enum": ["S3", "EC2", "RDS", "GKE", "GCS", "BigQuery", "Azure VM", "Azure Blob Storage", "Azure SQL Database"]
    }
  },
  "dependencies": {
    "cloud": {
      "oneOf": [
        {
          "properties": {
            "cloud": { "const": "AWS" },
            "services": {
              "type": "string",
              "enum": ["S3", "EC2", "RDS"]
            }
          }
        },
        {
          "properties": {
            "cloud": { "const": "GCP" },
            "services": {
              "type": "string",
              "enum": ["GKE", "GCS", "BigQuery"]
            }
          }
        },
        {
          "properties": {
            "cloud": { "const": "AZURE" },
            "services": {
              "type": "string",
              "enum": ["Azure VM", "Azure Blob Storage", "Azure SQL Database"]
            }
          }
        }
      ]
    }
  }
}

Fetching ENUM values from KV Store

Once we add the KV Store, you can also fetch these values dynamically (related issue #283).

Imagine that the ENUM values are dynamic and need to be fetched from some external source like a database or file. You can create a flow that will regularly update the value for a given key. Then, you can reference that value by key in your dynamic input:

id: myflow
namespace: dev
inputs:
  - id: cloud
    type: ENUM
    values: "{{ kv('CLOUD') }}" 

  - id: services
    type: ENUM
    dependsOn: cloud
    values: "{{ kv('SERVICES') }}"
@anna-geller anna-geller added the enhancement New feature or request label Apr 24, 2024
@anna-geller anna-geller added this to the v0.18.0 milestone Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant