Skip to content

Commit

Permalink
refactor: Set text input type to password if setting is secret (#153)
Browse files Browse the repository at this point in the history
* set input type to password if setting is secret

* set to password if setting is secret despite schema type
  • Loading branch information
hasore authored May 20, 2024
1 parent 93ef81f commit 9340507
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/renderer/components/form/form-widgets/hubaiTextWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ export default function HubaiTextWidget({
}: WidgetProps) {
let inputType = 'text'; // default to text input

if (schema.type === 'integer') {
inputType = 'number';
} else if (schema.type === 'number') {
inputType = 'text'; // Use text input to allow floating points, validate manually
if (schema.isSecret) {
inputType = 'password';
} else {
switch (schema.type) {
case 'integer':
inputType = 'number';
break;
case 'number':
inputType = 'text'; // Use text input to allow floating points, validate manually
break;
default:
break;
}
}

const handleChange = useCallback(
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/components/form/settingsMapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export function MapSettingToSchema(setting: ISettingMap): RJSFSchema {
defaultValueParsed = defaultValue === 'true';
}

const isSecret = !!setting.isSecret;

function getEnumValues(): string[] | undefined {
if (typeof enumValues === 'function') {
return enumValues?.();
Expand All @@ -74,6 +76,7 @@ export function MapSettingToSchema(setting: ISettingMap): RJSFSchema {
enum: getEnumValues(),
description,
originalName: name,
isSecret,
};

return property;
Expand Down

0 comments on commit 9340507

Please sign in to comment.