Skip to content

Commit

Permalink
Add support for new form field types
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Dec 18, 2024
1 parent 0aa91b5 commit dd51a60
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/main/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const NotificationMessage = ({ notification, level }: NotificationMessageProps)
className="primary"
style={{
marginTop: '10px',
marginLeft: '5px',
}}
color={color}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const getEntry = (
},
{
key: 'password',
type: API.SettingTypeEnum.STRING,
type: API.SettingTypeEnum.PASSWORD,
title: isNew ? 'Password' : 'New password',
optional: !isNew,
},
Expand Down Expand Up @@ -252,8 +252,6 @@ class WebUserDialog extends Component<Props> {
fieldOptions.factory = t.form.Select;
fieldOptions.template = PermissionSelector(moduleT);
fieldOptions.disabled = !this.isNew() && user.username === LoginStore.user.username;
} else if (id === 'password') {
fieldOptions.type = 'password';
} else if (id === 'username') {
fieldOptions.disabled = !this.isNew();
}
Expand Down
7 changes: 7 additions & 0 deletions src/types/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
export const enum SettingTypeEnum {
NUMBER = 'number',
BOOLEAN = 'boolean',

STRING = 'string',
TEXT = 'text',

PASSWORD = 'password',
URL = 'url',
EMAIL = 'email',

EXISTING_FILE_PATH = 'existing_file_path',
FILE_PATH = 'file_path',
DIRECTORY_PATH = 'directory_path',

STRUCT = 'struct',
LIST = 'list',
HINTED_USER = 'hinted_user',
Expand Down
15 changes: 15 additions & 0 deletions src/utils/FormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const typeToComponent = (
return tcomb.Boolean;
case API.SettingTypeEnum.STRING:
case API.SettingTypeEnum.TEXT:
case API.SettingTypeEnum.EMAIL:
case API.SettingTypeEnum.URL:
case API.SettingTypeEnum.PASSWORD:
case API.SettingTypeEnum.EXISTING_FILE_PATH:
case API.SettingTypeEnum.FILE_PATH:
case API.SettingTypeEnum.HUB_URL:
Expand Down Expand Up @@ -218,6 +221,18 @@ const parseTypeOptions = (type: API.SettingTypeEnum): tcomb.form.TcombOptions =>
};
break;
}
case API.SettingTypeEnum.EMAIL: {
options.type = 'email';
break;
}
case API.SettingTypeEnum.PASSWORD: {
options.type = 'password';
break;
}
case API.SettingTypeEnum.URL: {
options.type = 'url';
break;
}
case API.SettingTypeEnum.FILE_PATH:
case API.SettingTypeEnum.EXISTING_FILE_PATH:
case API.SettingTypeEnum.DIRECTORY_PATH: {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/RSS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const RSS = {
{
key: 'feed_url',
title: 'Feed URL',
type: API.SettingTypeEnum.STRING,
type: API.SettingTypeEnum.URL,
help: 'RSS and Atom feeds are supported',
default_value: '',
},
Expand Down

0 comments on commit dd51a60

Please sign in to comment.