Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Cannot read property 'onSort' of undefined #813

Merged
merged 2 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/TableHeadingCellContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DefaultTableHeadingCellContent = ({title, icon, iconClassName}) => (

const EnhancedHeadingCell = OriginalComponent => compose(
getContext({
events: PropTypes.object,
selectors: PropTypes.object,
}),
connect(
Expand Down
74 changes: 3 additions & 71 deletions src/plugins/local/components/TableHeadingCellContainer.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from '../../../utils/griddleConnect';
import compose from 'recompose/compose';
import mapProps from 'recompose/mapProps';
import getContext from 'recompose/getContext';
import withHandlers from 'recompose/withHandlers';
import { sortPropertyByIdSelector, iconsForComponentSelector, customHeadingComponentSelector, stylesForComponentSelector, classNamesForComponentSelector, cellPropertiesSelector } from '../../../selectors/dataSelectors';
import { setSortColumn } from '../../../actions';
import { combineHandlers } from '../../../utils/compositionUtils';
import { getSortIconProps, setSortProperties } from '../../../utils/sortUtils';
import { valueOrResult } from '../../../utils/valueUtils';
import TableHeadingCellContainer from '../../../components/TableHeadingCellContainer';

const DefaultTableHeadingCellContent = ({title, icon, iconClassName}) => (
<span>
{ title }
{ icon && <span className={iconClassName}>{icon}</span> }
</span>
)

const EnhancedHeadingCell = OriginalComponent => compose(
getContext({
events: PropTypes.object,
}),
connect(
(state, props) => ({
sortProperty: sortPropertyByIdSelector(state, props),
customHeadingComponent: customHeadingComponentSelector(state, props),
cellProperties: cellPropertiesSelector(state, props),
className: classNamesForComponentSelector(state, 'TableHeadingCell'),
sortAscendingClassName: classNamesForComponentSelector(state, 'TableHeadingCellAscending'),
sortDescendingClassName: classNamesForComponentSelector(state, 'TableHeadingCellDescending'),
style: stylesForComponentSelector(state, 'TableHeadingCell'),
...iconsForComponentSelector(state, 'TableHeadingCell'),
}),
(dispatch, { events: { onSort } }) => ({
setSortColumn: combineHandlers([
onSort,
compose(dispatch, setSortColumn),
]),
})
),
withHandlers(props => ({
onClick: props.cellProperties.sortable === false ? (() => () => {}) :
props.events.setSortProperties || setSortProperties,
})),
//TODO: use with props on change or something more performant here
mapProps(props => {
const iconProps = getSortIconProps(props);
const title = props.customHeadingComponent ?
<props.customHeadingComponent {...props.cellProperties.extraData} {...props} {...iconProps} /> :
<DefaultTableHeadingCellContent title={props.title} {...iconProps} />;
const className = valueOrResult(props.cellProperties.headerCssClassName, props) || props.className;
const style = {
...(props.cellProperties.sortable === false || { cursor: 'pointer' }),
...props.style,
};

return {
...props.cellProperties.extraData,
...props,
...iconProps,
title,
style,
className
};
})
)(props =>
<OriginalComponent
{...props}
/>
);
// Obsolete
const EnhancedHeadingCell = TableHeadingCellContainer;

export default EnhancedHeadingCell;
2 changes: 1 addition & 1 deletion src/plugins/local/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export default {
PreviousButtonContainer,
PageDropdownContainer,
TableContainer,
TableHeadingCellContainer,
TableHeadingCellContainer, // TODO: Obsolete; remove
};