File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 11class Customer < ApplicationRecord
2+ scope :company_name_contains , -> ( value ) { where ( 'company_name ILIKE ?' , "%#{ value . join } %" ) }
23end
Original file line number Diff line number Diff line change 11class CustomerResource < JSONAPI ::Resource
2+ extend ModelFilter
23 attributes :company_name ,
34 :contact_name ,
45 :contact_title ,
@@ -12,4 +13,5 @@ class CustomerResource < JSONAPI::Resource
1213 :created_at
1314
1415 paginator :paged
16+ model_filters :company_name_contains
1517end
Original file line number Diff line number Diff line change 11import React , { Component , PropTypes } from 'react' ;
22import { Link } from 'react-router' ;
33import { find , keyBy } from 'lodash' ;
4+ import { Button } from 'reactstrap' ;
45
56import { ListTable } from '../UI' ;
67import { withResourceList } from '../../hocs' ;
8+ import CustomerListFilter from './CustomerListFilter' ;
79
810const formatDate = date => ( new Date ( date ) ) . toLocaleString ( ) ;
911
@@ -14,6 +16,7 @@ export class CustomerList extends Component {
1416 }
1517
1618 render ( ) {
19+ const { onFilter } = this . props ;
1720 const columns = [
1821 {
1922 attribute : 'companyName' ,
@@ -36,9 +39,21 @@ export class CustomerList extends Component {
3639 ] ;
3740
3841 return (
39- < ListTable { ...this . props } columns = { columns } />
42+ < div >
43+ < Button tag = { Link } to = { '/customers/new' } > New Customer</ Button >
44+
45+ < CustomerListFilter
46+ onSubmit = { onFilter } >
47+ </ CustomerListFilter >
48+
49+ < ListTable { ...this . props } columns = { columns } />
50+ </ div >
4051 ) ;
4152 }
4253}
4354
55+ export const mapStateToProps = state => ( {
56+ filter : get ( state , 'form.customerListFilter.values' ) || { }
57+ } ) ;
58+
4459export default withResourceList ( 'customers' ) ( CustomerList ) ;
Original file line number Diff line number Diff line change 1+ import React , { Component , PropTypes } from 'react' ;
2+ import { isEmpty } from 'lodash' ;
3+ import { Field , reduxForm } from 'redux-form' ;
4+ import { Form , Row , Col } from 'reactstrap' ;
5+
6+ import { InputField , SelectField } from '../../forms' ;
7+
8+ class CustomerListFilter extends Component {
9+ render ( ) {
10+ const { handleSubmit, onSubmit } = this . props ;
11+
12+ const submitOnChange = ( ) => setTimeout ( ( ) => handleSubmit ( onSubmit ) ( ) , 0 ) ;
13+
14+
15+ return (
16+ < Form onSubmit = { handleSubmit } >
17+ < Row >
18+ < Col md = { 8 } >
19+ < Field
20+ name = "company_name_contains"
21+ label = "Company Name Contains"
22+ component = { InputField }
23+ onChange = { submitOnChange }
24+ />
25+ </ Col >
26+ </ Row >
27+ </ Form >
28+ ) ;
29+ }
30+ }
31+
32+ export default reduxForm ( {
33+ form : 'customerListFilter' ,
34+ destroyOnUnmount : false ,
35+ } ) ( CustomerListFilter ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export class Routes extends PureComponent {
3636 < Route path = "/users" component = { UserIsAdmin ( UserList ) } />
3737 < Route path = "/users/:id" component = { UserIsAdmin ( UserEdit ) } />
3838 < Route path = "/customers" component = { UserIsAdmin ( CustomerList ) } />
39+ < Route path = "/customers/new" component = { UserIsAdmin ( CustomerEdit ) } />
3940 < Route path = "/customers/:id" component = { UserIsAdmin ( CustomerEdit ) } />
4041 </ Route >
4142 < Route path = "/login" component = { Login } />
You can’t perform that action at this time.
0 commit comments