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

Dynamic search suite changes #33622

Merged
merged 15 commits into from
Nov 14, 2023
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
2 changes: 2 additions & 0 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ class CaseSearch(DocumentSchema):
title_label = LabelProperty(default={})
description = LabelProperty(default={})
include_all_related_cases = BooleanProperty(default=False)
dynamic_search = BooleanProperty(default=False)

# case property referencing another case's ID
custom_related_case_property = StringProperty(exclude_if_none=True)
Expand Down Expand Up @@ -4156,6 +4157,7 @@ def assert_app_v2(self):
default=const.DEFAULT_LOCATION_FIXTURE_OPTION, choices=const.LOCATION_FIXTURE_OPTIONS,
required=False
)
split_screen_dynamic_search = BooleanProperty(default=False)

@property
def id(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,12 @@
- ['only_flat_fixture', 'Only Flat Fixture']
- ['only_hierarchical_fixture', 'Only Hierarchical Fixture']
default: 'project_default'


- id: split_screen_dynamic_search
name: Dynamic Search for Split Screen Case Search
description: Enable searching as input values change after initial Split Screen Case Search
toggle: DYNAMICALLY_UPDATE_SEARCH_RESULTS
widget: bool
default: false
since: '2.54'
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- hq.translation_strategy
- hq.mobile_ucr_restore_version
- hq.location_fixture_restore
- hq.split_screen_dynamic_search
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me we might want to split out a "web apps" section and/or rename the android section to something like "UI", but that's not part of this PR.


- title: 'Disabled'
id: app-settings-disabled
Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/app_manager/static_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
gettext_noop('Disable'),
gettext_noop('Disabled'),
gettext_noop('Display root menu as a list or grid. Read more on the <a target="_blank" href="https://help.commcarehq.org/display/commcarepublic/Grid+View+for+Form+and+Module+Screens">Help Site</a>.'),
gettext_noop('Dynamic Search for Split Screen Case Search'),
gettext_noop('Enable Menu Display Setting Per-Module'),
gettext_noop('Enable'),
gettext_noop('Enabled'),
gettext_noop('Enable searching as input values change after initial Split Screen Case Search'),
gettext_noop('For mobile map displays, chooses a base tileset for the underlying map layer'),
gettext_noop('Forms Menu Display'),
gettext_noop('Forms are Never Removed'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def build_remote_request_queries(self):
data=self._remote_request_query_datums,
prompts=self.build_query_prompts(),
default_search=self.module.search_config.default_search,
dynamic_search=self.app.split_screen_dynamic_search and not self.module.is_auto_select(),
)
]

Expand Down
1 change: 1 addition & 0 deletions corehq/apps/app_manager/suite_xml/xml_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ class RemoteRequestQuery(OrderedXmlObject, XmlObject):
data = NodeListField('data', QueryData)
prompts = NodeListField('prompt', QueryPrompt)
default_search = BooleanField("@default_search")
dynamic_search = BooleanField("@dynamic_search")

