saleor-dashboard/src/components/TablePagination/TablePagination.tsx

125 lines
3 KiB
TypeScript
Raw Normal View History

import { TableCell, Toolbar } from "@material-ui/core";
2019-06-19 14:40:52 +00:00
import { IconButtonProps } from "@material-ui/core/IconButton";
2019-08-09 11:14:35 +00:00
import RowNumberSelect from "@saleor/components/RowNumberSelect";
import { maybe } from "@saleor/misc";
import { makeStyles } from "@saleor/theme";
import React from "react";
2019-08-09 11:14:35 +00:00
import { ListSettings } from "../../types";
2019-06-19 14:40:52 +00:00
import TablePaginationActions from "./TablePaginationActions";
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
actions: {
color: theme.palette.text.secondary,
flexShrink: 0,
marginLeft: theme.spacing(2.5)
},
caption: {
flexShrink: 0
},
input: {
flexShrink: 0,
fontSize: "inherit"
},
root: {
"&:last-child": {
padding: 0
}
},
select: {
paddingLeft: theme.spacing(),
paddingRight: theme.spacing(2)
},
selectIcon: {
top: 1
},
selectRoot: {
color: theme.palette.text.secondary,
marginLeft: theme.spacing(),
marginRight: theme.spacing(4)
},
spacer: {
flex: "1 1 100%"
},
toolbar: {
height: 56,
minHeight: 56,
paddingLeft: 2,
paddingRight: 2
2019-06-19 14:40:52 +00:00
}
2019-12-03 15:28:40 +00:00
}),
{ name: "TablePagination" }
);
2019-06-19 14:40:52 +00:00
2021-06-15 15:15:14 +00:00
export type ListSettingsUpdate = <T extends keyof ListSettings>(
key: T,
value: ListSettings[T]
) => void;
2019-10-30 14:34:24 +00:00
interface TablePaginationProps {
2019-06-19 14:40:52 +00:00
backIconButtonProps?: Partial<IconButtonProps>;
colSpan: number;
component?: string | typeof TableCell;
2019-08-09 11:14:35 +00:00
settings?: ListSettings;
2019-06-19 14:40:52 +00:00
hasNextPage: boolean;
hasPreviousPage: boolean;
nextIconButtonProps?: Partial<IconButtonProps>;
2021-06-15 15:15:14 +00:00
onUpdateListSettings?: ListSettingsUpdate;
2019-06-19 14:40:52 +00:00
onNextPage(event);
onPreviousPage(event);
}
2019-10-30 14:34:24 +00:00
const TablePagination: React.FC<TablePaginationProps> = props => {
const {
2019-06-19 14:40:52 +00:00
backIconButtonProps,
colSpan: colSpanProp,
component: Component,
2019-08-09 11:14:35 +00:00
settings,
2019-06-19 14:40:52 +00:00
hasNextPage,
hasPreviousPage,
nextIconButtonProps,
onNextPage,
onPreviousPage,
2019-08-09 11:14:35 +00:00
onUpdateListSettings,
2019-06-19 14:40:52 +00:00
...other
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
let colSpan;
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
if (Component === TableCell || Component === "td") {
colSpan = colSpanProp || 1000;
2019-06-19 14:40:52 +00:00
}
2019-10-30 14:34:24 +00:00
return (
<Component className={classes.root} colSpan={colSpan} {...other}>
<Toolbar className={classes.toolbar}>
<div className={classes.spacer}>
{maybe(() => settings.rowNumber) && (
<RowNumberSelect
Apps (#599) * create Apps view * create more app components, generate types and messages * apps refactor, update snapshots * show error message in tooltip when app installation fail * update apps components and view, add apps list to storybook * update defaultMessages * create app details view * update AppListPage with Skeleton component * create app activate/deactivate dialogs, create app details stories * add AppHeader to AppDetailsPage * update defaultMessages * update AppDetails view and components after review * create custom app details view * refactor webhooks * update webhooks fixtures * update WebhookDetailsPage story * update strings * create CustomAppCreate view and components * update AppListPage story * create AppInstall view and page * handle errors in AppInstall view * update defaultMessages * add AppInstallPage to storybook * add status prop to MessageManager * update defaultMessages * remove service account section * remove service account routes * remove as operator from notify status * add notifications for app installations * update styles for deactivated app * update app installations with local storage * update defaultMessages * AppInstall update * dd delete button to ongoin installations table * fix active installations condition * fix error messages in AppsList * update defaultMessages * add iframe to AppDetailsPage * create AppDetailsSettingsPage * install macaw-ui * apps styles clean up * update schema, fixtures * few apps updates * WebhookCreate - fix onBack button name * WebhookCreatePage story update * rename apps table from external to thirdparty * update defaultMessages * fix test, update snapshots * AppDetailsSettings - add token to headers * fix first number in local apps query * app details settings - use shop domain host * add onSettingsRowClick to InstalledApps * resolve conflicts * update changelog and messages * add noopener noreferrer do app privacy link * update snapshots * update snapshots * updates after review * update defaultMessages * CustomAppDetails - add missing notify status
2020-07-22 10:54:15 +00:00
choices={[10, 20, 30, 50, 100]}
2021-06-15 15:15:14 +00:00
rowNumber={settings.rowNumber}
onChange={value => onUpdateListSettings("rowNumber", value)}
2019-10-30 14:34:24 +00:00
/>
)}
</div>
<TablePaginationActions
backIconButtonProps={backIconButtonProps}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
nextIconButtonProps={nextIconButtonProps}
onNextPage={onNextPage}
onPreviousPage={onPreviousPage}
/>
</Toolbar>
</Component>
);
};
2019-06-19 14:40:52 +00:00
TablePagination.defaultProps = {
component: TableCell
};
TablePagination.displayName = "TablePagination";
export default TablePagination;