@samitouri / QOSami-HFS / commits / ef3e0a42

admin/plugins/installed: avoid changing position after start/stop

Massimo Melina committed Jan 17, 2024 at 23:27 UTC ef3e0a425e5ee26ce8f4efa6e785dd30fed30389
2 files changed +9 -7
admin/src/InstalledPlugins.ts
+8 -4
@@ -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 { apiCall, useApiList } from './api'
4 -import { createElement as h, Fragment, ReactNode, useMemo } from 'react'
4 +import { createElement as h, Fragment, ReactNode, useEffect } 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'
@@ -15,12 +15,16 @@ import { PLUGIN_ERRORS } from './PluginsPage'
15 import { Btn, IconBtn } from './mui'
16
17 export default function InstalledPlugins({ updates }: { updates?: true }) {
18 - const { list, updateEntry, error, initializing } = useApiList(updates ? 'get_plugin_updates' : 'get_plugins')
19 - const sorted = useMemo(() => _.sortBy(list, x => (x.started ? '0' : '1') + x.id), [list])
18 + const { list, updateEntry, error, updateList, initializing } = useApiList(updates ? 'get_plugin_updates' : 'get_plugins')
19 + useEffect(() => {
20 + if (!initializing)
21 + updateList(list =>
22 + _.sortBy(list, x => (x.started ? '0' : '1') + x.id))
23 + }, [initializing]);
24 const size = 'small'
25 return h(DataTable, {
26 error: xlate(error, PLUGIN_ERRORS),
23 - rows: sorted,
27 + rows: list.length ? list : [], // workaround for DataGrid bug causing 'no rows' message to be not displayed after 'loading' was also used
28 initializing,
29 disableColumnSelector: true,
30 disableColumnMenu: true,
admin/src/api.ts
+1 -3
@@ -159,9 +159,7 @@ export function useApiList<T=any, S=T>(cmd:string|Falsy, params: Dict={}, { map,
159 }
160
161 function updateList(cb: (toModify: Draft<typeof list>) => void) {
162 - setList(produce(list, x => {
163 - cb(x)
164 - }))
162 + setList(produce(list, cb))
163 }
164
165 function updateEntry(search: T, change: T) {