|
1 | | -import { CardMedia, Stack, Switch, Tooltip, Typography } from "@mui/material"; |
2 | | -import { CatalogItemRichened } from "../../types/catalog"; |
| 1 | +import { Avatar, CardHeader, Switch, Tooltip, Typography } from '@mui/material'; |
| 2 | +import { capitalize } from 'lodash-es'; |
| 3 | + |
| 4 | +import { CatalogItemRichened } from '../../types/catalog'; |
3 | 5 |
|
4 | 6 | type TopProps = { |
5 | | - onToggleRegister: (checked: boolean) => void, |
6 | | - item: CatalogItemRichened |
7 | | -} |
| 7 | + onToggleRegister: (checked: boolean) => void; |
| 8 | + item: CatalogItemRichened; |
| 9 | +}; |
8 | 10 |
|
9 | 11 | export default function Top({ item, onToggleRegister }: TopProps) { |
10 | | - |
11 | | - const getActionButton = () => { |
12 | | - if (!item.canRegister) { |
13 | | - return <Stack direction="row" spacing={0} alignItems="center"> |
14 | | - <Tooltip title="This tile needs configuration before it can be used."> |
15 | | - <span> |
16 | | - <Switch checked={false} disabled /> |
17 | | - </span> |
18 | | - </Tooltip> |
19 | | - </Stack> |
20 | | - } |
21 | | - return <Stack direction="row" spacing={0} alignItems="center"> |
22 | | - <Tooltip title={item.registered ? "Unregistering this tile will hide it from MCP clients." : "Registering this tile will expose it to MCP clients."}> |
23 | | - <Switch |
24 | | - checked={item.registered} |
25 | | - onChange={(event, checked) => { |
26 | | - event.stopPropagation() |
27 | | - event.preventDefault() |
28 | | - onToggleRegister(checked) |
29 | | - }} |
30 | | - /> |
31 | | - </Tooltip> |
32 | | - </Stack> |
33 | | - } |
34 | | - return ( |
35 | | - <Stack direction="row" spacing={0} sx={{ alignItems: 'center', justifyContent: 'space-between', width: '100%', mb: 1.5 }}> |
36 | | - <Stack direction="row" spacing={2} sx={{ alignItems: 'center', justifyContent: 'space-between' }}> |
37 | | - <CardMedia |
38 | | - component="img" |
39 | | - image={item.icon} |
40 | | - alt={item.name} |
41 | | - sx={{ width: 25, height: 25, borderRadius: 1, background: 'white', padding: '2px', justifySelf: 'flex-start' }} |
42 | | - /> |
43 | | - <Typography sx={{ justifySelf: 'flex-start', fontWeight: 'bold' }}>{item.name}</Typography> |
44 | | - </Stack> |
45 | | - {getActionButton()} |
46 | | - </Stack> |
47 | | - ) |
| 12 | + return ( |
| 13 | + <CardHeader |
| 14 | + sx={{ padding: 0 }} |
| 15 | + avatar={ |
| 16 | + <Avatar |
| 17 | + variant="square" |
| 18 | + src={item.icon} |
| 19 | + alt={item.name} |
| 20 | + sx={{ |
| 21 | + width: 24, |
| 22 | + height: 24, |
| 23 | + borderRadius: 1, |
| 24 | + }} |
| 25 | + /> |
| 26 | + } |
| 27 | + title={ |
| 28 | + <Typography sx={{ justifySelf: 'flex-start', fontWeight: 'bold' }}> |
| 29 | + { |
| 30 | + // Lodash doesn't have a capitalize function that works with strings |
| 31 | + item.name |
| 32 | + .replace(/-/g, ' ') |
| 33 | + .replace(/_/g, ' ') |
| 34 | + .split(' ') |
| 35 | + .map(capitalize) |
| 36 | + .join(' ') |
| 37 | + } |
| 38 | + </Typography> |
| 39 | + } |
| 40 | + action={ |
| 41 | + item.canRegister ? ( |
| 42 | + <Tooltip |
| 43 | + title={ |
| 44 | + item.registered |
| 45 | + ? 'Unregistering this server will hide it from MCP clients.' |
| 46 | + : 'Registering this server will expose it to MCP clients.' |
| 47 | + } |
| 48 | + > |
| 49 | + <Switch |
| 50 | + checked={item.registered} |
| 51 | + onChange={(event, checked) => { |
| 52 | + event.stopPropagation(); |
| 53 | + event.preventDefault(); |
| 54 | + onToggleRegister(checked); |
| 55 | + }} |
| 56 | + /> |
| 57 | + </Tooltip> |
| 58 | + ) : ( |
| 59 | + <Tooltip title="This server needs configuration before it can be used."> |
| 60 | + <span> |
| 61 | + <Switch checked={false} disabled /> |
| 62 | + </span> |
| 63 | + </Tooltip> |
| 64 | + ) |
| 65 | + } |
| 66 | + /> |
| 67 | + ); |
48 | 68 | } |
0 commit comments