admin/plugins: same link for installed and online plugins
Massimo Melina committed
Apr 14, 2023 at 16:16 UTC
e19fd8a2899f92ff13f1c80b243e757fc9e30a33
2 files changed
+18
-23
admin/src/InstalledPlugins.ts
+16
-21
@@ -4,8 +4,8 @@ import { apiCall, useApiList } from './api'
4
import { createElement as h, Fragment } from 'react'
5
import { Alert, Box, Link, Tooltip } from '@mui/material'
6
import { DataGrid } from '@mui/x-data-grid'
7
-import { Delete, Error, GitHub, PlayCircle, Settings, StopCircle, Upgrade } from '@mui/icons-material'
8
-import { IconBtn, prefix, xlate } from './misc'
7
+import { Delete, Error, PlayCircle, Settings, StopCircle, Upgrade } from '@mui/icons-material'
8
+import { IconBtn, xlate } from './misc'
9
import { formDialog, toast } from './dialog'
10
import _ from 'lodash'
11
import { BoolField, Field, MultiSelectField, NumberField, SelectField, StringField } from '@hfs/mui-grid-form'
@@ -31,17 +31,7 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
31
headerName: "name",
32
flex: .3,
33
minWidth: 150,
34
- renderCell({ row, value }) {
35
- const href = prefix('https://github.com/', row.repo)
36
- const children = [
37
- typeof row.badApi === 'string' && h(Tooltip, {
38
- title: row.badApi,
39
- children: h(Error, { fontSize: 'small', color: 'warning', sx: { ml: -.5, mr: .5 } })
40
- }),
41
- value,
42
- ]
43
- return !href ? children : h(Link, { href, target: 'plugin' }, ...children)
44
- }
34
+ renderCell: renderName
35
},
36
{
37
field: 'version',
@@ -113,6 +103,19 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
103
})
104
}
105
106
+export function renderName({ row, value }: any) {
107
+ const { repo } = row
108
+ const warn = typeof row.badApi === 'string' && h(Tooltip, {
109
+ title: row.badApi,
110
+ children: h(Error, { fontSize: 'small', color: 'warning', sx: { ml: -.5, mr: .5 } })
111
+ })
112
+ if (!repo)
113
+ return [warn, value]
114
+ const arr = repo.split('/')
115
+ const link = h(Link, { href: 'https://github.com/' + repo, target: 'plugin' }, arr[1])
116
+ return h(Fragment, {}, warn, link, '\xa0by ', arr[0])
117
+}
118
+
119
function makeFields(config: any) {
120
return Object.entries(config).map(([k,o]: [string,any]) => {
121
if (!_.isPlainObject(o))
@@ -137,14 +140,6 @@ const type2comp = {
140
real_path: FileField,
141
}
142
140
-export function repoLink(repo?: string) {
141
- return repo && h(IconBtn, {
142
- icon: GitHub,
143
- title: "Open web page",
144
- link: 'https://github.com/' + repo,
145
- })
146
-}
147
-
143
export function showError(error: any) {
144
return h(Alert, { severity: 'error' }, xlate(error, {
145
ENOTFOUND: "Couldn't reach github.com"
admin/src/OnlinePlugins.ts
+2
-2
@@ -8,7 +8,7 @@ import { Download, Search } from '@mui/icons-material'
8
import { confirmDialog } from './dialog'
9
import { StringField } from '@hfs/mui-grid-form'
10
import { useDebounce } from 'usehooks-ts'
11
-import { repoLink, showError, startPlugin, UpdateButton } from './InstalledPlugins'
11
+import { renderName, showError, startPlugin, UpdateButton } from './InstalledPlugins'
12
import { state, useSnapState } from './state'
13
import _ from 'lodash'
14
import md from './md'
@@ -39,6 +39,7 @@ export default function OnlinePlugins() {
39
field: 'id',
40
headerName: "name",
41
flex: 1,
42
+ renderCell: renderName,
43
},
44
{
45
field: 'version',
@@ -73,7 +74,6 @@ export default function OnlinePlugins() {
74
renderCell({ row }) {
75
const { id, branch } = row
76
return h('div', {},
76
- repoLink(id),
77
row.update ? h(UpdateButton, {
78
id,
79
then() {