Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1660. Now results can fit to map size #1661

Merged
merged 2 commits into from
Mar 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/client/components/mapcontrols/search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let SearchBar = React.createClass({
var text = this.props.searchText;
if ((text === undefined || text === "") && (!this.props.selectedItems || this.props.selectedItems.length === 0)) {
this.props.onSearchReset();
} else {
} else if (text !== undefined && text !== "") {
this.props.onSearch(text, this.props.searchOptions);
}

Expand Down
25 changes: 23 additions & 2 deletions web/client/components/mapcontrols/search/SearchResultList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@
var React = require('react');
var SearchResult = require('./SearchResult');
const I18N = require('../../I18N/I18N');
var assign = require('object-assign');


let SearchResultList = React.createClass({
propTypes: {
results: React.PropTypes.array,
searchOptions: React.PropTypes.object,
mapConfig: React.PropTypes.object,
fitToMapSize: React.PropTypes.bool,
containerStyle: React.PropTypes.containerStyle,
sizeAdjustment: React.PropTypes.object,
onItemClick: React.PropTypes.func,
addMarker: React.PropTypes.func,
afterItemClick: React.PropTypes.func,
notFoundMessage: React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.string])
},
getDefaultProps() {
return {
sizeAdjustment: {
width: 0,
height: 110
},
containerStyle: {
zIndex: 1000
},
onItemClick: () => {},
addMarker: () => {},
afterItemClick: () => {}
Expand All @@ -47,13 +58,23 @@ let SearchResultList = React.createClass({
if (!notFoundMessage) {
notFoundMessage = <I18N.Message msgId="noresultfound" />;
}
let containerStyle = this.props.containerStyle;
let mapSize = this.props.mapConfig && this.props.mapConfig.size;
if (this.props.fitToMapSize && mapSize) {
let maxWidth = mapSize.width - this.props.sizeAdjustment.width;
let maxHeight = mapSize.height - this.props.sizeAdjustment.height;
containerStyle = assign({}, this.props.containerStyle, {
maxWidth,
maxHeight
});
}
if (!this.props.results) {
return null;
} else if (this.props.results.length === 0) {
return <div className="search-result-list" style={{padding: "10px", textAlign: "center"}}>{notFoundMessage}</div>;
return <div className="search-result-list" style={assign({padding: "10px", textAlign: "center"}, containerStyle)}>{notFoundMessage}</div>;
}
return (
<div className="search-result-list">
<div className="search-result-list" style={containerStyle}>
{this.renderResults()}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ describe("test the SearchResultList", () => {
});

it('test component creation', () => {

const tb = ReactDOM.render(<SearchResultList results={results}/>, document.getElementById("container"));
expect(tb).toExist();

});

it('create component without items', () => {
Expand All @@ -54,6 +52,20 @@ describe("test the SearchResultList", () => {
expect(tb).toExist();
});


it('test fit map Size', () => {
const res = Array.from(Array(100).keys()).map((i) => ({
id: i,
properties: {
prop: i
}
}));
const cmp = ReactDOM.render(<SearchResultList mapConfig={{size: {width: 200, height: 200}}} sizeAdjustment={{width: 100, height: 120}} fitToMapSize={true} results={res} notFoundMessage="not found"/>, document.getElementById("container"));
expect(cmp).toExist();
let list = TestUtils.findRenderedDOMComponentWithClass(cmp, "search-result-list");
expect(list.offsetHeight).toBe(80);
expect(list.offsetWidth).toBe(100);
});
it('get service info from internal object', () => {
let tb = ReactDOM.render(<SearchResultList results={results} notFoundMessage="not found"/>, document.getElementById("container"));
expect(tb).toExist();
Expand Down
5 changes: 4 additions & 1 deletion web/client/plugins/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const ToggleButton = require('./searchbar/ToggleButton');
* @class Search
* @memberof plugins
* @prop {object} cfg.searchOptions initial search options
* @prop {bool} cfg.fitResultsToMapSize true by default, fits the result list to the mapSize (can be disabled, for custom uses)
* @prop {searchService[]} cfg.searchOptions.services a list of services to perform search.
* a **nominatim** search service look like this:
* ```
Expand Down Expand Up @@ -124,6 +125,7 @@ const SearchPlugin = connect((state) => ({
selectedItems: state && state.search && state.search.selectedItems
}))(React.createClass({
propTypes: {
fitResultsToMapSize: React.PropTypes.bool,
searchOptions: React.PropTypes.object,
selectedItems: React.PropTypes.array,
selectedServices: React.PropTypes.array,
Expand All @@ -135,6 +137,7 @@ const SearchPlugin = connect((state) => ({
searchOptions: {
services: [{type: "nominatim"}]
},
fitResultsToMapSize: true,
withToggle: false,
enabled: true
};
Expand Down Expand Up @@ -177,7 +180,7 @@ const SearchPlugin = connect((state) => ({
helpText={<Message msgId="helptexts.searchBar"/>}>
{this.getSearchAndToggleButton()}
</HelpWrapper>
<SearchResultList searchOptions={this.props.searchOptions} key="nominatimresults"/>
<SearchResultList fitToMapSize={this.props.fitResultsToMapSize} searchOptions={this.props.searchOptions} key="nominatimresults"/>
</span>
);
}
Expand Down