Skip to content

Commit

Permalink
Allow configuring whether to replace search text with selected result
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jul 11, 2024
1 parent 2d7b5b6 commit 8add91c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 8 additions & 7 deletions components/SearchBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SearchBox extends React.Component {
sectionsDefaultCollapsed: PropTypes.bool,
showLayerAfterChangeTheme: PropTypes.bool,
showLayerResultsBeforePlaces: PropTypes.bool,
showResultInSearchText: PropTypes.bool,
zoomToLayers: PropTypes.bool
}),
searchProviders: PropTypes.object,
Expand Down Expand Up @@ -762,10 +763,10 @@ class SearchBox extends React.Component {
tot_result_count: 1
}
};
this.setState({
searchText: text,
this.setState(state => ({
searchText: this.props.searchOptions.showResultInSearchText !== false ? text : state.searchText,
searchResults: results
});
}));
};
selectProviderResult = (group, result, provider, zoom = true) => {
this.setProviderResult(result.text.replace(/<\/?\w+\s*\/?>/g, ''), provider, group, result);
Expand Down Expand Up @@ -904,7 +905,7 @@ class SearchBox extends React.Component {
}
};
return {
searchText: text,
searchText: this.props.searchOptions.showResultInSearchText !== false ? text : state.searchText,
searchResults: results
};
});
Expand Down Expand Up @@ -966,10 +967,10 @@ class SearchBox extends React.Component {
results: [{dataproduct: result}]
}
};
this.setState({
searchText: text,
this.setState(state => ({
searchText: this.props.searchOptions.showResultInSearchText !== false ? text : state.searchText,
searchResults: results
});
}));
};
selectLayerResult = (result, info = false) => {
if (!info) {
Expand Down
2 changes: 1 addition & 1 deletion doc/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ Top bar, containing the logo, searchbar, task buttons and app menu.
| logoSrc | `string` | The logo image URL if a different source than the default assets/img/logo.<ext> and assets/img/logo-mobile.<ext> is desired. | `undefined` |
| logoUrl | `string` | The hyperlink to open when the logo is clicked. | `undefined` |
| menuItems | `array` | The menu items. Refer to the corresponding chapter of the viewer documentation and the sample config.json. | `[]` |
| searchOptions | `{`<br />`  allowSearchFilters: bool,`<br />`  hideResultLabels: bool,`<br />`  highlightStyle: {`<br />`  strokeColor: array,`<br />`  strokeWidth: number,`<br />`  strokeDash: array,`<br />`  fillColor: array,`<br />`},`<br />`  minScaleDenom: number,`<br />`  resultLimit: number,`<br />`  sectionsDefaultCollapsed: bool,`<br />`  showLayerAfterChangeTheme: bool,`<br />`  showLayerResultsBeforePlaces: bool,`<br />`  showProviderSelection: bool,`<br />`  showProvidersInPlaceholder: bool,`<br />`  providerSelectionAllowAll: bool,`<br />`  zoomToLayers: bool,`<br />`}` | Options passed down to the search component. | `{}` |
| searchOptions | `{`<br />`  allowSearchFilters: bool,`<br />`  hideResultLabels: bool,`<br />`  highlightStyle: {`<br />`  strokeColor: array,`<br />`  strokeWidth: number,`<br />`  strokeDash: array,`<br />`  fillColor: array,`<br />`},`<br />`  minScaleDenom: number,`<br />`  resultLimit: number,`<br />`  sectionsDefaultCollapsed: bool,`<br />`  showLayerAfterChangeTheme: bool,`<br />`  showLayerResultsBeforePlaces: bool,`<br />`  showProviderSelection: bool,`<br />`  showProvidersInPlaceholder: bool,`<br />`  showResultInSearchText: bool,`<br />`  providerSelectionAllowAll: bool,`<br />`  zoomToLayers: bool,`<br />`}` | Options passed down to the search component. | `{`<br />`  showResultInSearchText: true`<br />`}` |
| toolbarItems | `array` | The toolbar. Refer to the corresponding chapter of the viewer documentation and the sample config.json. | `[]` |
| toolbarItemsShortcutPrefix | `string` | The keyboard shortcut prefix for triggering toolbar tasks. I.e. alt+shift. The task are then triggered by <prefix>+{1,2,3,...} for the 1st, 2nd, 3rd... toolbar icon. | `undefined` |

Expand Down
8 changes: 6 additions & 2 deletions plugins/TopBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ class TopBar extends React.Component {
sectionsDefaultCollapsed: PropTypes.bool,
/** Whether to show the layer tree after selecting a theme result. */
showLayerAfterChangeTheme: PropTypes.bool,
/** Whether to show layer results before pkaces in the result menu (SearchBpx only). */
/** Whether to show layer results before pkaces in the result menu (SearchBox only). */
showLayerResultsBeforePlaces: PropTypes.bool,
/** Whether to show provider selection menu (Search only). */
showProviderSelection: PropTypes.bool,
/** Whether to list the names of active providers as search field placeholder (Search only). */
showProvidersInPlaceholder: PropTypes.bool,
/** Whether to replace the search text with the selected search result text (SearchBox only). */
showResultInSearchText: PropTypes.bool,
/** Whether to show the 'All providers' entry in the provider selection menu (Search only). */
providerSelectionAllowAll: PropTypes.bool,
/** Whether to zoom to layer search results. */
Expand All @@ -98,7 +100,9 @@ class TopBar extends React.Component {
toolbarItemsShortcutPrefix: PropTypes.string
};
static defaultProps = {
searchOptions: {},
searchOptions: {
showResultInSearchText: true
},
menuItems: [],
toolbarItems: [],
logoFormat: "svg"
Expand Down

0 comments on commit 8add91c

Please sign in to comment.