1
1
import React from 'react' ;
2
2
import { connect } from "react-redux" ;
3
- import { Button , Col , Row } from "reactstrap" ;
3
+ import { Button , Col , Form , Input , InputGroup , InputGroupAddon , Row , } from "reactstrap" ;
4
4
import * as PropTypes from 'prop-types' ;
5
5
import { addPlugin , getPlugins } from "../../actions/pluginActions" ;
6
6
import axios from "axios" ;
@@ -12,7 +12,8 @@ class StoreDashboard extends React.Component {
12
12
constructor ( props , context ) {
13
13
super ( props , context ) ;
14
14
this . state = {
15
- pluginsList : [ ]
15
+ pluginsList : [ ] ,
16
+ searchQuery : ""
16
17
}
17
18
}
18
19
@@ -34,21 +35,38 @@ class StoreDashboard extends React.Component {
34
35
}
35
36
36
37
render ( ) {
37
- const { pluginsList} = this . state ;
38
+ const { pluginsList, searchQuery } = this . state ;
38
39
if ( pluginsList . length <= 0 ) {
39
40
return ( < p > Loading</ p > )
40
41
}
42
+ const filteredList = pluginsList ? pluginsList . filter ( element => {
43
+ return (
44
+ element . name . toLowerCase ( ) . includes ( searchQuery ) ||
45
+ element . description . toLowerCase ( ) . includes ( searchQuery ) ||
46
+ element . longDescription . toLowerCase ( ) . includes ( searchQuery ) ||
47
+ element . author . toLowerCase ( ) . includes ( searchQuery )
48
+ ) ;
49
+ } ) : [ ] ;
41
50
return (
42
51
< div data-test = "storeDashboardComponent" >
43
52
< Row >
44
53
< Col lg = { 12 } className = "mb-4 d-flex justify-content-between" >
45
54
< Button color = "secondary" onClick = { ( ) => this . props . history . goBack ( ) } > Back</ Button >
46
- < Button color = "primary" > < span className = "fa fa-search" /> Search</ Button >
55
+ < Form inline onSubmit = { ( e ) => e . preventDefault ( ) } >
56
+ < InputGroup >
57
+ < Input placeholder = "Type to start searching" type = "text" value = { searchQuery }
58
+ onChange = { ( e ) => this . setState ( { searchQuery : e . target . value } ) } />
59
+ < InputGroupAddon addonType = "append" > < Button color = "primary" > < span
60
+ className = "fa fa-search" /> </ Button > </ InputGroupAddon >
61
+ </ InputGroup >
62
+
63
+
64
+ </ Form >
47
65
</ Col >
48
66
</ Row >
49
67
< Row >
50
68
{
51
- pluginsList && pluginsList . map ( ( e ) =>
69
+ filteredList . map ( ( e ) =>
52
70
< Col lg = { 6 } key = { e . name } >
53
71
< PluginPlaceHolderCard plugin = { e } />
54
72
</ Col >
0 commit comments