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 SELECT/MULTISELECT-type inputs to allow one input to depend on the chosen value from another input #3610

Closed
Tracked by #4656
anna-geller opened this issue Apr 24, 2024 · 0 comments · Fixed by #4972
Assignees
Labels
enhancement New feature or request kind/customer-request Requested by one or more customers

Comments

@anna-geller
Copy link
Member

anna-geller commented Apr 24, 2024

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 SELECT-type inputs helps accomplish that:

inputs:
  - id: cloud
    type: SELECT
    defaults: AWS
    values:
      - AWS
      - GCP
      - AZURE

  - id: services
    type: SELECT
    dependsOn:
     inputs: cloud
     condition: "{{ inputs.cloud == 'AWS' }}" # catch exception if not defined
    values: "{{ kv('SERVICE')[inputs.cloud] }}"

  - id: services2
    type: SELECT
    condition: "{{ inputs.cloud == 'AWS' }}" # catch exception if not defined
    values:
      - S3
      - EC2
      - RDS

  - id: services3
    type: SELECT
    condition: "{{ inputs.cloud == 'GCP' }}" # catch exception if not defined
    values:
      - GKE
      - GCS
      - BigQuery

  - id: services4
    type: SELECT
    condition: "{{ inputs.cloud == 'AZURE' }}" # catch exception if not defined
    values:
      - 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 SELECTed values from KV Store

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

Imagine that the SELECT 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: SELECT
    values: "{{ kv('CLOUD') }}" 

  - id: services
    type: SELECT
    dependsOn: cloud
    values: "{{ kv('SERVICES') }}"

Using keys:

id: myflow
namespace: dev
inputs:
  - id: cloud
    type: SELECT
    values: "{{ kv('SERVICES') | keys }}" 

  - id: services
    type: SELECT
    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
@anna-geller anna-geller removed this from the v0.18.0 milestone Jul 23, 2024
@anna-geller anna-geller changed the title Add dependsOn to the ENUM-type inputs to allow one input to depend on the chosen value from another input Add dependsOn to the SELECT/MULTISELECT-type inputs to allow one input to depend on the chosen value from another input Aug 12, 2024
@anna-geller anna-geller added the kind/highlight One of the highlights of the upcoming release label Aug 12, 2024
@anna-geller anna-geller added kind/customer-request Requested by one or more customers and removed kind/highlight One of the highlights of the upcoming release labels Aug 15, 2024
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 19, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 20, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 20, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
fhussonnois added a commit that referenced this issue Sep 20, 2024
This commits adds:
- support for dependsOn field in flow's inputs
- support for expression on input of type SELECT, MULTISELECT
- new REST API to validate inputs for an execution
- some code cleanup, and method renaming

Fix: #3610
@anna-geller anna-geller added kind/highlight One of the highlights of the upcoming release and removed kind/highlight One of the highlights of the upcoming release labels Sep 22, 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 kind/customer-request Requested by one or more customers
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants