admin/plugins: "clear" button for plugins' log #937

Massimo Melina committed May 4, 2025 at 10:56 UTC ae1966a7d3dffe729572c7eeb22d1f729e91a014
1 file changed +9 -5
admin/src/InstalledPlugins.ts
+9 -5
@@ -150,19 +150,23 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
150 { maxWidth: false, sx: { maxWidth: null } }, // cancel maxWidth to move it to the Box below
151 ),
152 Wrapper({ children }: any) {
153 - const { list } = useApiList('get_plugin_log', { id }, {
153 + const { list, setList } = useApiList('get_plugin_log', { id }, {
154 map(x) { x.ts = new Date(x.ts) }
155 })
156 const autoScroll = useAutoScroll(list)
157 let lastDate: any
158 return h(Flex, { alignItems: 'stretch', justifyContent: 'center', flexWrap: 'wrap', flexDirection: showOptions ? undefined : 'column' },
159 h(Box, { maxWidth, minWidth: 'min-content' /*in case content requires more space (eg: reverse-proxy's table)*/ }, children),
160 - list.length > 0 ? h(Paper, { elevation: 1, sx: { position: 'relative', fontFamily: 'monospace', flex: 1, minWidth: 'min(40em, 90vw)', minHeight: '20em', px: .5 } },
161 - h(Box, { my: .5, pb: .5, borderBottom: '1px solid' }, "Output"),
160 + h(Paper, { elevation: 1, sx: { position: 'relative', fontFamily: 'monospace', flex: 1, minWidth: 'min(40em, 90vw)', minHeight: '20em', px: .5 } },
161 + h(Box, { my: .5, pb: .5, borderBottom: '1px solid', display: 'flex', alignItems: 'center', justifyContent: 'space-between' },
162 + "Output",
163 + h(Btn, { size: 'small', sx: { p: 0 }, onClick() { setList([]) } }, "Clear")
164 + ),
165 h(Box, {
163 - position: 'absolute', bottom: 0, top: '1.8em', left: 0, right: 0, sx: { overflowY: 'auto' },
166 + position: 'absolute', bottom: 0, top: '31px', left: 0, right: 0, sx: { overflowY: 'auto' },
167 ref: autoScroll,
168 },
169 + !list.length && h(Box, { p: 1 }, "Log is empty"),
170 h(Box, {
171 sx: {
172 textIndent: '-1em', pl: '1em',
@@ -183,7 +187,7 @@ export default function InstalledPlugins({ updates }: { updates?: true }) {
187 )
188 }))
189 )
186 - ) : showOptions ? null : h(Box, { p: '1em', pt: 0 }, "Log is empty")
190 + )
191 )
192 }
193 })