Skip to content

Commit

Permalink
feat(core): create SELECT input and deprecate ENUM
Browse files Browse the repository at this point in the history
close #4063
  • Loading branch information
Skraye committed Jul 22, 2024
1 parent 4f15ebb commit 7cb41fb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/io/kestra/core/models/flows/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@JsonSubTypes.Type(value = SecretInput.class, name = "SECRET"),
@JsonSubTypes.Type(value = StringInput.class, name = "STRING"),
@JsonSubTypes.Type(value = EnumInput.class, name = "ENUM"),
@JsonSubTypes.Type(value = SelectInput.class, name = "SELECT"),
@JsonSubTypes.Type(value = TimeInput.class, name = "TIME"),
@JsonSubTypes.Type(value = URIInput.class, name = "URI"),
@JsonSubTypes.Type(value = MultiselectInput.class, name = "MULTISELECT")
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/io/kestra/core/models/flows/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public enum Type {
STRING(StringInput.class.getName()),
ENUM(EnumInput.class.getName()),
SELECT(SelectInput.class.getName()),
INT(IntInput.class.getName()),
FLOAT(FloatInput.class.getName()),
BOOLEAN(BooleanInput.class.getName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
@SuperBuilder
@Getter
@NoArgsConstructor
@Deprecated
public class EnumInput extends Input<String> {
@Schema(
title = "List of values."
title = "List of values.",
description = "DEPRECATED; use 'SELECT' instead."
)
@NotNull
List<@Regex String> values;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.kestra.core.models.flows.input;

import io.kestra.core.models.flows.Input;
import io.kestra.core.models.validations.ManualConstraintViolation;
import io.kestra.core.validations.Regex;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;

@SuperBuilder
@Getter
@NoArgsConstructor
public class SelectInput extends Input<String> {
@Schema(
title = "List of values."
)
@NotNull
List<@Regex String> values;

@Override
public void validate(String input) throws ConstraintViolationException {
if (!values.contains(input) & this.getRequired()) {
throw ManualConstraintViolation.toConstraintViolationException(
"it must match the values `" + values + "`",
this,
SelectInput.class,
getId(),
input
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private Optional<AbstractMap.SimpleEntry<String, Object>> parseData(
private Object parseType(Execution execution, Type type, String id, Type elementType, Object current) throws Exception {
try {
return switch (type) {
case ENUM, STRING -> current;
case SELECT, ENUM, STRING -> current;
case SECRET -> {
if (secretKey == null) {
throw new Exception("Unable to use a `SECRET` input/output as encryption is not configured");
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/inputs/InputsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:full-height="false"
:input="true"
:navbar="false"
v-if="input.type === 'ENUM'"
v-if="input.type === 'ENUM' || input.type === 'SELECT'"
v-model="inputs[input.id]"
@update:model-value="onChange"
>
Expand Down

0 comments on commit 7cb41fb

Please sign in to comment.