diff --git a/corehq/apps/app_manager/management/commands/enable_dynamic_results_ff_for_sscs_domains.py b/corehq/apps/app_manager/management/commands/enable_dynamic_results_ff_for_sscs_domains.py new file mode 100644 index 000000000000..623e0bf44a98 --- /dev/null +++ b/corehq/apps/app_manager/management/commands/enable_dynamic_results_ff_for_sscs_domains.py @@ -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) diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views/query.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views/query.js index 29f54a342633..73d9f531193c 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views/query.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/views/query.js @@ -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 = "__", @@ -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) { @@ -527,6 +530,9 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { } } }); + if (self.dynamicSearchEnabled) { + self.updateSearchResults(); + } }, clearAction: function () { @@ -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", @@ -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(); diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/spec/menu_list_spec.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/spec/menu_list_spec.js index 8a59ac08cf46..0560d201b470 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/spec/menu_list_spec.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/spec/menu_list_spec.js @@ -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 {}; }); diff --git a/corehq/toggles/__init__.py b/corehq/toggles/__init__.py index 4c1b3a88479f..062c5348eb12 100644 --- a/corehq/toggles/__init__.py +++ b/corehq/toggles/__init__.py @@ -1040,6 +1040,15 @@ 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" @@ -1047,7 +1056,7 @@ def _ensure_valid_randomness(randomness): 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(