yapi/client/containers/ProjectGroups/GroupList/GroupList.js

64 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-07-12 11:43:10 +08:00
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
2017-07-12 15:41:11 +08:00
import { Card, Button } from 'antd'
import { autobind } from 'core-decorators';
2017-07-12 11:43:10 +08:00
import {
fetchGroupList,
2017-07-12 15:41:11 +08:00
fetchCurrGroup,
addGroup
2017-07-12 11:43:10 +08:00
} from '../../../actions/group.js'
import './GroupList.scss'
@connect(
state => ({
groupList: state.group.groupList,
2017-07-12 14:18:17 +08:00
currGroup: state.group.currGroup
2017-07-12 11:43:10 +08:00
}),
{
fetchGroupList,
2017-07-12 15:41:11 +08:00
fetchCurrGroup,
addGroup
2017-07-12 11:43:10 +08:00
}
)
export default class GroupList extends Component {
static propTypes = {
groupList: PropTypes.array,
2017-07-12 15:41:11 +08:00
currGroup: PropTypes.string,
2017-07-12 16:38:42 +08:00
addGroup: PropTypes.func,
fetchGroupList: PropTypes.func
}
constructor(props) {
super(props)
}
componentWillMount() {
this.props.fetchGroupList();
2017-07-12 15:41:11 +08:00
}
@autobind
addGroup() {
this.props.addGroup('group');
2017-07-12 11:43:10 +08:00
}
render () {
const { groupList, currGroup } = this.props;
return (
<Card title="Groups">
2017-07-12 15:41:11 +08:00
<Button type="primary" onClick={this.addGroup}>添加分组</Button>
2017-07-12 11:43:10 +08:00
<div>{currGroup}</div>
{
groupList.map((group, index) => (
2017-07-14 15:15:59 +08:00
<div key={index}>{group.group_name}</div>
2017-07-12 11:43:10 +08:00
))
}
</Card>
)
}
}