admin/fs: icon for access
Massimo Melina committed
Feb 12, 2022 at 00:06 UTC
54b6f2d50dada04540a6a0d3d837c9775e4ca3bb
2 files changed
+8
-5
admin/src/FileCard.ts
+5
-2
@@ -1,6 +1,6 @@
1
import { state, useSnapState } from './state'
2
import { createElement as h, useEffect, useState } from 'react'
3
-import { Card, CardContent, List, ListItem, ListItemText } from '@mui/material'
3
+import { Box, Card, CardContent, List, ListItem, ListItemText } from '@mui/material'
4
import { BoolField, DisplayField, Form } from './Form'
5
import _ from 'lodash'
6
import { apiCall } from './api'
@@ -8,6 +8,7 @@ import { formatBytes, isEqualLax, objSameKeys } from './misc'
8
import { reloadVfs } from './VfsPage'
9
import { alertDialog } from './dialog'
10
import PermField from './PermField'
11
+import { Lock, LockOpen } from '@mui/icons-material'
12
13
export default function FileCard() {
14
const { selectedFiles: files } = useSnapState()
@@ -61,7 +62,9 @@ function FileForm({ file }:any) {
62
{ k: 'mtime', comp: DisplayField, md: 6, label: 'Modified', map: (x:string) => x && new Date(x).toLocaleString() },
63
{ k: 'hidden', comp: BoolField, md: 6 },
64
{ k: 'forbid', comp: BoolField, md: 6 },
64
- { k: 'perm', comp: PermField, label: values.perm ? 'Access restricted' : 'Access not restricted' },
65
+ { k: 'perm', comp: PermField,
66
+ label: h(Box, { display:'flex', gap:1 }, ...values.perm ? [h(Lock), 'Access restricted'] : [h(LockOpen), 'Access not restricted'])
67
+ },
68
{ k: 'mime', lg: 6, label:"MIME type" },
69
realFolder && { k: 'default', lg: 6, label:"Serve file instead of list" },
70
]
admin/src/Form.ts
+3
-3
@@ -15,7 +15,7 @@ import { Dict } from './misc'
15
import { Save } from '@mui/icons-material'
16
import _ from 'lodash'
17
18
-interface FieldDescriptor { k:string, comp?: any, label?: string, [extraProp:string]:any }
18
+interface FieldDescriptor { k:string, comp?: any, label?: string | ReactElement, [extraProp:string]:any }
19
20
interface FormProps {
21
fields: (FieldDescriptor | ReactElement | null | undefined | false)[]
@@ -68,7 +68,7 @@ export function Form({ fields, values, set, defaults, save, sticky, addToBar=[],
68
onChange(v:any) { set(v, field) },
69
...field,
70
}
71
- if (!field.label)
71
+ if (field.label === undefined)
72
field.label = _.capitalize(k.replaceAll('_', ' '))
73
Object.assign(field, defaults?.(field))
74
}
@@ -82,7 +82,7 @@ export function Form({ fields, values, set, defaults, save, sticky, addToBar=[],
82
}
83
84
export interface FieldProps<T> {
85
- label?: string
85
+ label?: string | ReactElement
86
value?: T
87
onChange: (v: T, more: { was?: T, event: any, [rest: string]: any }) => void
88
[rest: string]: any