better code
Massimo Melina committed
May 28, 2024 at 20:05 UTC
2a7e5791f587aebe1c0640a6133f176cb95cd484
2 files changed
+7
-8
admin/src/InstalledPlugins.ts
+2
-3
@@ -92,8 +92,7 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
92
|| !row.config && "No options available for this plugin",
93
progress: false,
94
async onClick() {
95
- const pl = await apiCall('get_plugin', { id })
96
- let lastSaved = pl.config
95
+ const { config: lastSaved } = await apiCall('get_plugin', { id })
96
const values = await formDialog({
97
title: `Options for ${id}`,
98
form: values => ({
@@ -103,7 +102,7 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
102
barSx: { gap: 1 },
103
addToBar: [h(Btn, { variant: 'outlined', onClick: () => save(values) }, "Save")],
104
}),
106
- values: pl.config,
105
+ values: lastSaved,
106
dialogProps: _.merge({ sx: { m: 'auto' } }, // center content when it is smaller than mobile (because of full-screen)
107
row.configDialog),
108
})
admin/src/dialog.ts
+5
-5
@@ -149,12 +149,12 @@ type FormDialog<T> = Omit<FormProps<T>, 'values' | 'save' | 'set'>
149
export async function formDialog<T>(
150
{ form, values, ...options }: Omit<DialogOptions, 'Content'> & {
151
values?: Partial<T>,
152
- form: FormDialog<T> | ((values: Partial<T>) => FormDialog<T>),
152
+ form: FormDialog<T> | ((values: Partial<T>) => FormDialog<T>), // allow callback form
153
},
154
) : Promise<T> {
155
return new Promise(resolve => {
156
const dialog = newDialog({
157
- className: 'dialog-confirm',
157
+ className: 'dialog-form',
158
onClose: resolve,
159
...options,
160
Content() {
@@ -172,11 +172,11 @@ export async function formDialog<T>(
172
return newV
173
})
174
},
175
- save: {
176
- ...props.save,
175
+ save: props.save !== false && {
176
onClick() {
177
dialog.close(curValues)
179
- }
178
+ },
179
+ ...props.save,
180
}
181
})
182
)