diff --git a/examples/custom-components/TableViewCol.js b/examples/custom-components/TableViewCol.js index 4983734b2..7d286ae94 100644 --- a/examples/custom-components/TableViewCol.js +++ b/examples/custom-components/TableViewCol.js @@ -1,11 +1,11 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import Checkbox from '@material-ui/core/Checkbox'; -import Typography from '@material-ui/core/Typography'; import Button from '@material-ui/core/Button'; +import Checkbox from '@material-ui/core/Checkbox'; import FormControl from '@material-ui/core/FormControl'; -import FormGroup from '@material-ui/core/FormGroup'; import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormGroup from '@material-ui/core/FormGroup'; +import PropTypes from 'prop-types'; +import React from 'react'; +import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles( @@ -42,12 +42,12 @@ const useStyles = makeStyles( { name: 'MUIDataTableViewCol' }, ); -const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updateColumns }) => { +const TableViewCol = React.memo(({ columns, options, components = {}, onColumnUpdate, updateColumns }) => { const classes = useStyles(); const textLabels = options.textLabels.viewColumns; const CheckboxComponent = components.Checkbox || Checkbox; - const handleColChange = index => { + const handleColChange = index => () => { onColumnUpdate(index); }; @@ -85,7 +85,7 @@ const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updat root: classes.checkboxRoot, checked: classes.checked, }} - onChange={() => handleColChange(index)} + onChange={handleColChange(index)} checked={column.display === 'true'} value={column.name} /> @@ -98,7 +98,7 @@ const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updat ); -}; +}); TableViewCol.propTypes = { /** Columns used to describe table */ diff --git a/src/components/TableFilterList.js b/src/components/TableFilterList.js index f3b78f408..e9da83a4d 100644 --- a/src/components/TableFilterList.js +++ b/src/components/TableFilterList.js @@ -1,7 +1,7 @@ -import { makeStyles } from '@material-ui/core/styles'; import PropTypes from 'prop-types'; import React from 'react'; import TableFilterListItem from './TableFilterListItem'; +import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles( () => ({ @@ -18,7 +18,7 @@ const useStyles = makeStyles( { name: 'MUIDataTableFilterList' }, ); -const TableFilterList = ({ +const TableFilterList = React.memo(({ options, filterList, filterUpdate, @@ -31,7 +31,7 @@ const TableFilterList = ({ const classes = useStyles(); const { serverSide } = options; - const removeFilter = (index, filterValue, columnName, filterType, customFilterListUpdate = null) => { + const removeFilter = (index, filterValue, columnName, filterType, customFilterListUpdate = null) => () => { let removedFilter = filterValue; if (Array.isArray(removedFilter) && removedFilter.length === 0) { removedFilter = filterList[index]; @@ -57,7 +57,7 @@ const TableFilterList = ({ + onDelete={ removeFilter( index, item[customFilterItemIndex] || [], @@ -84,7 +84,7 @@ const TableFilterList = ({ removeFilter(index, data, columnNames[index].name, 'chip')} + onDelete={removeFilter(index, data, columnNames[index].name, 'chip')} className={classes.chip} itemKey={colIndex} index={index} @@ -117,7 +117,7 @@ const TableFilterList = ({ {serverSide && serverSideFilterList ? getFilterList(serverSideFilterList) : getFilterList(filterList)} ); -}; +}); TableFilterList.propTypes = { /** Data used to filter table against */ diff --git a/src/components/TableHeadCell.js b/src/components/TableHeadCell.js index c237aae99..e7e6c7b73 100644 --- a/src/components/TableHeadCell.js +++ b/src/components/TableHeadCell.js @@ -1,13 +1,14 @@ +import React, { useState } from 'react'; + import Button from '@material-ui/core/Button'; -import clsx from 'clsx'; import HelpIcon from '@material-ui/icons/Help'; import MuiTooltip from '@material-ui/core/Tooltip'; import PropTypes from 'prop-types'; -import React, { useState } from 'react'; import TableCell from '@material-ui/core/TableCell'; import TableSortLabel from '@material-ui/core/TableSortLabel'; -import useColumnDrop from '../hooks/useColumnDrop.js'; +import clsx from 'clsx'; import { makeStyles } from '@material-ui/core/styles'; +import useColumnDrop from '../hooks/useColumnDrop.js'; import { useDrag } from 'react-dnd'; const useStyles = makeStyles( @@ -64,7 +65,7 @@ const useStyles = makeStyles( { name: 'MUIDataTableHeadCell' }, ); -const TableHeadCell = ({ +const TableHeadCell = React.memo(({ cellHeaderProps = {}, children, colPosition, @@ -189,6 +190,14 @@ const TableHeadCell = ({ setSortTooltipOpen(false); }; + const handleSortTooltipOpen = (open) => () => { + setSortTooltipOpen(open); + }; + + const handleHintTooltipOpen = (open) => () => { + setHintTooltipOpen(open); + }; + return ( { @@ -208,8 +217,8 @@ const TableHeadCell = ({ title={getTooltipTitle()} placement="bottom" open={sortTooltipOpen} - onOpen={() => (dragging ? setSortTooltipOpen(false) : setSortTooltipOpen(true))} - onClose={() => setSortTooltipOpen(false)} + onOpen={handleSortTooltipOpen(!dragging)} + onClose={handleSortTooltipOpen(false)} classes={{ tooltip: classes.tooltip, popper: classes.mypopper, @@ -253,8 +262,8 @@ const TableHeadCell = ({ title={hint} placement={'bottom-end'} open={hintTooltipOpen} - onOpen={() => showHintTooltip()} - onClose={() => setHintTooltipOpen(false)} + onOpen={showHintTooltip} + onClose={handleHintTooltipOpen(false)} classes={{ tooltip: classes.tooltip, popper: classes.mypopper, @@ -267,7 +276,7 @@ const TableHeadCell = ({ )} ); -}; +}); TableHeadCell.propTypes = { /** Options used to describe table */ diff --git a/src/components/TableViewCol.js b/src/components/TableViewCol.js index 1d2dccd1e..dcf87d850 100644 --- a/src/components/TableViewCol.js +++ b/src/components/TableViewCol.js @@ -1,10 +1,10 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import Checkbox from '@material-ui/core/Checkbox'; -import Typography from '@material-ui/core/Typography'; import FormControl from '@material-ui/core/FormControl'; -import FormGroup from '@material-ui/core/FormGroup'; import FormControlLabel from '@material-ui/core/FormControlLabel'; +import FormGroup from '@material-ui/core/FormGroup'; +import PropTypes from 'prop-types'; +import React from 'react'; +import Typography from '@material-ui/core/Typography'; import { makeStyles } from '@material-ui/core/styles'; const useStyles = makeStyles( @@ -41,12 +41,12 @@ const useStyles = makeStyles( { name: 'MUIDataTableViewCol' }, ); -const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updateColumns }) => { +const TableViewCol = React.memo(({ columns, options, components = {}, onColumnUpdate, updateColumns }) => { const classes = useStyles(); const textLabels = options.textLabels.viewColumns; const CheckboxComponent = components.Checkbox || Checkbox; - const handleColChange = index => { + const handleColChange = index => () => { onColumnUpdate(index); }; @@ -75,7 +75,7 @@ const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updat root: classes.checkboxRoot, checked: classes.checked, }} - onChange={() => handleColChange(index)} + onChange={handleColChange(index)} checked={column.display === 'true'} value={column.name} /> @@ -88,7 +88,7 @@ const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updat ); -}; +}); TableViewCol.propTypes = { /** Columns used to describe table */