Skip to content

Commit

Permalink
Merge branch 'bug_21236/when_we_arrive_on_the_node_search_page_with_a…
Browse files Browse the repository at this point in the history
…_query_pre_filed_the_query_is_done_twice_pr' into branches/rudder/7.2
  • Loading branch information
fanf committed Jun 14, 2023
2 parents aa61416 + e0afe26 commit 16251e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
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

0 comments on commit 16251e4

Please sign in to comment.