admin/monitoring: persist selection
Massimo Melina committed
Jan 3, 2024 at 11:35 UTC
4455eb1379084ffb47743f942c59e5c8b3e04bbe
2 files changed
+11
-8
admin/src/MonitorPage.ts
+8
-7
@@ -1,7 +1,7 @@
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 _ from "lodash"
4
-import { createElement as h, useMemo, Fragment, useState } from "react"
4
+import { createElement as h, useMemo, Fragment } from "react"
5
import { apiCall, useApiEvents, useApiEx, useApiList } from "./api"
6
import { LinkOff, Lock, Block, FolderZip, Upload, Download } from '@mui/icons-material'
7
import { Box, Chip, ChipProps } from '@mui/material'
@@ -12,6 +12,7 @@ import { Field, SelectField } from '@hfs/mui-grid-form'
12
import { StandardCSSProperties } from '@mui/system/styleFunctionSx/StandardCssProperties'
13
import { toast } from "./dialog"
14
import { agentIcons } from './LogsPage'
15
+import { state, useSnapState } from './state'
16
17
export default function MonitorPage() {
18
return h(Fragment, {},
@@ -85,17 +86,17 @@ function MoreInfo() {
86
function Connections() {
87
const { list, error, props } = useApiList('get_connections')
88
const config = useApiEx('get_config', { only: [CFG.geo_enable] })
88
- const [filtered, setFiltered] = useState(true)
89
+ const { monitorOnlyFiles } = useSnapState()
90
const { pause, pauseButton } = usePauseButton()
91
const rows = useMemo(() =>
91
- list?.filter((x: any) => !filtered || x.op).map((x: any, id: number) => ({ id, ...x })),
92
- [!pause && list, filtered]) //eslint-disable-line
92
+ list?.filter((x: any) => !monitorOnlyFiles || x.op).map((x: any, id: number) => ({ id, ...x })),
93
+ [!pause && list, monitorOnlyFiles]) //eslint-disable-line
94
return h(Fragment, {},
95
h(Box, { display: 'flex', alignItems: 'center' },
96
h(SelectField as Field<boolean>, {
97
fullWidth: false,
97
- value: filtered,
98
- onChange: setFiltered as any,
98
+ value: monitorOnlyFiles,
99
+ onChange: v => state.monitorOnlyFiles = v,
100
options: { "Show only files": true, "Show all connections": false }
101
}),
102
@@ -105,7 +106,7 @@ function Connections() {
106
h(DataTable, {
107
error,
108
rows,
108
- noRows: filtered && "No downloads at the moment",
109
+ noRows: monitorOnlyFiles && "No downloads at the moment",
110
columns: [
111
{
112
field: 'ip',
admin/src/state.ts
+3
-1
@@ -15,6 +15,7 @@ export const state = proxy<{
15
selectedFiles: VfsNode[]
16
loginRequired: boolean | number
17
username: string
18
+ monitorOnlyFiles: boolean
19
onlinePluginsColumns: Dict<boolean>
20
}>(Object.assign({
21
title: '',
@@ -24,6 +25,7 @@ export const state = proxy<{
25
vfs: undefined,
26
loginRequired: false,
27
username: '',
28
+ monitorOnlyFiles: true,
29
onlinePluginsColumns: {
30
version: false,
31
pushed_at: false,
@@ -31,7 +33,7 @@ export const state = proxy<{
33
}
34
}, JSON.parse(localStorage[STORAGE_KEY]||null)))
35
34
-const SETTINGS_TO_STORE: (keyof typeof state)[] = ['onlinePluginsColumns']
36
+const SETTINGS_TO_STORE: (keyof typeof state)[] = ['onlinePluginsColumns', 'monitorOnlyFiles']
37
const storeSettings = _.debounce(() =>
38
localStorage[STORAGE_KEY] = JSON.stringify(_.pick(state, SETTINGS_TO_STORE)), 500, { maxWait: 1000 })
39
for (const k of SETTINGS_TO_STORE)