plugins: new config type "username"
Massimo Melina committed
Apr 16, 2024 at 00:07 UTC
1be877b78c6f61f927be9b7008060edac487808b
3 files changed
+19
-4
admin/src/InstalledPlugins.ts
+15
-2
@@ -1,6 +1,6 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
-import { apiCall, useApiList } from './api'
3
+import { apiCall, useApiEx, useApiList } from './api'
4
import { createElement as h, Fragment, useEffect } from 'react'
5
import { Box, Link } from '@mui/material'
6
import { DataTable } from './DataTable'
@@ -8,7 +8,9 @@ import { Delete, Error as ErrorIcon, PlayCircle, Settings, StopCircle, Upgrade }
8
import { HTTP_FAILED_DEPENDENCY, prefix, with_, xlate } from './misc'
9
import { alertDialog, formDialog, toast } from './dialog'
10
import _ from 'lodash'
11
-import { BoolField, Field, MultiSelectField, NumberField, SelectField, StringField } from '@hfs/mui-grid-form'
11
+import { Account } from './AccountsPage'
12
+import { BoolField, Field, FieldProps, MultiSelectField, NumberField, SelectField, StringField
13
+} from '@hfs/mui-grid-form'
14
import { ArrayField } from './ArrayField'
15
import FileField from './FileField'
16
import { PLUGIN_ERRORS } from './PluginsPage'
@@ -169,6 +171,7 @@ const type2comp = {
171
multiselect: MultiSelectField,
172
array: ArrayField,
173
real_path: FileField,
174
+ username: UsernameField,
175
}
176
177
export async function startPlugin(id: string) {
@@ -181,3 +184,13 @@ export async function startPlugin(id: string) {
184
alertDialog(`Plugin ${id} didn't start, with error: ${String(e?.message || e)}`, 'error')
185
}
186
}
187
+
188
+function UsernameField({ value, onChange, ...rest }: FieldProps<string>) {
189
+ const { data, element } = useApiEx<{ list: Account[] }>('get_accounts')
190
+ return element || h(SelectField as Field<string>, {
191
+ value, onChange,
192
+ options: data?.list.map(x => x.username),
193
+ helperText: "Only users, no groups here",
194
+ ...rest,
195
+ })
196
+}
\ No newline at end of file
admin/src/VfsPathField.ts
+1
-1
@@ -8,7 +8,7 @@ interface VfsPathFieldProps extends FieldProps<string> {
8
autocompleteProps: Partial<AutocompleteProps<string, false, true, undefined>>
9
}
10
11
-export default function VfsPathField({ value='', onChange, helperText, setApi, autocompleteProps, onlyFolders=true, ...props }: VfsPathFieldProps) {
11
+export default function VfsPaathField({ value='', onChange, helperText, setApi, autocompleteProps, onlyFolders=true, ...props }: VfsPathFieldProps) {
12
const uri = dirname(value)
13
const { list, loading } = useApiList('get_file_list', { uri, admin: true, onlyFolders })
14
const options = useMemo(() => [uri + '/'].concat(list.map(x => value + x.n)), [list, uri])
dev-plugins.md
+3
-1
@@ -118,7 +118,7 @@ used must be strictly JSON (thus, no single quotes, only double quotes for strin
118
### FieldDescriptor
119
120
Currently, these properties are supported:
121
-- `type: 'string' | 'number' | 'boolean' | 'select' | 'multiselect' | 'real_path' | 'array'` . Default is `string`.
121
+- `type: 'string' | 'number' | 'boolean' | 'select' | 'multiselect' | 'real_path' | 'array' | 'username'ì` . Default is `string`.
122
- `label: string` what name to display next to the field. Default is based on `key`.
123
- `defaultValue: any` value to be used when nothing is set.
124
- `helperText: string` extra text printed next to the field.
@@ -147,6 +147,7 @@ Based on `type`, other properties are supported:
147
- `folders: boolean` allow to select a folder. Default is `false`.
148
- `defaultPath: string` what path to start from if no value is set. E.g. __dirname if you want to start with your plugin's folder.
149
- `fileMask: string` restrict files that are displayed. E.g. `*.jpg|*.png`
150
+- `username`
151
152
## api object
153
@@ -421,6 +422,7 @@ If you want to override a text regardless of the language, use the special langu
422
423
- 8.8 (v0.53.0)
424
- new event: menuZip
425
+- config.type:username
426
- 8.72 (v0.52.0)
427
- HFS.toast
428
- HFS.misc functions