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

unibox (WIP) #196

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
171 changes: 94 additions & 77 deletions matscholar_web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,75 +118,92 @@ def update_nav_bar_highlight(path):
################################################################################


@app.callback(
Output("search-main-bar-input", "value"),
[Input("search-example-button", "n_clicks")]
+ get_search_field_callback_args(
as_type="input", return_component="value"
),
)
def search_bar_live_display(example_search_n_clicks, *ent_txts):
"""
Update the main search bar text live from the example search button and the
entity fields being typed in.

Args:
example_search_n_clicks (int): The number of times the example search
button was clicked.
*ent_txts (strs): The strings for each guided search field.

Returns:
(str): The text to be shown in the search bar via live update.

"""
return sl.search_bar_live_display(example_search_n_clicks, *ent_txts)
# @app.callback(
# Output("search-main-bar-input", "value"),
# [Input("search-example-button", "n_clicks")]
# + get_search_field_callback_args(
# as_type="input", return_component="value"
# ),
# )
# def search_bar_live_display(example_search_n_clicks, *ent_txts):
# """
# Update the main search bar text live from the example search button and the
# entity fields being typed in.
#
# Args:
# example_search_n_clicks (int): The number of times the example search
# button was clicked.
# *ent_txts (strs): The strings for each guided search field.
#
# Returns:
# (str): The text to be shown in the search bar via live update.
#
# """
# return sl.search_bar_live_display(example_search_n_clicks, *ent_txts)


@app.callback(
Output("search-example-button", "n_clicks"),
get_search_field_callback_args(as_type="input"),
Output("search-query-display", "children"),
[Input("search-input-unibox", "n_submit")],
[State("search-input-unibox", "input"),
State("search-current-query-hidden", "value")]
)
def void_example_search_n_clicks_on_live_search(*ent_txts):
"""
Reset the number of example search button clicks when any search is changed
via the guided search fields.

Args:
*ent_txts: The entity texts, though it does not matter what they
actually are.
Returns:
(int): The number of clicks to set the example search button n_clicks
to.
"""
return 0


@app.callback(
Output("search-go-button", "n_clicks"),
[Input("search-main-bar-input", "n_submit")]
+ get_search_field_callback_args(
as_type="input", return_component="n_submit"
),
[State("search-go-button", "n_clicks")],
)
def sum_all_fields_and_buttons_n_submits(*all_n_clicks):
"""
Sum the guided search fields and main search field and "Go" button n_submits
and n_clicks to a single n_clicks number for the Go button. Thus the user
can hit enter on any guided search field or the main box and the app will
act like you are hitting the go button.

Args:
*all_n_clicks (ints): Integers representing the number of times each
guided search field or main search bar or Go button was
clicked/entered.

Returns:
n_times_searched (int): The total number of times a search was executed.
If this is voided correctly in another callback, it will be either
0 or 1.
"""
return sl.sum_all_fields_and_buttons_n_submits(*all_n_clicks)
def update_query_display(unibox_n_submit, unibox_input, current_query):
print("triggered in app.py")
return sl.update_query_display(unibox_input, unibox_n_submit, current_query)


# @app.callback(
# Output("search-current-query-hidden", "value"),
# [Input("")]
# )


# @app.callback(
# Output("search-example-button", "n_clicks"),
# get_search_field_callback_args(as_type="input"),
# )
# def void_example_search_n_clicks_on_live_search(*ent_txts):
# """
# Reset the number of example search button clicks when any search is changed
# via the guided search fields.
#
# Args:
# *ent_txts: The entity texts, though it does not matter what they
# actually are.
# Returns:
# (int): The number of clicks to set the example search button n_clicks
# to.
# """
# return 0


# @app.callback(
# Output("search-go-button", "n_clicks"),
# [Input("search-main-bar-input", "n_submit")]
# + get_search_field_callback_args(
# as_type="input", return_component="n_submit"
# ),
# [State("search-go-button", "n_clicks")],
# )
# def sum_all_fields_and_buttons_n_submits(*all_n_clicks):
# """
# Sum the guided search fields and main search field and "Go" button n_submits
# and n_clicks to a single n_clicks number for the Go button. Thus the user
# can hit enter on any guided search field or the main box and the app will
# act like you are hitting the go button.
#
# Args:
# *all_n_clicks (ints): Integers representing the number of times each
# guided search field or main search bar or Go button was
# clicked/entered.
#
# Returns:
# n_times_searched (int): The total number of times a search was executed.
# If this is voided correctly in another callback, it will be either
# 0 or 1.
# """
# return sl.sum_all_fields_and_buttons_n_submits(*all_n_clicks)


