import React from 'react';
import { Alert, Row, Col } from 'react-bootstrap';
import { Profile, WaitIcon, ReactTable } from '../../../components';
import U from '../../session-utils';
import CrudPagination from '../crud/crud-pagination';
import CrudCounter from '../crud/crud-counter';
/**
* Standard displaying of a list of cases inside a react table, with pagination support
*/
export default class CasesList extends React.Component {
constructor(props) {
super(props);
this._caseClick = this._caseClick.bind(this);
}
componentWillMount() {
this._registerListener(this.props.controller);
}
componentWillReceiveProps(nextProps) {
if (this.props.controller !== nextProps.controller) {
this._removeListener();
this._registerListener(nextProps.controller);
}
}
componentWillUnmount() {
this._removeListener();
}
_registerListener(controller) {
const self = this;
const handler = controller.on(evt => {
if (evt === 'list' || evt === 'fetching-list') {
self.forceUpdate();
}
});
this.setState({ handler: handler });
}
_removeListener() {
// remove registration
this.props.controller.removeListener(this.state.handler);
}
/**
* Called when user clicks on a case
*/
_caseClick(item) {
if (this.props.onCaseClick) {
this.props.onCaseClick(item);
}
}
render() {
const controller = this.props.controller;
if (controller.isFetching()) {
return