Skip to content

Commit 5e9df67

Browse files
committed
Add search filter for store dashboard
1 parent 0483a4c commit 5e9df67

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/views/StoreDashboard/StoreDashboard.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import {connect} from "react-redux";
3-
import {Button, Col, Row} from "reactstrap";
3+
import {Button, Col, Form, Input, InputGroup, InputGroupAddon, Row,} from "reactstrap";
44
import * as PropTypes from 'prop-types';
55
import {addPlugin, getPlugins} from "../../actions/pluginActions";
66
import axios from "axios";
@@ -12,7 +12,8 @@ class StoreDashboard extends React.Component {
1212
constructor(props, context) {
1313
super(props, context);
1414
this.state = {
15-
pluginsList: []
15+
pluginsList: [],
16+
searchQuery: ""
1617
}
1718
}
1819

@@ -34,21 +35,38 @@ class StoreDashboard extends React.Component {
3435
}
3536

3637
render() {
37-
const {pluginsList} = this.state;
38+
const {pluginsList, searchQuery} = this.state;
3839
if (pluginsList.length <= 0) {
3940
return (<p>Loading</p>)
4041
}
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+
}) : [];
4150
return (
4251
<div data-test="storeDashboardComponent">
4352
<Row>
4453
<Col lg={12} className="mb-4 d-flex justify-content-between">
4554
<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>
4765
</Col>
4866
</Row>
4967
<Row>
5068
{
51-
pluginsList && pluginsList.map((e) =>
69+
filteredList.map((e) =>
5270
<Col lg={6} key={e.name}>
5371
<PluginPlaceHolderCard plugin={e}/>
5472
</Col>

0 commit comments

Comments
 (0)