@samitouri / QOSami-HFS / commits / 60a227e7

admin/plugins: configure dialog now has save-without-closing button

Massimo Melina committed Oct 24, 2023 at 23:22 UTC 60a227e7878ac7a11e626a2b9fd10897cef5f6bd
2 files changed +16 -7
admin/src/HomePage.ts
+1 -1
@@ -2,7 +2,7 @@
2
3 import { createElement as h, ReactNode, useState } from 'react'
4 import { Box, Button, Card, CardContent, LinearProgress, Link } from '@mui/material'
5 -import { apiCall, apiEvents, useApiEvents, useApiEx, useApiList } from './api'
5 +import { apiCall, useApiEx, useApiList } from './api'
6 import {
7 Btn,
8 dontBotherWithKeys,
admin/src/InstalledPlugins.ts
+15 -6
@@ -5,7 +5,7 @@ import { createElement as h, Fragment, ReactNode } from 'react'
5 import { Box, Link, Tooltip } from '@mui/material'
6 import { DataTable } from './DataTable'
7 import { Delete, Error as ErrorIcon, PlayCircle, Settings, StopCircle, Upgrade } from '@mui/icons-material'
8 -import { IconBtn, prefix, with_, xlate } from './misc'
8 +import { Btn, IconBtn, prefix, with_ } 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'
@@ -83,19 +83,28 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
83 progress: false,
84 async onClick() {
85 const pl = await apiCall('get_plugin', { id })
86 + let lastSaved = pl.config
87 const values = await formDialog({
88 title: `Options for ${id}`,
88 - form: {
89 + form: values => ({
90 before: h(Box, { mx: 2, mb: 3 }, row.description),
91 fields: makeFields(row.config),
91 - },
92 + save: { children: "Save and close" },
93 + barSx: { gap: 1 },
94 + addToBar: [h(Btn, { variant: 'outlined', onClick: () => save(values) }, "Save")],
95 + }),
96 values: pl.config,
97 dialogProps: _.merge({ sx: { m: 'auto' } }, // center content when it is smaller than mobile (because of full-screen)
98 row.configDialog),
99 })
96 - if (!values || _.isEqual(pl.config, values)) return
97 - await apiCall('set_plugin', { id, config: values })
98 - toast("Configuration saved")
100 + if (values && !_.isEqual(lastSaved, values))
101 + return save(values)
102 +
103 + async function save(values: any) {
104 + await apiCall('set_plugin', { id, config: values })
105 + Object.assign(lastSaved, values)
106 + toast("Configuration saved")
107 + }
108 }
109 }),
110 h(IconBtn, {