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

onSort with *correct* sortProperties #749

Merged
merged 4 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 14 additions & 2 deletions src/components/TableHeadingCellContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ 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, classNamesForComponentSelector, stylesForComponentSelector, customHeadingComponentSelector, cellPropertiesSelector } from '../selectors/dataSelectors';
import { getSortIconProps } from '../utils/sortUtils';
import { setSortColumn } from '../actions';
import { combineHandlers } from '../utils/compositionUtils';
import { getSortIconProps, setSortProperties } from '../utils/sortUtils';
import { valueOrResult } from '../utils/valueUtils';

const DefaultTableHeadingCellContent = ({title, icon}) => (
Expand All @@ -28,8 +30,18 @@ const EnhancedHeadingCell = OriginalComponent => compose(
className: classNamesForComponentSelector(state, 'TableHeadingCell'),
style: stylesForComponentSelector(state, 'TableHeadingCell'),
...iconsForComponentSelector(state, 'TableHeadingCell'),
}),
(dispatch, { events: { onSort } }) => ({
setSortColumn: combineHandlers([
onSort,
sp => dispatch(setSortColumn(sp)),
]),
})
),
withHandlers(props => ({
onClick: props.cellProperties.sortable === false ? (() => () => {}) :
props.events.setSortProperties || setSortProperties,
})),
mapProps(props => {
const iconProps = getSortIconProps(props);
const title = props.customHeadingComponent ?
Expand Down
21 changes: 2 additions & 19 deletions src/components/TableHeadingCellEnhancer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import compose from 'recompose/compose';
import mapProps from 'recompose/mapProps';
import getContext from 'recompose/getContext';
import { combineHandlers } from '../utils/compositionUtils';

const EnhancedHeadingCell = OriginalComponent => compose(
getContext({
events: PropTypes.object,
}),
mapProps(({ events: { onSort }, ...props }) => ({
...props,
onClick: combineHandlers([
() => onSort && onSort(props.sortProperty || { id: props.columnId }),
props.onClick,
]),
}))
)(props => <OriginalComponent {...props} />);
// Obsolete
const EnhancedHeadingCell = OriginalComponent => OriginalComponent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, but it's technically a breaking change. Glad to remove if you're not concerned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double confirm - we're leaving this here to avoid causing a potential breaking change right? I think we're maybe just outside the realm of where a 2.0 release makes sense. If I'm understanding correctly, we can leave this here for now to avoid breaking change and remove the obsolete field in a 2.0 version.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I left it as a no-op to be cleaned up for a 2.0 release.

The chances someone is actually depending on this seem quite low, but it's been exported as part of the public API.


export default EnhancedHeadingCell;
10 changes: 7 additions & 3 deletions src/plugins/local/components/TableHeadingCellContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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';

Expand All @@ -32,9 +33,12 @@ const EnhancedHeadingCell = OriginalComponent => compose(
style: stylesForComponentSelector(state, 'TableHeadingCell'),
...iconsForComponentSelector(state, 'TableHeadingCell'),
}),
{
setSortColumn
}
(dispatch, { events: { onSort } }) => ({
setSortColumn: combineHandlers([
onSort,
sp => dispatch(setSortColumn(sp)),
]),
})
),
withHandlers(props => ({
onClick: props.cellProperties.sortable === false ? (() => () => {}) :
Expand Down
2 changes: 1 addition & 1 deletion stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ storiesOf('TypeScript', module)
.add('GriddleComponent accepts expected types', () => {
class Custom extends React.Component<{ value }> {
render() {
return this.props.value;
return <strong>{this.props.value}</strong>;
}
}

Expand Down