2019-08-09 10:17:04 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import IconButton from "@material-ui/core/IconButton";
|
2019-10-28 16:16:49 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-08-09 10:17:04 +00:00
|
|
|
import Table from "@material-ui/core/Table";
|
|
|
|
import TableCell from "@material-ui/core/TableCell";
|
|
|
|
import TableHead from "@material-ui/core/TableHead";
|
|
|
|
import TableRow from "@material-ui/core/TableRow";
|
|
|
|
import DeleteIcon from "@material-ui/icons/Delete";
|
|
|
|
import React from "react";
|
2019-08-16 11:47:30 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-08-09 10:17:04 +00:00
|
|
|
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
|
|
import {
|
|
|
|
SortableTableBody,
|
|
|
|
SortableTableRow
|
|
|
|
} from "@saleor/components/SortableTable";
|
|
|
|
import { maybe, renderCollection, stopPropagation } from "@saleor/misc";
|
|
|
|
import { ReorderAction } from "@saleor/types";
|
|
|
|
import { AttributeDetailsFragment_values } from "../../types/AttributeDetailsFragment";
|
|
|
|
|
|
|
|
export interface AttributeValuesProps {
|
|
|
|
disabled: boolean;
|
|
|
|
values: AttributeDetailsFragment_values[];
|
|
|
|
onValueAdd: () => void;
|
|
|
|
onValueDelete: (id: string) => void;
|
|
|
|
onValueReorder: ReorderAction;
|
|
|
|
onValueUpdate: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
2019-10-28 16:16:49 +00:00
|
|
|
const useStyles = makeStyles(theme => ({
|
2019-08-09 10:17:04 +00:00
|
|
|
columnAdmin: {
|
|
|
|
width: "50%"
|
|
|
|
},
|
|
|
|
columnDrag: {
|
2019-10-28 16:16:49 +00:00
|
|
|
width: 48 + theme.spacing(1.5)
|
2019-08-09 10:17:04 +00:00
|
|
|
},
|
|
|
|
columnStore: {
|
|
|
|
width: "50%"
|
|
|
|
},
|
|
|
|
dragIcon: {
|
|
|
|
cursor: "grab"
|
|
|
|
},
|
|
|
|
iconCell: {
|
|
|
|
"&:last-child": {
|
2019-10-28 16:16:49 +00:00
|
|
|
paddingRight: theme.spacing()
|
2019-08-09 10:17:04 +00:00
|
|
|
},
|
2019-10-28 16:16:49 +00:00
|
|
|
width: 48 + theme.spacing(1.5)
|
2019-08-09 10:17:04 +00:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
cursor: "pointer"
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
const AttributeValues: React.FC<AttributeValuesProps> = ({
|
|
|
|
disabled,
|
|
|
|
onValueAdd,
|
|
|
|
onValueDelete,
|
|
|
|
onValueReorder,
|
|
|
|
onValueUpdate,
|
|
|
|
values
|
|
|
|
}) => {
|
|
|
|
const classes = useStyles({});
|
2019-08-16 11:47:30 +00:00
|
|
|
const intl = useIntl();
|
2019-08-09 10:17:04 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
2019-08-16 11:47:30 +00:00
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Attribute Values",
|
2019-08-22 16:25:55 +00:00
|
|
|
description: "section header"
|
2019-08-16 11:47:30 +00:00
|
|
|
})}
|
2019-08-09 10:17:04 +00:00
|
|
|
toolbar={
|
|
|
|
<Button color="primary" variant="text" onClick={onValueAdd}>
|
2019-08-16 11:47:30 +00:00
|
|
|
<FormattedMessage
|
2019-09-05 13:33:50 +00:00
|
|
|
defaultMessage="Assign value"
|
2019-09-11 14:24:24 +00:00
|
|
|
description="assign attribute value button"
|
2019-08-16 11:47:30 +00:00
|
|
|
/>
|
2019-08-09 10:17:04 +00:00
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Table>
|
|
|
|
<TableHead>
|
|
|
|
<TableRow>
|
|
|
|
<TableCell className={classes.columnDrag} />
|
|
|
|
<TableCell className={classes.columnAdmin}>
|
2019-08-16 11:47:30 +00:00
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Admin"
|
|
|
|
description="attribute values list: slug column header"
|
|
|
|
/>
|
2019-08-09 10:17:04 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.columnStore}>
|
2019-08-16 11:47:30 +00:00
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Default Store View"
|
|
|
|
description="attribute values list: name column header"
|
|
|
|
/>
|
2019-08-09 10:17:04 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell />
|
|
|
|
</TableRow>
|
|
|
|
</TableHead>
|
|
|
|
<SortableTableBody onSortEnd={onValueReorder}>
|
|
|
|
{renderCollection(
|
|
|
|
values,
|
|
|
|
(value, valueIndex) => (
|
|
|
|
<SortableTableRow
|
|
|
|
className={!!value ? classes.link : undefined}
|
|
|
|
hover={!!value}
|
|
|
|
onClick={!!value ? () => onValueUpdate(value.id) : undefined}
|
|
|
|
key={maybe(() => value.id)}
|
|
|
|
index={valueIndex || 0}
|
|
|
|
>
|
|
|
|
<TableCell className={classes.columnAdmin}>
|
|
|
|
{maybe(() => value.slug) ? value.slug : <Skeleton />}
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.columnStore}>
|
|
|
|
{maybe(() => value.name) ? value.name : <Skeleton />}
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.iconCell}>
|
|
|
|
<IconButton
|
|
|
|
disabled={disabled}
|
|
|
|
onClick={stopPropagation(() => onValueDelete(value.id))}
|
|
|
|
>
|
|
|
|
<DeleteIcon color="primary" />
|
|
|
|
</IconButton>
|
|
|
|
</TableCell>
|
|
|
|
</SortableTableRow>
|
|
|
|
),
|
|
|
|
() => (
|
|
|
|
<TableRow>
|
2019-08-16 11:47:30 +00:00
|
|
|
<TableCell colSpan={2}>
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="No values found"
|
|
|
|
description="No attribute values found"
|
|
|
|
/>
|
|
|
|
</TableCell>
|
2019-08-09 10:17:04 +00:00
|
|
|
</TableRow>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</SortableTableBody>
|
|
|
|
</Table>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
AttributeValues.displayName = "AttributeValues";
|
|
|
|
export default AttributeValues;
|