-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCLOMRS-98: Add Functionality To The Search (#71)
- Loading branch information
Showing
17 changed files
with
428 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { Component } from 'react'; | ||
import propTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import '../dashboard/styles/index.css'; | ||
import ListSearchResults from './ListSearchResults'; | ||
import generalSearch from '../../redux/actions/GeneralSearchActions/generalSearchActionCreators'; | ||
|
||
export class GeneralSearchContainer extends Component { | ||
static propTypes = { | ||
match: propTypes.shape({ | ||
params: propTypes.shape({ | ||
typeName: propTypes.string, | ||
}), | ||
}).isRequired, | ||
dictionaries: propTypes.arrayOf(propTypes.shape({ | ||
dictionaryName: propTypes.string, | ||
})).isRequired, | ||
generalSearch: propTypes.func.isRequired, | ||
loading: propTypes.bool.isRequired, | ||
} | ||
componentDidMount() { | ||
const { | ||
match: { | ||
params: { | ||
query, | ||
}, | ||
}, | ||
} = this.props; | ||
this.props.generalSearch(query); | ||
} | ||
render() { | ||
const { dictionaries, loading } = this.props; | ||
return ( | ||
<div className="dashboard-wrapper"> | ||
<div className="dashboard-head"> | ||
<div className="row justify-content-center"> | ||
<div className="offset-sm-1 col-10"> | ||
<ListSearchResults | ||
dictionaries={dictionaries} | ||
fetching={loading} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
export const mapStateToProps = state => ({ | ||
dictionaries: state.generalSearch.dictionaries, | ||
loading: state.generalSearch.loading, | ||
}); | ||
export default connect(mapStateToProps, { generalSearch })(GeneralSearchContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Card from '../dashboard/components/dictionary/DictionaryCard'; | ||
import Loader from '../Loader'; | ||
|
||
const ListDictionaries = ({ | ||
dictionaries, fetching, | ||
}) => { | ||
if (fetching) { | ||
return ( | ||
<div className="text-center mt-3"> | ||
<Loader /> | ||
</div> | ||
); | ||
} | ||
if (dictionaries.length >= 1) { | ||
return ( | ||
<div> | ||
<div className="row justify-content-center"> | ||
{dictionaries.map(dictionary => | ||
(<Card | ||
dictionary={dictionary} | ||
key={dictionary.uuid} | ||
/>))} | ||
</div> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="text-center mt-3" id="Noresults"> | ||
<h5>No Results Found <span aria-label="sad-emoji" role="img"> 😞 </span> </h5> | ||
</div> | ||
); | ||
}; | ||
|
||
ListDictionaries.propTypes = { | ||
fetching: PropTypes.bool.isRequired, | ||
dictionaries: PropTypes.arrayOf(PropTypes.shape({ | ||
dictionaryName: PropTypes.string, | ||
})).isRequired, | ||
}; | ||
export default ListDictionaries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const GeneralSearch = ({ onSearch, onSubmit, searchValue }) => ( | ||
<form className="form-inline" id="generalSearchForm" onSubmit={onSubmit}> | ||
<input | ||
className="form-control mr-sm-2" | ||
name="searchInput" | ||
id="generalSearch" | ||
type="search" | ||
value={searchValue} | ||
onChange={onSearch} | ||
placeholder="Search" | ||
aria-label="Search" | ||
required | ||
/> | ||
</form> | ||
); | ||
GeneralSearch.propTypes = { | ||
onSearch: PropTypes.func.isRequired, | ||
onSubmit: PropTypes.func.isRequired, | ||
searchValue: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default GeneralSearch; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/redux/actions/GeneralSearchActions/GeneralSearchActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SEARCH_RESULTS, IS_FETCHING } from '../types'; | ||
|
||
export const searchResults = payload => ({ | ||
type: SEARCH_RESULTS, | ||
payload, | ||
}); | ||
|
||
export const isFetching = payload => ({ | ||
type: IS_FETCHING, | ||
payload, | ||
}); | ||
|
26 changes: 26 additions & 0 deletions
26
src/redux/actions/GeneralSearchActions/generalSearchActionCreators.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import api from '../../api'; | ||
import { searchResults, isFetching } from './GeneralSearchActions'; | ||
import { filterPayload } from '../../reducers/util'; | ||
|
||
const generalsearch = searchItem => (dispatch) => { | ||
if (searchItem) { | ||
dispatch(isFetching(true)); | ||
return api.dictionaries | ||
.searchDictionaries(searchItem) | ||
.then((payload) => { | ||
const result = filterPayload(payload); | ||
dispatch(searchResults(result)); | ||
dispatch(isFetching(false)); | ||
}); | ||
} | ||
dispatch(isFetching(true)); | ||
return api.dictionaries | ||
.fetchingDictionaries() | ||
.then((payload) => { | ||
const result = filterPayload(payload); | ||
dispatch(searchResults(result)); | ||
dispatch(isFetching(false)); | ||
}); | ||
}; | ||
|
||
export default generalsearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SEARCH_RESULTS, IS_FETCHING } from '../actions/types'; | ||
|
||
const initialState = { dictionaries: [], loading: false }; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case SEARCH_RESULTS: | ||
return { | ||
...state, | ||
dictionaries: action.payload, | ||
}; | ||
case IS_FETCHING: | ||
return { | ||
...state, | ||
loading: action.payload, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/tests/GeneralSearch/Actions/generalSearchActions.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import moxios from 'moxios'; | ||
import configure from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import instance from '../../../config/axiosConfig'; | ||
import { IS_FETCHING, SEARCH_RESULTS } from '../../../redux/actions/types'; | ||
import generalsearch from '../../../redux/actions/GeneralSearchActions/generalSearchActionCreators'; | ||
import dictionaries from '../../__mocks__/dictionaries'; | ||
|
||
const mockstore = configure([thunk]); | ||
|
||
describe('Test suite for Search Results actions', () => { | ||
beforeEach(() => { | ||
moxios.install(instance); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(instance); | ||
}); | ||
|
||
it('should return a dictionary', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: [dictionaries], | ||
}); | ||
}); | ||
const expectedActions = [ | ||
{ type: IS_FETCHING, payload: true }, | ||
{ type: SEARCH_RESULTS, payload: [dictionaries] }, | ||
{ type: IS_FETCHING, payload: false }, | ||
]; | ||
const store = mockstore({ | ||
payload: {}, | ||
}); | ||
|
||
return store.dispatch(generalsearch('ChrisMain4567')).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
it('should return a dictionary', () => { | ||
moxios.wait(() => { | ||
const request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: [dictionaries], | ||
}); | ||
}); | ||
const expectedActions = [ | ||
{ type: IS_FETCHING, payload: true }, | ||
{ type: SEARCH_RESULTS, payload: [dictionaries] }, | ||
{ type: IS_FETCHING, payload: false }, | ||
]; | ||
const store = mockstore({ | ||
payload: {}, | ||
}); | ||
return store.dispatch(generalsearch()).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.