Fix clearing search result
This commit is contained in:
parent
5fb69ffcc5
commit
040fe12d75
|
@ -198,23 +198,12 @@ export default class TreeMode extends Component {
|
||||||
// data = addErrors(data, this.getErrors())
|
// data = addErrors(data, this.getErrors())
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// enrich the data with search results
|
|
||||||
// TODO: reimplement search and selection
|
|
||||||
const searchResults = []
|
|
||||||
// const searchResults = this.state.search.text ? search(data, this.state.search.text) : null
|
|
||||||
// if (searchResults) {
|
|
||||||
// data = applySearchResults(data, searchResults, this.state.search.active)
|
|
||||||
// }
|
|
||||||
// if (this.state.selection) {
|
|
||||||
// data = applySelection(data, this.state.selection)
|
|
||||||
// }
|
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
className: `jsoneditor jsoneditor-mode-${props.mode}`,
|
className: `jsoneditor jsoneditor-mode-${props.mode}`,
|
||||||
onKeyDown: this.handleKeyDown,
|
onKeyDown: this.handleKeyDown,
|
||||||
'data-jsoneditor': 'true'
|
'data-jsoneditor': 'true'
|
||||||
}, [
|
}, [
|
||||||
this.renderMenu(searchResults),
|
this.renderMenu(),
|
||||||
|
|
||||||
h('div', {
|
h('div', {
|
||||||
key: 'contents',
|
key: 'contents',
|
||||||
|
@ -244,7 +233,7 @@ export default class TreeMode extends Component {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
renderMenu (searchResults: [] | null) {
|
renderMenu () {
|
||||||
let items = [
|
let items = [
|
||||||
h('button', {
|
h('button', {
|
||||||
key: 'expand-all',
|
key: 'expand-all',
|
||||||
|
@ -301,7 +290,7 @@ export default class TreeMode extends Component {
|
||||||
h('div', {key: 'search', className: 'jsoneditor-menu-panel-right'},
|
h('div', {key: 'search', className: 'jsoneditor-menu-panel-right'},
|
||||||
h(Search, {
|
h(Search, {
|
||||||
text: this.state.search.text,
|
text: this.state.search.text,
|
||||||
searchResults,
|
resultCount: this.state.search.matches ? this.state.search.matches.length : 0,
|
||||||
onChange: this.handleSearch,
|
onChange: this.handleSearch,
|
||||||
onNext: this.handleNext,
|
onNext: this.handleNext,
|
||||||
onPrevious: this.handlePrevious,
|
onPrevious: this.handlePrevious,
|
||||||
|
@ -592,7 +581,6 @@ export default class TreeMode extends Component {
|
||||||
|
|
||||||
handleSearch = (text) => {
|
handleSearch = (text) => {
|
||||||
const { eson, matches, active } = search(this.state.eson, text)
|
const { eson, matches, active } = search(this.state.eson, text)
|
||||||
|
|
||||||
if (matches.length > 0) {
|
if (matches.length > 0) {
|
||||||
this.setState({
|
this.setState({
|
||||||
search: { text, active, matches },
|
search: { text, active, matches },
|
||||||
|
@ -604,7 +592,8 @@ export default class TreeMode extends Component {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.setState({
|
this.setState({
|
||||||
search: { text, active, matches }
|
search: { text, active, matches },
|
||||||
|
eson
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ export default class Search extends Component {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return h('div', {className: 'jsoneditor-search'}, [
|
return h('div', {className: 'jsoneditor-search'}, [
|
||||||
this.renderResultsCount(this.props.searchResults),
|
this.renderResultsCount(this.props.resultCount),
|
||||||
h('form', {
|
h('form', {
|
||||||
key: 'box',
|
key: 'box',
|
||||||
className: 'jsoneditor-search-box',
|
className: 'jsoneditor-search-box',
|
||||||
|
@ -54,21 +54,19 @@ export default class Search extends Component {
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
renderResultsCount (searchResults : []) {
|
renderResultsCount (resultCount) {
|
||||||
if (!searchResults) {
|
if (resultCount === 0) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = searchResults.length
|
if (resultCount === 0) {
|
||||||
|
|
||||||
if (count === 0) {
|
|
||||||
return h('div', {key: 'count', className: 'jsoneditor-results'}, '(no results)')
|
return h('div', {key: 'count', className: 'jsoneditor-results'}, '(no results)')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0) {
|
if (resultCount > 0) {
|
||||||
const suffix = count === 1 ? ' result' : ' results'
|
const suffix = resultCount === 1 ? ' result' : ' results'
|
||||||
|
|
||||||
return h('div', {key: 'count', className: 'jsoneditor-results'}, count + suffix)
|
return h('div', {key: 'count', className: 'jsoneditor-results'}, resultCount + suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -352,7 +352,7 @@ export function addErrors (eson: ESON, errors) {
|
||||||
/**
|
/**
|
||||||
* Search some text in all properties and values
|
* Search some text in all properties and values
|
||||||
* @param {ESON} eson
|
* @param {ESON} eson
|
||||||
* @param {String} text
|
* @param {String} text Search text
|
||||||
* @return {{eson: ESON, matches: ESONPointer[], active: ESONPointer}} Returns search result:
|
* @return {{eson: ESON, matches: ESONPointer[], active: ESONPointer}} Returns search result:
|
||||||
* An updated eson object containing the search results,
|
* An updated eson object containing the search results,
|
||||||
* and an array with the paths of all matches
|
* and an array with the paths of all matches
|
||||||
|
@ -367,7 +367,7 @@ export function search (eson, text) {
|
||||||
|
|
||||||
// check property name
|
// check property name
|
||||||
const prop = last(path)
|
const prop = last(path)
|
||||||
if (typeof prop === 'string' && containsCaseInsensitive(prop, text)) {
|
if (typeof prop === 'string' && text !== '' && containsCaseInsensitive(prop, text)) {
|
||||||
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
||||||
matches.push({path, area: 'property'})
|
matches.push({path, area: 'property'})
|
||||||
updatedValue = setIn(updatedValue, ['_meta', 'searchProperty'], searchState)
|
updatedValue = setIn(updatedValue, ['_meta', 'searchProperty'], searchState)
|
||||||
|
@ -377,7 +377,7 @@ export function search (eson, text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check value
|
// check value
|
||||||
if (value._meta.type === 'value' && containsCaseInsensitive(value._meta.value, text)) {
|
if (value._meta.type === 'value' && text !== '' && containsCaseInsensitive(value._meta.value, text)) {
|
||||||
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
||||||
matches.push({path, area: 'value'})
|
matches.push({path, area: 'value'})
|
||||||
updatedValue = setIn(updatedValue, ['_meta', 'searchValue'], searchState)
|
updatedValue = setIn(updatedValue, ['_meta', 'searchValue'], searchState)
|
||||||
|
|
Loading…
Reference in New Issue