Skip to content

Commit

Permalink
Merge pull request #33849 from dimagi/riese/lazy_config_3
Browse files Browse the repository at this point in the history
Add config for lazy loading case lists
  • Loading branch information
Jtang-1 authored Dec 7, 2023
2 parents a804489 + 2dc1dcd commit 7d30444
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@ class Module(ModuleBase, ModuleDetailsMixin):
parent_select = SchemaProperty(ParentSelect)
search_config = SchemaProperty(CaseSearch)
display_style = StringProperty(default='list')
lazy_load_case_list_fields = BooleanProperty(default=False)

@classmethod
def new_module(cls, name, lang):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ hqDefine("app_manager/js/modules/module_view", function () {
});
}

$('#lazy-load-case-list-fields').koApplyBindings({
lazy_load_case_list_fields: ko.observable(initial_page_data('lazy_load_case_list_fields')),
});

// Registration in case list
if ($('#case-list-form').length) {
var caseListFormModel = function (originalFormId, formOptions, postFormWorkflow) {
Expand Down
3 changes: 3 additions & 0 deletions corehq/apps/app_manager/suite_xml/features/case_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def build_case_tile_detail(self):
header_rows=self.detail.case_tile_group.header_rows
)

if (self.detail_type == 'case_short' or self.detail_type == 'search_short') \
and hasattr(self.module, 'lazy_load_case_list_fields') and self.module.lazy_load_case_list_fields:
detail.lazy_loading = self.module.lazy_load_case_list_fields
return detail

def _get_matched_detail_column(self, case_tile_field):
Expand Down
4 changes: 4 additions & 0 deletions corehq/apps/app_manager/suite_xml/sections/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def build_detail(self, module, detail_type, detail, detail_column_infos, tabs=No
"""
from corehq.apps.app_manager.detail_screen import get_column_generator
d = Detail(id=id, title=title, nodeset=nodeset, print_template=print_template, relevant=relevant)
if (detail_type == 'case_short' or detail_type == 'search_short') \
and hasattr(module, 'lazy_load_case_list_fields') and module.lazy_load_case_list_fields:
d.lazy_loading = module.lazy_load_case_list_fields

self._add_custom_variables(detail, d)
if tabs:
tab_spans = detail.get_tab_spans()
Expand Down
5 changes: 4 additions & 1 deletion corehq/apps/app_manager/suite_xml/xml_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ class TileGroup(XmlObject):

class Detail(OrderedXmlObject, IdNode):
"""
<detail id="">
<detail id="" lazy_loading="false">
<title><text/></title>
<lookup action="" image="" name="">
<extra key="" value = "" />
Expand All @@ -909,6 +909,9 @@ class Detail(OrderedXmlObject, IdNode):
"""

ROOT_NAME = 'detail'

lazy_loading = BooleanField('@lazy_loading')

ORDER = ('title', 'lookup', 'no_items_text', 'details', 'fields')

nodeset = StringField('@nodeset')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{% initial_page_data 'form_endpoint_options' form_endpoint_options %}
{% initial_page_data 'case_list_form_not_allowed_reasons' case_list_form_not_allowed_reasons %}
{% initial_page_data 'case_type' module.case_type %}
{% initial_page_data 'lazy_load_case_list_fields' module.lazy_load_case_list_fields %}
{% initial_page_data 'multimedia_upload_managers' multimedia.upload_managers_js %}
{% initial_page_data 'nav_menu_media_specifics' nav_menu_media_specifics %}
{% initial_page_data 'parent_case_modules' parent_case_modules %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% load i18n %}
{% load hq_shared_tags %}
<label class="control-label col-sm-2">
{% trans "Lazy load Case List fields" %}
<span class="hq-help-template"
data-title="{% trans "Incrementally load case list fields" %}"
data-content="{% blocktrans %}Case list only calculates display properties for a case if the user sees it on the page{% endblocktrans %}"
></span>
</label>
<div id="lazy-load-case-list-fields" class="col-sm-8 commcare-feature" data-since-version="2.54">
<input type="checkbox" value="true"
data-bind="checked: lazy_load_case_list_fields"/>
<input type="hidden" name="lazy_load_case_list_fields" data-bind="value: lazy_load_case_list_fields"/>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ <h4 class="panel-title panel-title-nolink">{% trans "Advanced" %}</h4>
{% endif %}
{% endif %}

{% if request|toggle_enabled:'CASE_LIST_LAZY' and app.cloudcare_enabled %}
<div class="form-group">
{% include "app_manager/partials/modules/case_list_lazy_loading.html" %}
</div>
{% endif %}

{% if request|toggle_enabled:'USH_EMPTY_CASE_LIST_TEXT' %}
<div class="form-group">
<label for="no_items_text" class="{% css_label_class %} control-label">
Expand Down
4 changes: 4 additions & 0 deletions corehq/apps/app_manager/views/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ def edit_module_attr(request, domain, app_id, module_unique_id, attr):
"session_endpoint_id": None,
"case_list_session_endpoint_id": None,
'custom_assertions': None,
'lazy_load_case_list_fields': None,
}

if attr not in attributes:
Expand Down Expand Up @@ -824,6 +825,9 @@ def should_edit(attribute):
raw_endpoint_id = request.POST['case_list_session_endpoint_id']
set_case_list_session_endpoint(module, raw_endpoint_id, app)

if should_edit('lazy_load_case_list_fields'):
module["lazy_load_case_list_fields"] = request.POST.get("lazy_load_case_list_fields") == 'true'

if should_edit('custom_assertions'):
module.custom_assertions = validate_custom_assertions(
request.POST.get('custom_assertions'),
Expand Down
9 changes: 9 additions & 0 deletions corehq/toggles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,15 @@ def _ensure_valid_randomness(randomness):
'spaceKey=saas&title=Allow+Configuration+of+Case+List+Tiles',
)

CASE_LIST_LAZY = StaticToggle(
'case_list_lazy',
'USH: Add option to lazy load case list',
TAG_CUSTOM,
[NAMESPACE_DOMAIN],
help_link='https://confluence.dimagi.com/pages/viewpage.action?'
'spaceKey=saas&title=Allow+Configuration+of+Case+List+Lazy',
)

SHOW_PERSIST_CASE_CONTEXT_SETTING = StaticToggle(
'show_persist_case_context_setting',
'Allow toggling the persistent case context tile',
Expand Down

0 comments on commit 7d30444

Please sign in to comment.