catalog-react: improve link rendering in entity inspector

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-05-12 15:52:05 +02:00
parent 7c868974a4
commit b7514d19ff
2 changed files with 19 additions and 10 deletions
@@ -89,26 +89,30 @@ export function Container(props: {
);
}
// Extracts a link from a value, if possible
function findLink(value: string): string | undefined {
if (value.match(/^url:https?:\/\//)) {
return value.slice('url:'.length);
}
if (value.match(/^https?:\/\//)) {
return value;
}
return undefined;
}
export function KeyValueListItem(props: {
indent?: boolean;
entry: [string, string];
}) {
const [key, value] = props.entry;
const link = findLink(value);
return (
<ListItem>
{props.indent && <ListItemIcon />}
<ListItemText
primary={key}
secondary={
!value.match(/^url:https?:\/\//) ? (
value
) : (
<>
{value.substring(0, 4)}
<Link to={value.substring(4)}>{value.substring(4)}</Link>
</>
)
}
secondary={link ? <Link to={link}>{value}</Link> : value}
/>
</ListItem>
);