2020-07-02 06:26:01 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import {
|
|
|
|
|
PaginationWrapper,
|
|
|
|
|
TableHeaderWrapper,
|
|
|
|
|
PaginationItemWrapper,
|
2020-07-03 08:26:04 +00:00
|
|
|
CommonFunctionsMenuWrapper,
|
2020-07-02 06:26:01 +00:00
|
|
|
} from "./TableStyledWrappers";
|
|
|
|
|
import { Icon } from "@blueprintjs/core";
|
2020-07-03 08:26:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TableHeader = (props: TableHeaderProps) => {
|
|
|
|
|
return (
|
|
|
|
|
<TableHeaderWrapper>
|
2020-07-03 08:26:04 +00:00
|
|
|
<SearchComponent
|
|
|
|
|
value={props.searchKey}
|
|
|
|
|
placeholder="Search..."
|
|
|
|
|
onSearch={props.searchTableData}
|
|
|
|
|
/>
|
|
|
|
|
<CommonFunctionsMenuWrapper>
|
|
|
|
|
<TableColumnsVisibility
|
|
|
|
|
columns={props.columns}
|
|
|
|
|
hiddenColumns={props.hiddenColumns}
|
|
|
|
|
updateHiddenColumns={props.updateHiddenColumns}
|
|
|
|
|
/>
|
|
|
|
|
</CommonFunctionsMenuWrapper>
|
2020-07-02 06:26:01 +00:00
|
|
|
{props.serverSidePaginationEnabled && (
|
|
|
|
|
<PaginationWrapper>
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={false}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.prevPageClick();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="chevron-left" iconSize={16} color="#A1ACB3" />
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
<PaginationItemWrapper selected className="page-item">
|
|
|
|
|
{props.pageNo + 1}
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={false}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.nextPageClick();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="chevron-right" iconSize={16} color="#A1ACB3" />
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
</PaginationWrapper>
|
|
|
|
|
)}
|
|
|
|
|
{!props.serverSidePaginationEnabled && (
|
|
|
|
|
<PaginationWrapper>
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={props.currentPageIndex === 0}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const pageNo =
|
|
|
|
|
props.currentPageIndex > 0 ? props.currentPageIndex - 1 : 0;
|
|
|
|
|
props.updatePageNo(pageNo + 1);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="chevron-left" iconSize={16} color="#A1ACB3" />
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
{props.pageOptions.map((pageNumber: number, index: number) => {
|
|
|
|
|
return (
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
key={index}
|
|
|
|
|
selected={pageNumber === props.currentPageIndex}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.updatePageNo(pageNumber + 1);
|
|
|
|
|
}}
|
|
|
|
|
className="page-item"
|
|
|
|
|
>
|
|
|
|
|
{index + 1}
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
<PaginationItemWrapper
|
|
|
|
|
disabled={props.currentPageIndex === props.pageCount - 1}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const pageNo =
|
|
|
|
|
props.currentPageIndex < props.pageCount - 1
|
|
|
|
|
? props.currentPageIndex + 1
|
|
|
|
|
: 0;
|
|
|
|
|
props.updatePageNo(pageNo + 1);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="chevron-right" iconSize={16} color="#A1ACB3" />
|
|
|
|
|
</PaginationItemWrapper>
|
|
|
|
|
</PaginationWrapper>
|
|
|
|
|
)}
|
|
|
|
|
</TableHeaderWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TableHeader;
|