@samitouri / QOSami-HFS / commits / ce56c6be

nicer

Massimo Melina committed Nov 5, 2023 at 10:41 UTC ce56c6beae588e757449be8d477c4264171dbd48
4 files changed +29 -30
admin/src/AccountForm.ts
+2 -4
@@ -5,7 +5,7 @@ import { BoolField, Form, MultiSelectField } from '@hfs/mui-grid-form'
5 import { Alert, Box } from '@mui/material'
6 import { apiCall } from './api'
7 import { alertDialog, toast, useDialogBarColors } from './dialog'
8 -import { IconBtn, isEqualLax, modifiedSx } from './misc'
8 +import { IconBtn, isEqualLax, modifiedSx, wantArray } from './misc'
9 import { Account, account2icon } from './AccountsPage'
10 import { createVerifierAndSalt, SRPParameters, SRPRoutines } from 'tssrp6a'
11 import { AutoDelete, Delete } from '@mui/icons-material'
@@ -46,9 +46,7 @@ export default function AccountForm({ account, done, groups, addToBar, reload }:
46 disabled: account.invalidated,
47 onClick: () => apiCall('invalidate_sessions', { username: account.username }).then(reload)
48 }),
49 - addToBar,
50 - h(Box, { flex:1 }),
51 - account2icon(values, { fontSize: 'large', sx: { p: 1 }})
49 + ...wantArray(addToBar),
50 ],
51 fields: [
52 { k: 'username', label: group ? 'Group name' : undefined, autoComplete: 'off', required: true, xl: group ? 12 : 4,
admin/src/AccountsPage.ts
+17 -15
@@ -4,7 +4,7 @@ import { createElement as h, useState, useEffect, Fragment } from "react"
4 import { apiCall, useApiEx } from './api'
5 import { Alert, Box, Button, Card, CardContent, Grid, List, ListItem, ListItemText, Typography } from '@mui/material'
6 import { Close, Delete, DoNotDisturb, Group, MilitaryTech, Person, PersonAdd } from '@mui/icons-material'
7 -import { IconBtn, iconTooltip, newDialog, reloadBtn, useBreakpoint } from './misc'
7 +import { IconBtn, iconTooltip, newDialog, reloadBtn, useBreakpoint, with_ } from './misc'
8 import { TreeItem, TreeView } from '@mui/lab'
9 import MenuButton from './MenuButton'
10 import AccountForm from './AccountForm'
@@ -43,20 +43,22 @@ export default function AccountsPage() {
43 h(ListItem, { key: username },
44 h(ListItemText, {}, username))))
45 )
46 - : h(AccountForm, {
47 - account: selectedAccount || { username: '', hasPassword: sel === 'new-user', adminActualAccess: false, invalidated: true },
48 - groups: list.filter(x => !x.hasPassword).map( x => x.username ),
49 - addToBar: isSideBreakpoint && h(IconBtn, { // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
50 - icon: Close,
51 - title: "Close",
52 - onClick: selectNone
53 - }),
54 - reload,
55 - done(username) {
56 - setSel([username])
57 - reload()
58 - }
59 - })
46 + : with_(selectedAccount || { username: '', hasPassword: sel === 'new-user', adminActualAccess: false, invalidated: true }, a =>
47 + h(AccountForm, {
48 + account: a,
49 + groups: list.filter(x => !x.hasPassword).map( x => x.username ),
50 + addToBar: isSideBreakpoint && [
51 + h(Box, { flex:1 }),
52 + account2icon(a, { fontSize: 'large', sx: { p: 1 }}),
53 + // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
54 + h(IconBtn, { icon: Close, title: "Close", onClick: selectNone }),
55 + ],
56 + reload,
57 + done(username) {
58 + setSel([username])
59 + reload()
60 + }
61 + }))
62 useEffect(() => {
63 if (isSideBreakpoint || !sideContent || !sel.length) return
64 const { close } = newDialog({
admin/src/FileForm.ts
+3 -5
@@ -14,10 +14,8 @@ import {
14 StringField
15 } from '@hfs/mui-grid-form'
16 import { apiCall, UseApi, useApiEx } from './api'
17 -import {
18 - basename, Btn, defaultPerms, formatBytes, formatTimestamp, IconBtn, isEqualLax, isWhoObject, LinkBtn, modifiedSx,
19 - newDialog, objSameKeys, onlyTruthy, prefix, useBreakpoint, VfsPerms, Who, WhoObject, wikiLink
20 -} from './misc'
17 +import { basename, Btn, defaultPerms, formatBytes, formatTimestamp, IconBtn, isEqualLax, isWhoObject, LinkBtn, modifiedSx,
18 + newDialog, objSameKeys, onlyTruthy, prefix, useBreakpoint, VfsPerms, wantArray, Who, WhoObject, wikiLink } from './misc'
19 import { reloadVfs, VfsNode } from './VfsPage'
20 import md from './md'
21 import _ from 'lodash'
@@ -110,7 +108,7 @@ export default function FileForm({ file, anyMask, addToBar, statusApi }: FileFor
108 confirm: "Delete?",
109 onClick: () => apiCall('del_vfs', { uris: [file.id] }).then(() => reloadVfs()),
110 }),
113 - addToBar
111 + ...wantArray(addToBar)
112 ],
113 onError: alertDialog,
114 save: {
admin/src/VfsPage.ts
+7 -6
@@ -2,7 +2,7 @@
2
3 import { createElement as h, Fragment, useEffect, useMemo, useState } from 'react'
4 import { apiCall, useApiEx } from './api'
5 -import { Alert, Button, Card, CardContent, Grid, Link, List, ListItem, ListItemText, Typography } from '@mui/material'
5 +import { Alert, Box, Button, Card, CardContent, Grid, Link, List, ListItem, ListItemText, Typography } from '@mui/material'
6 import { state, useSnapState } from './state'
7 import VfsMenuBar from './VfsMenuBar'
8 import VfsTree, { vfsNodeIcon } from './VfsTree'
@@ -45,11 +45,12 @@ export default function VfsPage() {
45
46 const sideContent = !selectedFiles.length ? null
47 : selectedFiles.length === 1 ? h(FileForm, {
48 - addToBar: isSideBreakpoint && h(IconBtn, { // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
49 - icon: Close,
50 - title: "Close",
51 - onClick: selectNone
52 - }),
48 + addToBar: isSideBreakpoint && [
49 + h(Box, { flex: 1 }),
50 + // not really useful, but users misled in thinking it's a dialog will find satisfaction in dismissing the form
51 + vfsNodeIcon(selectedFiles[0] as VfsNode),
52 + h(IconBtn, { icon: Close, title: "Close", onClick: selectNone })
53 + ],
54 anyMask,
55 statusApi,
56 file: selectedFiles[0] as VfsNode // it's actually Snapshot<VfsNode> but it's easier this way