@property
def id(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<instance id="results" src="jr://instance/remote/results"/>
<instance id="search_selected_cases" src="jr://instance/selected-entities/search_selected_cases"/>
<session>
<query default_search="false" storage-instance="results" template="case" url="https://www.example.com/a/multiple-referrals/phone/search/{app_id}/">
<query default_search="false" dynamic_search="false" storage-instance="results" template="case" url="https://www.example.com/a/multiple-referrals/phone/search/{app_id}/">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<session>
<query url="https://www.example.com/a/test_domain/phone/search/123/"
default_search="false"
dynamic_search="false"
storage-instance="results"
template="case">
<title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<session>
<query url="https://www.example.com/a/test_domain/phone/search/123/"
default_search="false"
dynamic_search="false"
storage-instance="results"
template="case">
<title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<session>
<query url="https://www.example.com/a/test_domain/phone/search/123/"
default_search="false"
dynamic_search="false"
storage-instance="results"
template="case">
<title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<session>
<query url="https://www.example.com/a/test_domain/phone/search/123/"
default_search="false"
dynamic_search="false"
storage-instance="results"
template="case">
<title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<instance id="commcaresession" src="jr://instance/session"/>
<instance id="results" src="jr://instance/remote/results"/>
<session>
<query default_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/{app_id}/">
<query default_search="false" dynamic_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/{app_id}/">
<title>
<text>
<locale id="case_search.m1.inputs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<instance id="commcaresession" src="jr://instance/session"/>
<instance id="results:inline" src="jr://instance/remote/results:inline"/>
<session>
<query default_search="false" storage-instance="results:inline" template="case"
<query default_search="false" dynamic_search="false" storage-instance="results:inline" template="case"
url="http://localhost:8000/a/test_domain/phone/search/456/">
<title>
<text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<instance id="item-list:colors" src="jr://fixture/item-list:colors"/>
<instance id="results" src="jr://instance/remote/results"/>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/" storage-instance="results" template="case" default_search="false">
<query url="http://localhost:8000/a/test_domain/phone/search/123/" storage-instance="results" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<instance id="item-list:textures" src="jr://fixture/item-list:textures"/>
<instance id="results" src="jr://instance/remote/results"/>
<session>
<query default_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/456/">
<query default_search="false" dynamic_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/456/">
<title>
<text>
<locale id="case_search.m1.inputs"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<instance id="item-list:textures" src="jr://fixture/item-list:textures"/>
<instance id="results" src="jr://instance/remote/results"/>
<session>
<query default_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/456/">
<query default_search="false" dynamic_search="false" storage-instance="results" template="case" url="https://www.example.com/a/test_domain/phone/search/456/">
<title>
<text>
<locale id="case_search.m1.inputs"/>
Expand Down
20 changes: 13 additions & 7 deletions corehq/apps/app_manager/tests/test_advanced_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def test_advanced_suite_auto_select_with_filter(self, *args):
<text>
<locale id="modules.m1"/>
</text>
<command id="m1-f0" relevant="instance('casedb')/casedb/case[@case_id=instance('commcaresession')/session/data/case_id_case_clinic]/edd = '123'"/>
<command id="m1-f0" relevant="instance('casedb')/casedb/""" +\
"""case[@case_id=instance('commcaresession')/session/data/case_id_case_clinic]/edd = '123'"/>
<command id="m1-f1"/>
<command id="m1-f2"/>
<command id="m1-case-list"/>
Expand All @@ -161,7 +162,8 @@ def test_advanced_suite_load_case_from_fixture(self, *args):
case_tag="adherence",
case_type="clinic",
load_case_from_fixture=LoadCaseFromFixture(
fixture_nodeset="instance('item-list:table_tag')/calendar/year/month/day[@date > 735992 and @date < 736000]",
fixture_nodeset="instance('item-list:table_tag')/calendar/year/month"
"/day[@date > 735992 and @date < 736000]",
fixture_tag="selected_date",
fixture_variable="./@date",
case_property="adherence_event_date",
Expand All @@ -178,7 +180,8 @@ def test_advanced_suite_load_case_from_fixture_with_arbitrary_datum(self, *args)
case_tag="adherence",
case_type="clinic",
load_case_from_fixture=LoadCaseFromFixture(
fixture_nodeset="instance('item-list:table_tag')/calendar/year/month/day[@date > 735992 and @date < 736000]",
fixture_nodeset="instance('item-list:table_tag')/calendar/year/month/"
"day[@date > 735992 and @date < 736000]",
fixture_tag="selected_date",
fixture_variable="./@date",
case_property="adherence_event_date",
Expand Down Expand Up @@ -228,8 +231,10 @@ def test_advanced_suite_load_case_from_fixture_with_report_fixture(self, *args):
)
))
suite = app.create_suite()
self.assertXmlPartialEqual(self.get_xml('load_case_from_report_fixture_session'), suite, './entry[2]/session')
self.assertXmlPartialEqual(self.get_xml('load_case_from_report_fixture_instance'), suite, './entry[2]/instance')
self.assertXmlPartialEqual(self.get_xml('load_case_from_report_fixture_session'), suite,
'./entry[2]/session')
self.assertXmlPartialEqual(self.get_xml('load_case_from_report_fixture_instance'), suite,
'./entry[2]/instance')

def test_advanced_suite_load_from_fixture(self, *args):
nodeset = "instance('item-list:table_tag')/calendar/year/month/day[@date > 735992 and @date < 736000]"
Expand Down Expand Up @@ -375,7 +380,8 @@ def test_advanced_module_remote_request(self, *args):
<partial>
<remote-request>
<post url="http://localhost:8000/a/domain/phone/claim-case/"
relevant="count(instance('casedb')/casedb/case[@case_id=instance('commcaresession')/session/data/search_case_id]) = 0">
relevant="count(instance('casedb')/casedb/""" +\
"""case[@case_id=instance('commcaresession')/session/data/search_case_id]) = 0">
<data key="case_id" ref="instance('commcaresession')/session/data/search_case_id"/>
</post>
<command id="search_command.m0">
Expand All @@ -390,7 +396,7 @@ def test_advanced_module_remote_request(self, *args):
<instance id="results" src="jr://instance/remote/results"/>
<session>
<query url="http://localhost:8000/a/domain/phone/search/123/"
storage-instance="results" template="case" default_search="false">
storage-instance="results" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down
12 changes: 6 additions & 6 deletions corehq/apps/app_manager/tests/test_suite_inline_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_inline_search(self):
<instance id="results:inline" src="jr://instance/remote/results:inline"/>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false">
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_inline_search_case_list_item(self):
<instance id="results:inline" src="jr://instance/remote/results:inline"/>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false">
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_inline_search_multi_select(self):
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{RESULTS_INSTANCE_INLINE}"
template="case" default_search="false">
template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down Expand Up @@ -395,7 +395,7 @@ def test_inline_search_with_parent_select(self):
nodeset="instance('casedb')/casedb/case[@case_type='case'][@status='open']"
value="./@case_id" detail-select="m2_case_short"/>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false">
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down Expand Up @@ -564,7 +564,7 @@ def test_child_module_with_inline_search_entry(self):
<datum id="case_id" nodeset="instance('casedb')/casedb/case[@case_type='case'][@status='open']"
value="./@case_id" detail-select="m0_case_short"/>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false">
storage-instance="{RESULTS_INSTANCE_INLINE}" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m1.inputs"/>
Expand Down Expand Up @@ -667,7 +667,7 @@ def _expected_entry_query(self, module, custom_instance):
<instance id="{custom_instance}" src="jr://instance/remote/{custom_instance}"/>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/"
storage-instance="{custom_instance}" template="case" default_search="false">
storage-instance="{custom_instance}" template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.{module}.inputs"/>
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/app_manager/tests/test_suite_registry_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_search_data_registry(self, *args):
<partial>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/" storage-instance="results"
template="case" default_search="false">
template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_inline_search_with_data_registry(self):
<instance id="results:inline" src="jr://instance/remote/results:inline"/>
<session>
<query url="http://localhost:8000/a/test_domain/phone/search/123/" storage-instance="{RESULTS_INSTANCE_INLINE}"
template="case" default_search="false">
template="case" default_search="false" dynamic_search="false">
<title>
<text>
<locale id="case_search.m0.inputs"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from unittest.mock import patch

from django.test import SimpleTestCase

from corehq.apps.app_manager.models import Module, Application, CaseSearch, CaseSearchProperty
from corehq.apps.app_manager.tests.app_factory import AppFactory
from corehq.apps.app_manager.tests.util import (
SuiteMixin,
patch_get_xform_resource_overrides,
)
from corehq.apps.builds.models import BuildSpec
from corehq.tests.util.xml import parse_normalize
from corehq.util.test_utils import flag_enabled


Expand Down Expand Up @@ -35,3 +40,41 @@ def test_split_screen_case_search_removes_search_again(self):
suite,
"./detail[@id='m0_search_short']/action[display/text/locale[@id='case_list_form.m0']]"
)


@patch_get_xform_resource_overrides()
class DynamicSearchSuiteTest(SimpleTestCase, SuiteMixin):
file_path = ('data', 'suite')

def setUp(self):
self.app = Application.new_app("domain", "Untitled Application")
self.app._id = '123'
self.app.split_screen_dynamic_search = True
self.app.build_spec = BuildSpec(version='2.53.0', build_number=1)
self.module = self.app.add_module(Module.new_module("Followup", None))

self.module.search_config = CaseSearch(
properties=[
CaseSearchProperty(name='name', label={'en': 'Name'}),
]
)
self.module.assign_references()
# wrap to have assign_references called
self.app = Application.wrap(self.app.to_json())
self.module = self.app.modules[0]

@flag_enabled('SPLIT_SCREEN_CASE_SEARCH')
@flag_enabled('DYNAMICALLY_UPDATE_SEARCH_RESULTS')
def test_dynamic_search_suite(self):
suite = self.app.create_suite()
suite = parse_normalize(suite, to_string=False)
self.assertEqual("true", suite.xpath("./remote-request[1]/session/query/@dynamic_search")[0])

@patch('corehq.apps.app_manager.models.ModuleBase.is_auto_select', return_value=True)
@flag_enabled('SPLIT_SCREEN_CASE_SEARCH')
@flag_enabled('DYNAMICALLY_UPDATE_SEARCH_RESULTS')
def test_dynamic_search_suite_disable_with_auto_select(self, mock):
suite = self.app.create_suite()
suite = parse_normalize(suite, to_string=False)
self.assertEqual(True, self.module.is_auto_select())
self.assertEqual("false", suite.xpath("./remote-request[1]/session/query/@dynamic_search")[0])
Loading
Loading