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 1
1
class Customer < ApplicationRecord
2
+ scope :company_name_contains , -> ( value ) { where ( 'company_name ILIKE ?' , "%#{ value . join } %" ) }
2
3
end
Original file line number Diff line number Diff line change 1
1
class CustomerResource < JSONAPI ::Resource
2
+ extend ModelFilter
2
3
attributes :company_name ,
3
4
:contact_name ,
4
5
:contact_title ,
@@ -12,4 +13,5 @@ class CustomerResource < JSONAPI::Resource
12
13
:created_at
13
14
14
15
paginator :paged
16
+ model_filters :company_name_contains
15
17
end
Original file line number Diff line number Diff line change 1
1
import React , { Component , PropTypes } from 'react' ;
2
2
import { Link } from 'react-router' ;
3
3
import { find , keyBy } from 'lodash' ;
4
+ import { Button } from 'reactstrap' ;
4
5
5
6
import { ListTable } from '../UI' ;
6
7
import { withResourceList } from '../../hocs' ;
8
+ import CustomerListFilter from './CustomerListFilter' ;
7
9
8
10
const formatDate = date => ( new Date ( date ) ) . toLocaleString ( ) ;
9
11
@@ -14,6 +16,7 @@ export class CustomerList extends Component {
14
16
}
15
17
16
18
render ( ) {
19
+ const { onFilter } = this . props ;
17
20
const columns = [
18
21
{
19
22
attribute : 'companyName' ,
@@ -36,9 +39,21 @@ export class CustomerList extends Component {
36
39
] ;
37
40
38
41
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 >
40
51
) ;
41
52
}
42
53
}
43
54
55
+ export const mapStateToProps = state => ( {
56
+ filter : get ( state , 'form.customerListFilter.values' ) || { }
57
+ } ) ;
58
+
44
59
export 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 {
36
36
< Route path = "/users" component = { UserIsAdmin ( UserList ) } />
37
37
< Route path = "/users/:id" component = { UserIsAdmin ( UserEdit ) } />
38
38
< Route path = "/customers" component = { UserIsAdmin ( CustomerList ) } />
39
+ < Route path = "/customers/new" component = { UserIsAdmin ( CustomerEdit ) } />
39
40
< Route path = "/customers/:id" component = { UserIsAdmin ( CustomerEdit ) } />
40
41
</ Route >
41
42
< Route path = "/login" component = { Login } />
You can’t perform that action at this time.
0 commit comments