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

Fixes #21236: When we arrive on the node search page with a query pre-filed, the query is done twice #4794

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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import scala.xml.NodeSeq.seqToNodeSeq
* Snippet that handle the "searchNodes" page.
*
* Two main feature:
* - diplay details of a node
* - display details of a node
* - search for nodes based on a query
*
* Node details are ALWAYS load via Ajax (see parseHashtag method).
Expand All @@ -94,17 +94,15 @@ class SearchNodes extends StatefulSnippet with Loggable {
throw new Exception(e.messageChain)
}

val searchNodeComponent = new LocalSnippet[SearchNodeComponent]
val searchNodeComponent = new LocalSnippet[SearchNodeComponent] // init will be done in parseHash

var srvList: Box[Seq[NodeInfo]] = Empty

setSearchComponent(None)

var dispatch: DispatchIt = {
case "showQuery" =>
searchNodeComponent.get match {
case Full(component) => { _ => queryForm(component) }
case _ => { _ => <div>The component is not set</div><div></div> }
case _ => { _ => <div>loading...</div><div></div> }
}
case "head" => head _
case "createGroup" => createGroup _
Expand Down Expand Up @@ -192,23 +190,33 @@ class SearchNodes extends StatefulSnippet with Loggable {
* way - just don't take of errors.
*
* We want to look for #{ "nodeId":"XXXXXXXXXXXX" }
*
* The contract for the JS function `parseSearchHash` is:
* - pass an empty string if hash is undefined or empty
* - pass a json-serialised structure in other cases
*/
private[this] def parseHashtag(): JsCmd = {
def executeQuery(query: String): JsCmd = {
val q = queryParser(query).map(_ match {
case q: NewQuery => q; case q: Query => NewQuery(q.returnType, q.composition, ResultTransformation.Identity, q.criteria)
})
val sc = setSearchComponent(q)

q match {
case e: EmptyBox =>
val fail = e ?~! s"Could not parse ${query} as a valid query"
logger.error(fail.messageChain)
Noop
case Full(q) =>
Replace("SearchNodes", queryForm(sc)) &
JsRaw("$('#SubmitSearch').click();")
val sc = if (query.nonEmpty) {
val parsed = queryParser(query).map(_ match {
case q: NewQuery => q; case q: Query => NewQuery(q.returnType, q.composition, ResultTransformation.Identity, q.criteria)
})

parsed match {
case e: EmptyBox =>
val fail = e ?~! s"Could not parse ${query} as a valid query"
logger.error(fail.messageChain)
setSearchComponent(None)
case Full(q) =>
setSearchComponent(Some(q))
}
} else {
setSearchComponent(None)
}
Replace(
"SearchNodes",
queryForm(sc)
) & JsRaw("$('#SubmitSearch').click();")
}

JsRaw(s"""parseSearchHash(function(x) { ${SHtml.ajaxCall(JsVar("x"), executeQuery _)._2.toJsCmd} })""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ function parseSearchHash(queryCallback) {
var hash = parseURLHash();
if( hash.query != null && JSON.stringify(hash.query).length > 0) {
queryCallback(JSON.stringify(hash.query));
} else {
queryCallback("");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ <h1>
<div id="query-search-content">
<div class="inner-portlet-content">
<div id="SearchNodes">
<div data-lift="node.SearchNodes.head"></div>
<div data-lift="node.SearchNodes.showQuery"></div>
</div>
<lift:authz role="group_write">
Expand Down