|
1
|
import { ArrowUpRightOnBox } from "@medusajs/icons" |
|
2
|
import { Badge, Container, Heading, IconButton } from "@medusajs/ui" |
|
3
|
import { useTranslation } from "react-i18next" |
|
4
|
import { Link } from "react-router-dom" |
|
5
|
|
|
6
|
type MetadataSectionProps<TData extends object> = { |
|
7
|
data: TData |
|
8
|
href?: string |
|
9
|
} |
|
10
|
|
|
11
|
export const MetadataSection = <TData extends object>({ |
|
12
|
data, |
|
13
|
href = "metadata/edit", |
|
14
|
}: MetadataSectionProps<TData>) => { |
|
15
|
const { t } = useTranslation() |
|
16
|
|
|
17
|
if (!data) { |
|
18
|
return null |
|
19
|
} |
|
20
|
|
|
21
|
if (!("metadata" in data)) { |
|
22
|
return null |
|
23
|
} |
|
24
|
|
|
25
|
const numberOfKeys = data.metadata ? Object.keys(data.metadata).length : 0 |
|
26
|
|
|
27
|
return ( |
|
28
|
<Container className="flex items-center justify-between"> |
|
29
|
<div className="flex items-center gap-x-3"> |
|
30
|
<Heading level="h2">{t("metadata.header")}</Heading> |
|
31
|
<Badge size="2xsmall" rounded="full"> |
|
32
|
{t("metadata.numberOfKeys", { |
|
33
|
count: numberOfKeys, |
|
34
|
})} |
|
35
|
</Badge> |
|
36
|
</div> |
|
37
|
<IconButton |
|
38
|
size="small" |
|
39
|
variant="transparent" |
|
40
|
className="text-ui-fg-muted hover:text-ui-fg-subtle" |
|
41
|
asChild |
|
42
|
> |
|
43
|
<Link to={href}> |
|
44
|
<ArrowUpRightOnBox /> |
|
45
|
</Link> |
|
46
|
</IconButton> |
|
47
|
</Container> |
|
48
|
) |
|
49
|
} |