2020-07-03 08:26:04 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import {
|
|
|
|
|
Popover,
|
|
|
|
|
Classes,
|
|
|
|
|
PopoverInteractionKind,
|
|
|
|
|
Position,
|
|
|
|
|
Icon,
|
2020-07-20 06:04:05 +00:00
|
|
|
Tooltip,
|
2020-07-03 08:26:04 +00:00
|
|
|
} from "@blueprintjs/core";
|
|
|
|
|
import { IconWrapper } from "constants/IconConstants";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
2020-07-14 07:40:52 +00:00
|
|
|
import { ReactComponent as VisibleIcon } from "assets/icons/control/columns-visibility.svg";
|
2020-07-03 08:26:04 +00:00
|
|
|
import Button from "components/editorComponents/Button";
|
2020-08-10 11:16:13 +00:00
|
|
|
import { ReactTableColumnProps } from "widgets/TableWidget";
|
2020-07-20 06:04:05 +00:00
|
|
|
import { TableIconWrapper } from "components/designSystems/appsmith/TableStyledWrappers";
|
2020-07-03 08:26:04 +00:00
|
|
|
|
|
|
|
|
const DropDownWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
background: white;
|
|
|
|
|
z-index: 1;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
border: 1px solid ${Colors.ATHENS_GRAY};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const OptionWrapper = styled.div<{ selected: boolean }>`
|
|
|
|
|
display: flex;
|
|
|
|
|
width: calc(100% - 20px);
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
height: 32px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
color: ${Colors.OXFORD_BLUE};
|
|
|
|
|
opacity: ${props => (props.selected ? 1 : 0.7)};
|
|
|
|
|
min-width: 200px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
margin: 10px 10px 0 10px;
|
|
|
|
|
background: ${Colors.WHITE};
|
|
|
|
|
.option-title {
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
line-height: 24px;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ButtonWrapper = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
width: 100%;
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
align-items; center;
|
|
|
|
|
height: 40px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
min-width: 224px;
|
|
|
|
|
padding: 5px 15px;
|
|
|
|
|
background: ${Colors.WHITE};
|
|
|
|
|
box-shadow: 0px -1px 2px rgba(67, 70, 74, 0.12);
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface TableColumnsVisibilityProps {
|
|
|
|
|
columns: ReactTableColumnProps[];
|
|
|
|
|
hiddenColumns?: string[];
|
|
|
|
|
updateHiddenColumns: (hiddenColumns?: string[]) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 07:40:52 +00:00
|
|
|
const VisibilityIcon = (props: { visible?: boolean }) => {
|
|
|
|
|
return props.visible ? (
|
|
|
|
|
<Icon icon="eye-open" iconSize={20} color={Colors.OXFORD_BLUE} />
|
|
|
|
|
) : (
|
|
|
|
|
<VisibleIcon />
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-03 08:26:04 +00:00
|
|
|
const TableColumnsVisibility = (props: TableColumnsVisibilityProps) => {
|
|
|
|
|
const [selected, selectMenu] = React.useState(false);
|
2020-07-14 07:40:52 +00:00
|
|
|
if (props.columns.length === 0) {
|
|
|
|
|
return (
|
|
|
|
|
<TableIconWrapper disabled>
|
|
|
|
|
<IconWrapper width={20} height={20} color={Colors.CADET_BLUE}>
|
|
|
|
|
<VisibilityIcon />
|
|
|
|
|
</IconWrapper>
|
|
|
|
|
</TableIconWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
const columns = props.columns.sort(
|
|
|
|
|
(a: ReactTableColumnProps, b: ReactTableColumnProps) => {
|
|
|
|
|
return a.accessor > b.accessor ? 1 : b.accessor > a.accessor ? -1 : 0;
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-07-03 08:26:04 +00:00
|
|
|
return (
|
|
|
|
|
<Popover
|
|
|
|
|
minimal
|
|
|
|
|
usePortal
|
|
|
|
|
enforceFocus={false}
|
|
|
|
|
interactionKind={PopoverInteractionKind.CLICK}
|
|
|
|
|
position={Position.BOTTOM}
|
|
|
|
|
onClose={() => {
|
|
|
|
|
selectMenu(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TableIconWrapper
|
|
|
|
|
selected={selected}
|
2020-07-14 07:40:52 +00:00
|
|
|
onClick={e => {
|
2020-07-03 08:26:04 +00:00
|
|
|
selectMenu(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-07-20 06:04:05 +00:00
|
|
|
<Tooltip
|
|
|
|
|
autoFocus={false}
|
|
|
|
|
hoverOpenDelay={1000}
|
|
|
|
|
content="Hidden Fields"
|
|
|
|
|
position="top"
|
2020-07-03 08:26:04 +00:00
|
|
|
>
|
2020-07-20 06:04:05 +00:00
|
|
|
<IconWrapper
|
|
|
|
|
width={20}
|
|
|
|
|
height={20}
|
|
|
|
|
color={selected ? Colors.OXFORD_BLUE : Colors.CADET_BLUE}
|
|
|
|
|
>
|
|
|
|
|
<VisibilityIcon />
|
|
|
|
|
</IconWrapper>
|
|
|
|
|
</Tooltip>
|
2020-07-03 08:26:04 +00:00
|
|
|
</TableIconWrapper>
|
|
|
|
|
<DropDownWrapper>
|
2020-07-14 07:40:52 +00:00
|
|
|
{columns.map((option: ReactTableColumnProps, index: number) => (
|
2020-07-03 08:26:04 +00:00
|
|
|
<OptionWrapper
|
|
|
|
|
selected={!option.isHidden}
|
|
|
|
|
key={index}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
const hiddenColumns = props.hiddenColumns || [];
|
|
|
|
|
if (!option.isHidden) {
|
|
|
|
|
hiddenColumns.push(option.accessor);
|
2020-07-14 07:40:52 +00:00
|
|
|
} else {
|
|
|
|
|
hiddenColumns.splice(hiddenColumns.indexOf(option.accessor), 1);
|
2020-07-03 08:26:04 +00:00
|
|
|
}
|
|
|
|
|
props.updateHiddenColumns(hiddenColumns);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="option-title">{option.Header}</div>
|
2020-07-14 07:40:52 +00:00
|
|
|
<VisibilityIcon visible={!option.isHidden} />
|
2020-07-03 08:26:04 +00:00
|
|
|
</OptionWrapper>
|
|
|
|
|
))}
|
|
|
|
|
<ButtonWrapper className={Classes.POPOVER_DISMISS}>
|
|
|
|
|
<Button
|
|
|
|
|
intent="primary"
|
|
|
|
|
text="Show All"
|
|
|
|
|
filled
|
|
|
|
|
size="small"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
props.updateHiddenColumns([]);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</ButtonWrapper>
|
|
|
|
|
</DropDownWrapper>
|
|
|
|
|
</Popover>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TableColumnsVisibility;
|