ux: admin/updates: avoid removing the entry after update is completed
Massimo Melina committed
Jun 5, 2023 at 21:19 UTC
a244f05d10cbffd1acd9a64e7e24fd72e2a0e44f
2 files changed
+15
-6
admin/src/InstalledPlugins.ts
+6
-5
@@ -13,7 +13,7 @@ import { ArrayField } from './ArrayField'
13
import FileField from './FileField'
14
15
export default function InstalledPlugins({ updates }: { updates?: true }) {
16
- const { list, setList, error, initializing } = useApiList(updates ? 'get_plugin_updates' : 'get_plugins')
16
+ const { list, updateEntry, error, initializing } = useApiList(updates ? 'get_plugin_updates' : 'get_plugins')
17
if (error)
18
return showError(error)
19
return h(DataGrid, {
@@ -49,9 +49,9 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
49
hideSortIcons: true,
50
disableColumnMenu: true,
51
renderCell({ row }) {
52
- const { config, id } = row
52
+ const { config, id, updated } = row
53
if (updates)
54
- return h(UpdateButton, { id, then: () => setList(list.filter(x => x.id !== id)) })
54
+ return h(UpdateButton, { id, updated, then: () => updateEntry({ id }, { updated: true }) })
55
return h('div', {},
56
h(IconBtn, row.started ? {
57
icon: StopCircle,
@@ -152,10 +152,11 @@ export function showError(error: any) {
152
}))
153
}
154
155
-export function UpdateButton({ id, then }: { id: string, then: (id:string)=>void }) {
155
+export function UpdateButton({ id, updated, then }: { id: string, updated?: boolean, then: (id:string)=>void }) {
156
return h(IconBtn, {
157
icon: Upgrade,
158
- title: "Update",
158
+ title: updated ? "Already updated" : "Update",
159
+ disabled: updated,
160
async onClick() {
161
await apiCall('update_plugin', { id }, { timeout: false })
162
then?.(id)
admin/src/api.ts
+9
-1
@@ -133,7 +133,7 @@ export function useApiList<T=any>(cmd:string|Falsy, params: Dict={}, { addId=fal
133
apply.flush()
134
}
135
}, [reloader, cmd, JSON.stringify(params)]) //eslint-disable-line
136
- return { list, props, loading, error, initializing, connecting, setList, updateList, reload }
136
+ return { list, props, loading, error, initializing, connecting, setList, updateList, updateEntry, reload }
137
138
function reload() {
139
setReloader(x => x + 1)
@@ -144,4 +144,12 @@ export function useApiList<T=any>(cmd:string|Falsy, params: Dict={}, { addId=fal
144
cb(x)
145
}))
146
}
147
+
148
+ function updateEntry(search: T, change: T) {
149
+ updateList(list => {
150
+ const res = _.find(list, search as any)
151
+ if (res)
152
+ Object.assign(res, change)
153
+ })
154
+ }
155
}