appEnvs should support enum dropdown (#532)

This commit is contained in:
Hoan Luu Huu
2025-06-02 18:41:18 +07:00
committed by GitHub
parent 03e52e3dc5
commit 4a293ae7da
2 changed files with 22 additions and 1 deletions

View File

@@ -810,6 +810,7 @@ export interface AppEnvProperty {
default?: string | number | boolean; default?: string | number | boolean;
obscure?: boolean; obscure?: boolean;
uiHint?: "input" | "textarea" | "filepicker"; uiHint?: "input" | "textarea" | "filepicker";
enum?: string[];
} }
export interface AppEnv { export interface AppEnv {

View File

@@ -845,7 +845,9 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => {
? String(defaultValue) ? String(defaultValue)
: "", : "",
onChange: ( onChange: (
e: React.ChangeEvent<HTMLInputElement>, e: React.ChangeEvent<
HTMLInputElement | HTMLSelectElement
>,
) => { ) => {
// Convert to proper type based on schema // Convert to proper type based on schema
let newValue; let newValue;
@@ -870,6 +872,11 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => {
type: isNumber ? "number" : "text", type: isNumber ? "number" : "text",
}; };
const isDropdown =
webhook.webhookEnv![key].type === "string" &&
(webhook.webhookEnv![key].enum?.length || 0) >
0;
const textAreaSpecificProps = { const textAreaSpecificProps = {
rows: 6, rows: 6,
cols: 61, cols: 61,
@@ -880,6 +887,19 @@ export const ApplicationForm = ({ application }: ApplicationFormProps) => {
.obscure .obscure
? ObscureInput ? ObscureInput
: webhook.webhookEnv![key].uiHint || "input"; : webhook.webhookEnv![key].uiHint || "input";
if (isDropdown) {
return (
<Selector
{...commonProps}
options={webhook.webhookEnv![
key
].enum!.map((option) => ({
name: option,
value: option,
}))}
/>
);
}
if (componentType === "filepicker") { if (componentType === "filepicker") {
return ( return (
<> <>