Skip to content

Commit

Permalink
Add secrets handling in UI (#1313)
Browse files Browse the repository at this point in the history
* Add secrets handling in UI

* Clear password input after getting from server
  • Loading branch information
jamakase authored Dec 18, 2020
1 parent 5532aa3 commit 4f4ff5f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ const PropertyField: React.FC<IProps> = ({ property }) => {
/>
);
} else {
const inputType = property.isSecret
? "password"
: property.type === "integer"
? "number"
: "text";

const onKeyDown = (key: React.KeyboardEvent) => {
key.preventDefault();
form.setValue(key.key);
};

return (
<LabeledInput
{...field}
Expand All @@ -102,8 +113,13 @@ const PropertyField: React.FC<IProps> = ({ property }) => {
label={label}
message={constructMessage}
placeholder={placeholder}
type={property.type === "integer" ? "number" : "text"}
type={inputType}
value={field.value || property.default || ""}
onKeyDown={
inputType === "password" && field.value === meta.initialValue
? (key: React.KeyboardEvent) => onKeyDown(key)
: undefined
}
/>
);
}
Expand Down
7 changes: 4 additions & 3 deletions airbyte-webapp/src/core/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ export type FormBaseItem = {
fieldKey: string;
fieldName: string;
isRequired: boolean;
meta?: { [key: string]: any };
isSecret?: boolean;
title?: string;
meta?: { [key: string]: any };
} & Partial<JSONSchema7>;

type FormGroupItem = {
_type: "formGroup";
fieldName: string;
fieldKey: string;
isRequired: boolean;
title?: string;
properties: FormBlock[];
isLoading?: boolean;
title?: string;
description?: string;
default?: JSONSchema7Type;
examples?: JSONSchema7Type;
};

type FormConditionItem = {
_type: "formCondition";
title?: string;
fieldName: string;
fieldKey: string;
isRequired: boolean;
title?: string;
conditions: { [key: string]: FormGroupItem | FormBaseItem };
};

Expand Down
4 changes: 3 additions & 1 deletion airbyte-webapp/src/core/jsonSchema/schemaToUiWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ test("should reformat jsonSchema to internal widget representation", () => {
},
dbname: { type: "string", description: "Name of the database." },
password: {
airbyte_secret: true,
type: "string",
description: "Password associated with the username."
}
} as any // Because airbyte_secret is not part of json_schema
}
};

Expand Down Expand Up @@ -70,6 +71,7 @@ test("should reformat jsonSchema to internal widget representation", () => {
fieldName: "key.password",
fieldKey: "password",
isRequired: false,
isSecret: true,
type: "string"
}
]
Expand Down
4 changes: 3 additions & 1 deletion airbyte-webapp/src/core/jsonSchema/schemaToUiWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const jsonSchemaToUiWidget = (
fieldName: key,
fieldKey: key,
type: "null",
isRequired
isRequired,
isSecret: false
};
}

Expand Down Expand Up @@ -78,6 +79,7 @@ export const jsonSchemaToUiWidget = (
fieldName: path || key,
fieldKey: key,
isRequired,
isSecret: (jsonSchema as { airbyte_secret: boolean }).airbyte_secret,
type:
(Array.isArray(jsonSchema.type) ? jsonSchema.type[0] : jsonSchema.type) ??
"null"
Expand Down

0 comments on commit 4f4ff5f

Please sign in to comment.