@samitouri / QOSami-HFS / commits / 91c9b043

admin/fs: render link as a link #53

Massimo Melina committed Dec 31, 2023 at 16:51 UTC 91c9b0432bf6c460f9b597e2e4a7f30a5117cab0
1 file changed +3 -1
admin/src/FileForm.ts
+3 -1
@@ -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 { state, useSnapState } from './state'
4 -import { createElement as h, ReactElement, ReactNode, useEffect, useMemo, useState } from 'react'
4 +import { createElement as h, forwardRef, ReactElement, ReactNode, useEffect, useMemo, useState } from 'react'
5 import { Alert, Box, Collapse, FormHelperText, Link, MenuItem, MenuList } from '@mui/material'
6 import { BoolField, DisplayField, Field, FieldProps, Form, MultiSelectField, SelectField, StringField
7 } from '@hfs/mui-grid-form'
@@ -278,12 +278,14 @@ function LinkField({ value, statusApi }: LinkFieldProps) {
278 if (root)
279 value &&= value.indexOf(root) === 1 ? value.slice(root.length) : undefined
280 const link = prefix(data?.baseUrl || '', value)
281 + const RenderLink = useMemo(() => forwardRef((props: any, ref) => h(Link, { ref, ...props, href: link, style: { height: 'auto' }, target: 'frontend' }, link)), [link])
282 return h(Box, { display: 'flex' },
283 !urls ? 'error' : // check data is ok
284 h(DisplayField, {
285 label: "Link",
286 value: link || `outside of configured base address (${baseHost})`,
287 error,
288 + InputProps: { inputComponent: RenderLink },
289 end: h(Box, {},
290 h(IconBtn, {
291 icon: ContentCopy,