saleor-dashboard/src/plugins/components/PluginsList/PluginsList.tsx

156 lines
4.9 KiB
TypeScript
Raw Normal View History

2019-08-21 14:30:56 +00:00
import Card from "@material-ui/core/Card";
import {
createStyles,
Theme,
withStyles,
WithStyles
} from "@material-ui/core/styles";
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
2019-09-02 11:24:21 +00:00
import TableHead from "@material-ui/core/TableHead";
2019-08-21 14:30:56 +00:00
import TableRow from "@material-ui/core/TableRow";
import EditIcon from "@material-ui/icons/Edit";
import React from "react";
2019-08-30 13:10:07 +00:00
import { useIntl } from "react-intl";
2019-08-21 14:30:56 +00:00
import Skeleton from "@saleor/components/Skeleton";
import StatusLabel from "@saleor/components/StatusLabel";
import TablePagination from "@saleor/components/TablePagination";
2019-08-30 13:10:07 +00:00
import { translateBoolean } from "@saleor/intl";
2019-08-21 14:30:56 +00:00
import { maybe, renderCollection } from "@saleor/misc";
import { ListProps } from "@saleor/types";
2019-08-28 14:53:57 +00:00
import { Plugins_plugins_edges_node } from "../../types/Plugins";
2019-08-21 14:30:56 +00:00
export interface PluginListProps extends ListProps {
2019-08-28 14:53:57 +00:00
plugins: Plugins_plugins_edges_node[];
2019-08-21 14:30:56 +00:00
}
const styles = (theme: Theme) =>
createStyles({
[theme.breakpoints.up("lg")]: {
colAction: {
"& svg": {
color: theme.palette.primary.main
2019-08-27 12:36:19 +00:00
},
textAlign: "right"
},
colActive: {},
colName: {}
2019-08-21 14:30:56 +00:00
},
colAction: {},
2019-08-27 12:36:19 +00:00
colActive: {},
colName: {},
2019-08-21 14:30:56 +00:00
link: {
cursor: "pointer"
}
});
const numberOfColumns = 4;
2019-08-26 17:08:32 +00:00
const PluginList = withStyles(styles, { name: "PluginList" })(
2019-08-21 14:30:56 +00:00
({
classes,
settings,
plugins,
disabled,
onNextPage,
pageInfo,
onRowClick,
onUpdateListSettings,
onPreviousPage
2019-08-21 14:30:56 +00:00
}: PluginListProps & WithStyles<typeof styles>) => {
2019-08-30 13:10:07 +00:00
const intl = useIntl();
2019-08-21 14:30:56 +00:00
return (
<Card>
<Table>
2019-09-02 11:24:21 +00:00
<TableHead>
2019-08-21 14:30:56 +00:00
<TableCell className={classes.colName} padding="dense">
2019-08-30 13:10:07 +00:00
{intl.formatMessage({
defaultMessage: "Name",
2019-08-30 14:15:32 +00:00
description: "plugin name"
2019-08-30 13:10:07 +00:00
})}
2019-08-21 14:30:56 +00:00
</TableCell>
<TableCell className={classes.colActive} padding="dense">
2019-08-30 13:10:07 +00:00
{intl.formatMessage({
defaultMessage: "Active",
2019-08-30 14:15:32 +00:00
description: "plugin status"
2019-08-30 13:10:07 +00:00
})}
2019-08-21 14:30:56 +00:00
</TableCell>
<TableCell className={classes.colAction} padding="dense">
2019-08-30 13:10:07 +00:00
{intl.formatMessage({
defaultMessage: "Action",
2019-08-30 14:15:32 +00:00
description: "user action bar"
2019-08-30 13:10:07 +00:00
})}
2019-08-21 14:30:56 +00:00
</TableCell>
</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(
plugins,
plugin => {
return (
<TableRow
hover={!!plugin}
className={!!plugin ? classes.link : undefined}
onClick={plugin ? onRowClick(plugin.id) : undefined}
key={plugin ? plugin.id : "skeleton"}
>
<TableCell className={classes.colName}>
{maybe<React.ReactNode>(() => plugin.name, <Skeleton />)}
</TableCell>
<TableCell className={classes.colActive}>
{maybe<React.ReactNode>(
() => (
<StatusLabel
2019-08-30 13:10:07 +00:00
label={translateBoolean(plugin.active, intl)}
2019-08-21 14:30:56 +00:00
status={plugin.active ? "success" : "error"}
/>
),
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colAction}>
<div onClick={plugin ? onRowClick(plugin.id) : undefined}>
<EditIcon />
</div>
</TableCell>
</TableRow>
);
},
() => (
<TableRow>
<TableCell colSpan={numberOfColumns}>
2019-08-30 13:10:07 +00:00
{intl.formatMessage({
2019-08-30 14:15:32 +00:00
defaultMessage: "No plugins found"
2019-08-30 13:10:07 +00:00
})}
2019-08-21 14:30:56 +00:00
</TableCell>
</TableRow>
)
)}
</TableBody>
</Table>
</Card>
);
}
);
PluginList.displayName = "PluginList";
export default PluginList;