Skip to content

Commit

Permalink
Merge pull request #33429 from dimagi/smh/sscs-dynamically-update-res…
Browse files Browse the repository at this point in the history
…ults

Split Screen Case Search: Dynamically update results
  • Loading branch information
stephherbers authored Sep 8, 2023
2 parents 19bf29b + 096354c commit 2ee137f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.core.management import BaseCommand
from corehq.toggles import SPLIT_SCREEN_CASE_SEARCH, DYNAMICALLY_UPDATE_SEARCH_RESULTS, NAMESPACE_DOMAIN


class Command(BaseCommand):
help = """
Enabled DYNAMICALLY_UPDATE_SEARCH_RESULTS feature flag for domains with SPLIT_SCREEN_CASE_SEARCH enabled.
"""

def handle(self, **options):
sscs_enabled_domains = SPLIT_SCREEN_CASE_SEARCH.get_enabled_domains()
print("Processing " + str(len(sscs_enabled_domains)) + " domains")
for domain in sscs_enabled_domains:
DYNAMICALLY_UPDATE_SEARCH_RESULTS.set(domain, True, NAMESPACE_DOMAIN)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () {
formEntryUtils = hqImport("cloudcare/js/form_entry/utils"),
FormplayerFrontend = hqImport("cloudcare/js/formplayer/app"),
formplayerUtils = hqImport("cloudcare/js/formplayer/utils/utils"),
initialPageData = hqImport("hqwebapp/js/initial_page_data");
initialPageData = hqImport("hqwebapp/js/initial_page_data"),
toggles = hqImport("hqwebapp/js/toggles");

var separator = " to ",
serverSeparator = "__",
Expand Down Expand Up @@ -455,6 +456,8 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () {
// only here to maintain backward compatibility and can be removed
// once web apps fully transition using keys to convey select prompt selection.
this.selectValuesByKeys = false;
this.dynamicSearchEnabled = toggles.toggleEnabled('DYNAMICALLY_UPDATE_SEARCH_RESULTS') &&
this.options.sidebarEnabled;

for (let model of this.parentModel) {
if ("itemsetChoicesKey" in model.attributes) {
Expand Down Expand Up @@ -527,6 +530,9 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () {
}
}
});
if (self.dynamicSearchEnabled) {
self.updateSearchResults();
}
},

clearAction: function () {
Expand All @@ -540,7 +546,11 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () {
submitAction: function (e) {
var self = this;
e.preventDefault();
self.performSubmit();
},

performSubmit: function () {
var self = this;
self.validateAllFields().done(function () {
FormplayerFrontend.trigger(
"menu:query",
Expand All @@ -551,6 +561,19 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () {
});
},

updateSearchResults: function () {
var self = this;
var invalidRequiredFields = [];
self.children.each(function (childView) {
if (childView.hasRequiredError()) {
invalidRequiredFields.push(childView.model.get('text'));
}
});
if (invalidRequiredFields.length === 0) {
self.performSubmit();
}
},

validateFieldChange: function (changedChildView) {
var self = this;
var promise = $.Deferred();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ hqDefine("cloudcare/js/formplayer/spec/menu_list_spec", function () {
"toggles_dict",
{
SPLIT_SCREEN_CASE_SEARCH: false,
DYNAMICALLY_UPDATE_SEARCH_RESULTS: false,

}
);
sinon.stub(Utils, 'getCurrentQueryInputs').callsFake(function () { return {}; });
Expand Down
11 changes: 10 additions & 1 deletion corehq/toggles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,23 @@ def _ensure_valid_randomness(randomness):
namespaces=[NAMESPACE_DOMAIN]
)

DYNAMICALLY_UPDATE_SEARCH_RESULTS = StaticToggle(
'dynamically_update_search_results',
"In case search with split screen case search enabled, search results update when a search field is updated"
" without requiring the user to manually press a button to search.",
TAG_CUSTOM,
help_link='https://confluence.dimagi.com/display/USH/Split+Screen+Case+Search',
namespaces=[NAMESPACE_DOMAIN],
)

SPLIT_SCREEN_CASE_SEARCH = StaticToggle(
'split_screen_case_search',
"Split screen case search: In case search, show the search filters in a sidebar on the left and the results"
" on the right.",
TAG_CUSTOM,
help_link='https://confluence.dimagi.com/display/USH/Split+Screen+Case+Search',
namespaces=[NAMESPACE_DOMAIN],
parent_toggles=[SYNC_SEARCH_CASE_CLAIM]
parent_toggles=[SYNC_SEARCH_CASE_CLAIM, DYNAMICALLY_UPDATE_SEARCH_RESULTS]
)

USH_USERCASES_FOR_WEB_USERS = StaticToggle(
Expand Down

0 comments on commit 2ee137f

Please sign in to comment.