From d81ae4f1b63b1d8a55d3c76c73c251de5c02cd15 Mon Sep 17 00:00:00 2001 From: RC Date: Thu, 23 Feb 2017 13:28:59 +0530 Subject: [PATCH] feat(): Ability to sort lane by custom attributes --- dist/index.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6739e5ea0..b0cc96334 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; @@ -265,9 +266,30 @@ 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, @@ -275,7 +297,9 @@ var Lane = function (_Component) { 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, @@ -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 ),