2020-07-02 06:26:01 +00:00
|
|
|
import React from "react";
|
2020-07-03 08:32:21 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { Icon, NumericInput } from "@blueprintjs/core";
|
|
|
|
|
import SearchComponent from "components/designSystems/appsmith/SearchComponent";
|
|
|
|
|
import TableColumnsVisibility from "components/designSystems/appsmith/TableColumnsVisibility";
|
|
|
|
|
import { ReactTableColumnProps } from "components/designSystems/appsmith/ReactTableComponent";
|
2020-07-02 06:26:01 +00:00
|
|
|
import {
|
2020-07-03 08:32:21 +00:00
|
|
|
RowWrapper,
|
2020-07-02 06:26:01 +00:00
|
|
|
PaginationWrapper,
|
|
|
|
|
TableHeaderWrapper,
|
|
|
|
|
PaginationItemWrapper,
|
2020-07-03 08:26:04 +00:00
|
|
|
CommonFunctionsMenuWrapper,
|
2020-07-02 06:26:01 +00:00
|
|
|
} from "./TableStyledWrappers";
|
2020-07-03 08:32:21 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
|
|
|
|
|
const PageNumberInputWrapper = styled(NumericInput)`
|
|
|
|
|
&&& input {
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
background: linear-gradient(0deg, ${Colors.WHITE}, ${Colors.WHITE}),
|
|
|
|
|
${Colors.POLAR};
|
|
|
|
|
border: 1px solid ${Colors.GREEN};
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
width: 32px;
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
margin: 0 8px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const PageNumberInput = (props: {
|
|
|
|
|
pageNo: number;
|
|
|
|
|
pageCount: number;
|
|
|
|
|
updatePageNo: Function;
|
|
|
|
|
}) => {
|
|
|
|
|
return (
|
|
|
|
|
<PageNumberInputWrapper
|
2020-07-06 13:35:31 +00:00
|
|
|
value={props.pageNo || 0}
|
2020-07-03 08:32:21 +00:00
|
|
|
min={1}
|
2020-07-03 11:03:56 +00:00
|
|
|
max={props.pageCount || 1}
|
2020-07-03 08:32:21 +00:00
|
|
|
buttonPosition="none"
|
|
|
|
|
clampValueOnBlur={true}
|
|
|
|
|
onValueChange={(value: number) => {
|
|
|
|
|
if (isNaN(value) || value < 1) {
|
|
|
|
|
props.updatePageNo(1);
|
|
|
|
|
} else if (value > props.pageCount) {
|
|
|
|
|
props.updatePageNo(props.pageCount);
|
|
|
|
|
} else {
|
|
|
|
|
props.updatePageNo(value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
2020-07-02 06:26:01 +00:00
|
|
|
|
|
|
|
|
interface TableHeaderProps {
|
|
|
|
|
updatePageNo: Function;
|
|
|
|
|
nextPageClick: () => void;
|
|
|
|
|
prevPageClick: () => void;
|
|
|
|
|
pageNo: number;
|
|
|
|
|
pageCount: number;
|
|
|
|
|
currentPageIndex: number;
|
|
|
|
|
pageOptions: number[];
|
2020-07-03 08:26:04 +00:00
|
|
|
columns: ReactTableColumnProps[];
|
|
|
|
|
hiddenColumns?: string[];
|
|
|
|
|
updateHiddenColumns: (hiddenColumns?: string[]) => void;
|
|
|
|
|
searchKey: string;
|
|
|
|
|
searchTableData: (searchKey: any) => void;
|
2020-07-02 06:26:01 +00:00
|
|
|
serverSidePaginationEnabled: boolean;
|
2020-07-14 07:40:52 +00:00
|
|
|
displayColumnActions: boolean;
|
2020-07-02 06:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TableHeader = (props: TableHeaderProps) => {
|
|
|
|
|
return (
|
|
|
|
|
<TableHeaderWrapper>
|
2020-07-03 08:26:04 +00:00
|
|
|
<SearchComponent
|
|
|
|
|
value={props.searchKey}
|
|
|
|
|
placeholder="Search..."
|
|
|
|
|
onSearch={props.searchTableData}
|
|
|
|
|
/>
|
|
|
|
|
<CommonFunctionsMenuWrapper>
|
2020-07-14 07:40:52 +00:00
|
|
|
{props.displayColumnActions && (
|
|
|
|
|
<TableColumnsVisibility
|
|
|
|
|
columns={props.columns}
|
|
|
|
|
hiddenColumns={props.hiddenColumns}
|
|
|
|
|
updateHiddenColumns={props.updateHiddenColumns}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-07-03 08:26:04 +00:00
|
|
|
</CommonFunctionsMenuWrapper>
|
2020-07-02 06:26:01 +00:00
|
|
|
{props.serverSidePaginationEnabled && (
|
|
|
|
|
<PaginationWrapper>
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={false}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.prevPageClick();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-07-03 08:32:21 +00:00
|
|
|
<Icon icon="chevron-left" iconSize={16} color={Colors.HIT_GRAY} />
|
2020-07-02 06:26:01 +00:00
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
<PaginationItemWrapper selected className="page-item">
|
|
|
|
|
{props.pageNo + 1}
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={false}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.nextPageClick();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-07-03 08:32:21 +00:00
|
|
|
<Icon icon="chevron-right" iconSize={16} color={Colors.HIT_GRAY} />
|
2020-07-02 06:26:01 +00:00
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
</PaginationWrapper>
|
|
|
|
|
)}
|
|
|
|
|
{!props.serverSidePaginationEnabled && (
|
|
|
|
|
<PaginationWrapper>
|
2020-07-03 08:32:21 +00:00
|
|
|
<RowWrapper>
|
|
|
|
|
Showing {props.currentPageIndex + 1}-{props.pageCount} items
|
|
|
|
|
</RowWrapper>
|
2020-07-02 06:26:01 +00:00
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={props.currentPageIndex === 0}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const pageNo =
|
|
|
|
|
props.currentPageIndex > 0 ? props.currentPageIndex - 1 : 0;
|
|
|
|
|
props.updatePageNo(pageNo + 1);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-07-03 08:32:21 +00:00
|
|
|
<Icon icon="chevron-left" iconSize={16} color={Colors.HIT_GRAY} />
|
2020-07-02 06:26:01 +00:00
|
|
|
</PaginationItemWrapper>
|
2020-07-03 08:32:21 +00:00
|
|
|
<RowWrapper>
|
|
|
|
|
Page{" "}
|
|
|
|
|
<PageNumberInput
|
|
|
|
|
pageNo={props.pageNo + 1}
|
|
|
|
|
updatePageNo={props.updatePageNo}
|
|
|
|
|
pageCount={props.pageCount}
|
|
|
|
|
/>{" "}
|
|
|
|
|
of {props.pageCount}
|
|
|
|
|
</RowWrapper>
|
2020-07-02 06:26:01 +00:00
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={props.currentPageIndex === props.pageCount - 1}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const pageNo =
|
|
|
|
|
props.currentPageIndex < props.pageCount - 1
|
|
|
|
|
? props.currentPageIndex + 1
|
|
|
|
|
: 0;
|
|
|
|
|
props.updatePageNo(pageNo + 1);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-07-03 08:32:21 +00:00
|
|
|
<Icon icon="chevron-right" iconSize={16} color={Colors.HIT_GRAY} />
|
2020-07-02 06:26:01 +00:00
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
</PaginationWrapper>
|
|
|
|
|
)}
|
|
|
|
|
</TableHeaderWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TableHeader;
|