removed unused code

Massimo Melina committed Oct 22, 2023 at 23:43 UTC 7846e9f7bc68794f2eaa4887a06d1c018f2eeb14
1 file changed -80
admin/src/PermField.ts deleted
-80
@@ -1,80 +0,0 @@
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 { Dict, useStateMounted } from './misc'
4 -import { createElement as h, Fragment } from 'react'
5 -import { Button, Grid } from '@mui/material'
6 -import { Field, FieldProps, SelectField } from '@hfs/mui-grid-form'
7 -import _ from 'lodash'
8 -import { useApiEx } from './api'
9 -
10 -export default function PermField({ label, value, onChange }: FieldProps<Dict<string> | null> & { keyLabel:string }) {
11 - const [temp, setTemp] = useStateMounted<string|undefined>(undefined)
12 - const { data, element } = useApiEx('get_usernames')
13 - const usernames = data?.list || []
14 -
15 - const permOptions = [{ label:'read', value:'r' }, { label:'none', value:'' }]
16 - const usernamesLeft = _.difference(usernames, Object.keys(value||{}))
17 -
18 - return h(Grid, { container: true },
19 - label && h(Grid, { item: true, xs: 12, pl: 2, py: 1, display: 'flex', alignItems: 'center', justifyContent: 'space-between' },
20 - label,
21 - !element && h(Button, {
22 - onClick(event){
23 - setTemp(undefined)
24 - onChange(null, { event, was: value })
25 - }
26 - }, 'Clear')),
27 - element || h(Fragment, {},
28 - // existing entries
29 - Object.entries(value||{}).map(([username, perm]) => [
30 - h(Grid, { key:'k', item: true, xs: 6 },
31 - h(SelectField as Field<string>, {
32 - label: 'Username',
33 - options: usernames,
34 - value: username,
35 - onChange(v, { was, ...rest }){
36 - const copy: any = { ...value, [v]: value![was!] }
37 - delete copy[was!]
38 - onChange(copy, { was:value, ...rest })
39 - }
40 - })),
41 - h(Grid, { key:'v', item: true, xs: 6 },
42 - h(SelectField as Field<string>, {
43 - label: 'Access',
44 - options: permOptions,
45 - value: perm,
46 - onChange(v, { was, ...rest }){
47 - const copy = { ...value }
48 - if (v)
49 - copy[username] = v
50 - else
51 - delete copy[username]
52 - onChange( _.isEmpty(copy) ? null : copy, { was:value, ...rest })
53 - }
54 - })),
55 - ]),
56 - // row for new entries
57 - !usernamesLeft.length && h(Grid, { item: true, xs: 12, py: 1, px: 2, color:'text.secondary' }, "No accounts left"),
58 - usernamesLeft.length>0 && h(Grid, { item: true, xs: 6 },
59 - h(SelectField as Field<string>, {
60 - label: value ? "Add access to" : "Restrict access to ",
61 - value: temp,
62 - options: usernamesLeft,
63 - onChange: setTemp as any,
64 - })),
65 - usernamesLeft.length>0 && h(Grid, { item: true, xs: 6 },
66 - h(SelectField as Field<string>, {
67 - value: undefined,
68 - label: temp && "Select access type",
69 - disabled: !temp,
70 - options: permOptions,
71 - onChange(v, rest) {
72 - if (v)
73 - onChange({ ...value, [temp!]: v }, { ...rest, was: value })
74 - setTemp(undefined)
75 - }
76 - }))
77 - )
78 - )
79 -}
80 -