admin/plugins: show last error

Massimo Melina committed Jun 3, 2023 at 17:06 UTC 71fb2e08f2c888cbfdb6266a4d190074dc29505f
1 file changed +14 -10
admin/src/InstalledPlugins.ts
+14 -10
@@ -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 } from 'react'
4 +import { createElement as h, Fragment, ReactNode } from 'react'
5 import { Alert, Box, Link, Tooltip } from '@mui/material'
6 import { DataGrid } from '@mui/x-data-grid'
7 import { Delete, Error, PlayCircle, Settings, StopCircle, Upgrade } from '@mui/icons-material'
@@ -106,15 +106,19 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
106
107 export function renderName({ row, value }: any) {
108 const { repo } = row
109 - const warn = typeof row.badApi === 'string' && h(Tooltip, {
110 - title: row.badApi,
111 - children: h(Error, { fontSize: 'small', color: 'warning', sx: { ml: -.5, mr: .5 } })
112 - })
113 - if (!repo)
114 - return [warn, value]
115 - const arr = repo.split('/')
116 - const link = h(Link, { href: 'https://github.com/' + repo, target: 'plugin' }, arr[1])
117 - return h(Fragment, {}, warn, link, '\xa0by ', arr[0])
109 + const arr = repo?.split('/')
110 + return h(Fragment, {},
111 + errorIcon(row.badApi, true),
112 + errorIcon(row.error),
113 + ...!repo ? [value] : [ h(Link, { href: 'https://github.com/' + repo, target: 'plugin' }, arr[1]), '\xa0by ', arr[0] ]
114 + )
115 +
116 + function errorIcon(msg: ReactNode, warning=false) {
117 + return msg && h(Tooltip, {
118 + title: msg,
119 + children: h(Error, { fontSize: 'small', color: warning ? 'warning' : 'error', sx: { ml: -.5, mr: .5 } })
120 + })
121 + }
122 }
123
124 function makeFields(config: any) {