import { Card, CardActions, CardContent, Table, TableBody, TableCell, TableHead, TableRow, TextField, Typography, } from "@material-ui/core"; import { Button } from "@saleor/components/Button"; import { MetadataInput } from "@saleor/graphql"; import { FormChange } from "@saleor/hooks/useForm"; import { DeleteIcon, ExpandIcon, IconButton } from "@saleor/macaw-ui"; import classNames from "classnames"; import React, { useEffect } from "react"; import { FormattedMessage, useIntl } from "react-intl"; import CardTitle from "../CardTitle"; import Skeleton from "../Skeleton"; import useStyles from "./styles"; import { EventDataAction, EventDataField } from "./types"; export interface MetadataCardProps { data: MetadataInput[]; isPrivate: boolean; onChange: FormChange; } export const nameSeparator = ":"; export const nameInputPrefix = EventDataField.name; export const valueInputPrefix = EventDataField.value; const MetadataCard: React.FC = ({ data, isPrivate, onChange, }) => { const intl = useIntl(); const loaded = React.useRef(false); const [expanded, setExpanded] = React.useState(true); const classes = useStyles({}); useEffect(() => { if (data !== undefined) { loaded.current = true; if (data.length > 0) { setExpanded(false); } } }, [data === undefined]); return ( {isPrivate ? intl.formatMessage({ id: "ETHnjq", defaultMessage: "Private Metadata", description: "header", }) : intl.formatMessage({ id: "VcI+Zh", defaultMessage: "Metadata", description: "header", })} setExpanded(!expanded)} > } /> {data === undefined ? ( ) : ( <> {data.length > 0 && ( )} {expanded && ( <> {data.length === 0 ? ( ) : ( {data.map((field, fieldIndex) => ( onChange({ target: { name: EventDataAction.delete, value: fieldIndex, }, }) } > ))}
)} )} )}
); }; MetadataCard.displayName = "MetadataCard"; export default MetadataCard;