Skip to content

Commit

Permalink
feat(): Ability to sort lane by custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcdexta committed Feb 23, 2017
1 parent 4ff6d2b commit d81ae4f
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var _Card = require('./lib/Card');

var _Card2 = _interopRequireDefault(_Card);


function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.Board = _Board2.default;
Expand Down Expand Up @@ -265,17 +266,40 @@ var Lane = function (_Component) {
value: function componentWillReceiveProps(nextProps) {
this.setState({ cards: nextProps.cards });
}
}, {
key: 'sortedCards',
value: function sortedCards(cards, sortFunction) {
if (!cards) return [];
if (!sortFunction) return cards;
return cards.sort(function (card1, card2) {
return sortFunction(card1.metadata, card2.metadata);
});
}
}, {
key: 'createCard',
value: function createCard(card, onCardClick) {
if (!onCardClick) {
return _react2.default.createElement(_Card2.default, { key: card.key, title: card.title, rightHeader: card.rightHeader, description: card.description });
}
return _react2.default.createElement(_Card2.default, { key: card.key, title: card.title, rightHeader: card.rightHeader, description: card.description, onClick: function onClick() {
return onCardClick(card.metadata);
} });
}
}, {
key: 'render',
value: function render() {
var _this2 = this;

var loading = this.state.loading;

var _props = this.props,
title = _props.title,
rightHeader = _props.rightHeader,
cards = _props.cards,
onScroll = _props.onScroll,
otherProps = _objectWithoutProperties(_props, ['title', 'rightHeader', 'cards', 'onScroll']);
sortFunction = _props.sortFunction,
onCardClick = _props.onCardClick,
otherProps = _objectWithoutProperties(_props, ['title', 'rightHeader', 'cards', 'onScroll', 'sortFunction', 'onCardClick']);

return _react2.default.createElement(
_Base.Section,
Expand All @@ -297,11 +321,8 @@ var Lane = function (_Component) {
_react2.default.createElement(
_Base.DraggableList,
null,
this.state.cards && this.state.cards.map(function (card) {
return _react2.default.createElement(_Card2.default, { key: card.key,
title: card.title,
rightHeader: card.rightHeader,
description: card.description });
this.sortedCards(this.state.cards, sortFunction).map(function (card) {
return _this2.createCard(card, onCardClick);
}),
this.props.children
),
Expand Down

0 comments on commit d81ae4f

Please sign in to comment.