@app.callback(
Expand Down Expand Up @@ -242,18 +259,18 @@ def memoize_wrapper(dropdown_value, search_text):

# Rotates example searches through the search bar
# See example_searches.js and clientside.js for more details
app.clientside_callback(
ClientsideFunction(
namespace="clientside",
function_name="cycleExampleSearchesClientsideFunction",
),
Output("search-main-bar-input", "children"),
[
Input("core-url", "pathname"),
Input("search-main-bar-input", "id"),
Input("search-examples-hidden-ref-cs", "id"),
],
)
# app.clientside_callback(
# ClientsideFunction(
# namespace="clientside",
# function_name="cycleExampleSearchesClientsideFunction",
# ),
# Output("search-main-bar-input", "children"),
# [
# Input("core-url", "pathname"),
# Input("search-main-bar-input", "id"),
# Input("search-examples-hidden-ref-cs", "id"),
# ],
# )


################################################################################
Expand Down
12 changes: 6 additions & 6 deletions matscholar_web/assets/msweb.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
}

.react-autosuggest__input {
width: 240px;
height: 30px;
width: 100%;
height: 60px;
padding: 10px 20px;
font-family: Helvetica, sans-serif;
font-weight: 300;
font-size: 16px;
font-size: 32px;
border: 1px solid #aaa;
border-radius: 4px;
}
Expand All @@ -35,7 +35,7 @@
display: block;
position: absolute;
top: 51px;
width: 280px;
width: 100%;
border: 1px solid #aaa;
background-color: #fff;
font-family: Helvetica, sans-serif;
Expand All @@ -47,8 +47,8 @@
}

.react-autosuggest__suggestions-list {
margin: 0;
padding: 0;
margin: 5;
padding: 5;
list-style-type: none;
}

Expand Down
11 changes: 11 additions & 0 deletions matscholar_web/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def common_404_html():
return html.Div("404", className="has-text-centered")


def empty_div_html():
"""
Return an empty div with no id.

Returns:
(dash_html_components.Div): The empty div.

"""
return html.Div("")


def common_stat_style():
"""
The common style for info statistics.
Expand Down
2 changes: 0 additions & 2 deletions matscholar_web/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
example_searches = load_static_data_file("example_searches.json")
sample_abstracts = load_static_data_file("sample_abstracts.json")


# Artifacts for making tests run easier
fake_endpoint = "not_a_real_endpoint"
fake_api_key = "not_a_real_api_key"
Expand All @@ -26,7 +25,6 @@
api_key = os.environ.get("MATERIALS_SCHOLAR_API_KEY", fake_api_key)
rester = Rester(endpoint=endpoint, api_key=api_key)


# Artifacts for elastic testing
fake_elastic_credential = "not_a_real_elastic_credential"

Expand Down
12 changes: 11 additions & 1 deletion matscholar_web/search/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

from matscholar.rest import MatScholarRestError
from matscholar_web.common import common_rester_error_html
from matscholar_web.common import common_rester_error_html, empty_div_html
from matscholar_web.constants import example_searches, valid_search_filters
from matscholar_web.search.common import cobalt_warning_html
from matscholar_web.search.subviews.abstracts import abstracts_results_html
Expand All @@ -16,6 +16,7 @@
from matscholar_web.search.view import (
malformed_query_warning_html,
no_query_warning_html,
query_display_html
)


Expand Down Expand Up @@ -73,6 +74,15 @@ def show_search_results(go_button_n_clicks, dropdown_value, search_text):
return common_rester_error_html(rester_error)


def update_query_display(unibox_input, unibox_n_submit, current_query):
print("triggered in logic")

if unibox_n_submit in [None, 0]:
return empty_div_html()
else:
return query_display_html("nothing...")


def sum_all_fields_and_buttons_n_submits(*all_n_clicks):
"""
Sum the guided search fields and main search field and "Go" button n_submits
Expand Down
Loading