Skip to content
Snippets Groups Projects
Commit 39e5d412 authored by esikkala's avatar esikkala
Browse files

Override react-sortable-tree's search match highlighting

parent f75243f2
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,9 @@ const styles = () => ({ ...@@ -43,6 +43,9 @@ const styles = () => ({
marginLeft: 6, marginLeft: 6,
marginRight: 4, marginRight: 4,
}, },
searchMatch: {
boxShadow: '0 2px 0 #673ab7',
},
label: { label: {
// no styling // no styling
}, },
...@@ -73,6 +76,7 @@ class HierarchicalFacet extends Component { ...@@ -73,6 +76,7 @@ class HierarchicalFacet extends Component {
searchString: '', searchString: '',
searchFocusIndex: 0, searchFocusIndex: 0,
searchFoundCount: null, searchFoundCount: null,
matches: []
}; };
} }
...@@ -225,9 +229,15 @@ class HierarchicalFacet extends Component { ...@@ -225,9 +229,15 @@ class HierarchicalFacet extends Component {
generateLabel = node => { generateLabel = node => {
let count = node.totalInstanceCount == null || node.totalInstanceCount == 0 ? node.instanceCount : node.totalInstanceCount; let count = node.totalInstanceCount == null || node.totalInstanceCount == 0 ? node.instanceCount : node.totalInstanceCount;
let isSearchMatch = false;
if (this.state.matches.length > 0) {
// console.log(this.state.matches)
isSearchMatch = this.state.matches.some(match => match.node.id === node.id);
}
return ( return (
<React.Fragment> <React.Fragment>
<Typography variant='body2'> <Typography className={isSearchMatch ? this.props.classes.searchMatch : ''} variant='body2'>
{node.prefLabel} {node.prefLabel}
<span> [{count}]</span> <span> [{count}]</span>
</Typography> </Typography>
...@@ -296,6 +306,7 @@ class HierarchicalFacet extends Component { ...@@ -296,6 +306,7 @@ class HierarchicalFacet extends Component {
<Input <Input
placeholder={`Search...`} placeholder={`Search...`}
onChange={this.handleSearchFieldOnChange} onChange={this.handleSearchFieldOnChange}
value={this.state.searchString}
> >
</Input> </Input>
{searchFoundCount > 0 && {searchFoundCount > 0 &&
...@@ -331,13 +342,14 @@ class HierarchicalFacet extends Component { ...@@ -331,13 +342,14 @@ class HierarchicalFacet extends Component {
searchMethod={customSearchMethod} searchMethod={customSearchMethod}
searchQuery={searchString} searchQuery={searchString}
searchFocusOffset={searchFocusIndex} searchFocusOffset={searchFocusIndex}
searchFinishCallback={matches => searchFinishCallback={matches => {
this.setState({ this.setState({
searchFoundCount: matches.length, searchFoundCount: matches.length,
searchFocusIndex: searchFocusIndex:
matches.length > 0 ? searchFocusIndex % matches.length : 0, matches.length > 0 ? searchFocusIndex % matches.length : 0,
}) matches
} });
}}
onlyExpandSearchedNodes={true} onlyExpandSearchedNodes={true}
theme={FileExplorerTheme} theme={FileExplorerTheme}
generateNodeProps={this.generateNodeProps} generateNodeProps={this.generateNodeProps}
......
...@@ -39,7 +39,10 @@ ...@@ -39,7 +39,10 @@
align-items: center; align-items: center;
} }
.rstcustom__rowSearchMatch { .rstcustom__rowSearchMatch {
box-shadow: 0 2px 0 #673ab7 ; /*box-shadow: 0 2px 0 #673ab7 ;*/
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
} }
.leaflet-popup-scrolled { .leaflet-popup-scrolled {
border: 0px; border: 0px;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment