2019-09-25 14:11:45 +00:00
|
|
|
import IconButton from "@material-ui/core/IconButton";
|
2019-10-30 14:34:24 +00:00
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
2019-09-25 14:11:45 +00:00
|
|
|
import TableBody from "@material-ui/core/TableBody";
|
|
|
|
import TableCell from "@material-ui/core/TableCell";
|
|
|
|
import TableFooter from "@material-ui/core/TableFooter";
|
2019-09-27 12:21:38 +00:00
|
|
|
import TableHead from "@material-ui/core/TableHead";
|
2019-09-25 14:11:45 +00:00
|
|
|
import TableRow from "@material-ui/core/TableRow";
|
|
|
|
import Typography from "@material-ui/core/Typography";
|
|
|
|
import DeleteIcon from "@material-ui/icons/Delete";
|
|
|
|
import EditIcon from "@material-ui/icons/Edit";
|
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage } from "react-intl";
|
|
|
|
|
2019-11-04 14:25:23 +00:00
|
|
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
2019-09-25 14:11:45 +00:00
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
|
|
import TablePagination from "@saleor/components/TablePagination";
|
2019-09-27 13:57:54 +00:00
|
|
|
import { maybe, renderCollection, stopPropagation } from "@saleor/misc";
|
2019-09-27 12:21:38 +00:00
|
|
|
import { ListProps } from "@saleor/types";
|
2019-09-25 14:11:45 +00:00
|
|
|
import { ServiceList_serviceAccounts_edges_node } from "../../types/ServiceList";
|
|
|
|
|
2019-09-27 12:21:38 +00:00
|
|
|
export interface ServiceListProps extends ListProps {
|
2019-09-25 14:11:45 +00:00
|
|
|
services: ServiceList_serviceAccounts_edges_node[];
|
|
|
|
onRemove: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
[theme.breakpoints.up("lg")]: {
|
|
|
|
colName: {
|
|
|
|
"&&": {
|
|
|
|
width: "auto"
|
|
|
|
}
|
2019-10-30 14:34:24 +00:00
|
|
|
}
|
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
colAction: {
|
|
|
|
"&&": {
|
|
|
|
paddingRight: theme.spacing(1)
|
|
|
|
},
|
|
|
|
textAlign: "right",
|
|
|
|
width: 100
|
|
|
|
},
|
|
|
|
colName: {
|
|
|
|
paddingLeft: 0,
|
|
|
|
width: 250
|
|
|
|
},
|
|
|
|
table: {
|
|
|
|
tableLayout: "fixed"
|
|
|
|
},
|
|
|
|
tableRow: {
|
|
|
|
cursor: "pointer"
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{ name: "ServiceList" }
|
|
|
|
);
|
2019-09-25 14:11:45 +00:00
|
|
|
|
2019-09-27 12:21:38 +00:00
|
|
|
const numberOfColumns = 2;
|
2019-09-25 14:11:45 +00:00
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
const ServiceList: React.FC<ServiceListProps> = props => {
|
|
|
|
const {
|
2019-09-25 14:11:45 +00:00
|
|
|
settings,
|
|
|
|
disabled,
|
|
|
|
onNextPage,
|
|
|
|
onPreviousPage,
|
|
|
|
onUpdateListSettings,
|
|
|
|
onRemove,
|
|
|
|
onRowClick,
|
|
|
|
pageInfo,
|
2019-09-27 12:21:38 +00:00
|
|
|
services
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
return (
|
2019-11-04 14:25:23 +00:00
|
|
|
<ResponsiveTable className={classes.table}>
|
2019-09-27 12:21:38 +00:00
|
|
|
<TableHead>
|
2019-09-27 13:57:54 +00:00
|
|
|
<TableRow>
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Name"
|
|
|
|
description="service name"
|
|
|
|
/>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell />
|
|
|
|
</TableRow>
|
2019-09-25 14:11:45 +00:00
|
|
|
</TableHead>
|
|
|
|
<TableFooter>
|
|
|
|
<TableRow>
|
|
|
|
<TablePagination
|
|
|
|
colSpan={numberOfColumns}
|
|
|
|
settings={settings}
|
|
|
|
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
|
|
|
|
onNextPage={onNextPage}
|
|
|
|
onUpdateListSettings={onUpdateListSettings}
|
|
|
|
hasPreviousPage={
|
|
|
|
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
|
|
|
|
}
|
|
|
|
onPreviousPage={onPreviousPage}
|
|
|
|
/>
|
|
|
|
</TableRow>
|
|
|
|
</TableFooter>
|
|
|
|
<TableBody>
|
|
|
|
{renderCollection(
|
|
|
|
services,
|
2019-09-27 12:21:38 +00:00
|
|
|
service => (
|
|
|
|
<TableRow
|
|
|
|
className={!!service ? classes.tableRow : undefined}
|
|
|
|
hover={!!service}
|
|
|
|
key={service ? service.id : "skeleton"}
|
|
|
|
onClick={service ? onRowClick(service.id) : undefined}
|
|
|
|
>
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
<span data-tc="name">
|
|
|
|
{maybe<React.ReactNode>(() => service.name, <Skeleton />)}
|
|
|
|
</span>
|
|
|
|
<Typography data-tc="isActive" variant="caption">
|
|
|
|
{maybe(() =>
|
|
|
|
service.isActive ? (
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="active"
|
|
|
|
description="account status"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="inactive"
|
|
|
|
description="account status"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colAction}>
|
|
|
|
<IconButton
|
|
|
|
color="primary"
|
|
|
|
onClick={service ? onRowClick(service.id) : undefined}
|
|
|
|
>
|
|
|
|
<EditIcon />
|
|
|
|
</IconButton>
|
|
|
|
<IconButton
|
|
|
|
color="primary"
|
2019-09-27 13:57:54 +00:00
|
|
|
onClick={
|
|
|
|
service
|
|
|
|
? stopPropagation(() => onRemove(service.id))
|
|
|
|
: undefined
|
|
|
|
}
|
2019-09-27 12:21:38 +00:00
|
|
|
>
|
|
|
|
<DeleteIcon />
|
|
|
|
</IconButton>
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
),
|
2019-09-25 14:11:45 +00:00
|
|
|
() => (
|
|
|
|
<TableRow>
|
|
|
|
<TableCell colSpan={numberOfColumns}>
|
|
|
|
<FormattedMessage defaultMessage="No service accounts found" />
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</TableBody>
|
2019-11-04 14:25:23 +00:00
|
|
|
</ResponsiveTable>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
2019-09-25 14:11:45 +00:00
|
|
|
ServiceList.displayName = "ServiceList";
|
|
|
|
export default ServiceList;
|