1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/client/src/containers/ListContainer.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import omit from 'lodash/omit';
2019-08-31 04:07:25 +05:00
import {
isAnyFilterActiveForCurrentBoardSelector,
makeCardIdsByListIdSelector,
makeListByIdSelector,
} from '../selectors';
2019-08-31 04:07:25 +05:00
import { createCard, deleteList, updateList } from '../actions/entry';
import List from '../components/List';
const makeMapStateToProps = () => {
const listByIdSelector = makeListByIdSelector();
const cardIdsByListIdSelector = makeCardIdsByListIdSelector();
return (state, { id, index }) => {
const { name, isPersisted } = listByIdSelector(state, id);
const cardIds = cardIdsByListIdSelector(state, id);
const isAnyFilterActive = isAnyFilterActiveForCurrentBoardSelector(state);
2019-08-31 04:07:25 +05:00
return {
id,
index,
name,
isPersisted,
cardIds,
isDeletable: !isAnyFilterActive,
2019-08-31 04:07:25 +05:00
};
};
};
const mapDispatchToProps = (dispatch, { id }) =>
bindActionCreators(
{
2020-03-25 00:15:47 +05:00
onUpdate: (data) => updateList(id, data),
onDelete: () => deleteList(id),
2020-03-25 00:15:47 +05:00
onCardCreate: (data) => createCard(id, data),
},
dispatch,
);
2019-08-31 04:07:25 +05:00
const mergeProps = (stateProps, dispatchProps) => ({
...omit(stateProps, 'isDeletable'),
...(stateProps.isDeletable ? dispatchProps : omit(dispatchProps, 'onDelete')),
});
export default connect(makeMapStateToProps, mapDispatchToProps, mergeProps)(List);