Skip to content

Commit

Permalink
Merge pull request #35045 from dimagi/revert-35023-jt/locations-displ…
Browse files Browse the repository at this point in the history
…ay-name

Revert "Use Locations Display Name"
  • Loading branch information
AmitPhulera authored Aug 27, 2024
2 parents 83b9580 + 92d3267 commit e981a4e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 39 deletions.
7 changes: 2 additions & 5 deletions corehq/apps/locations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from dimagi.utils.couch.database import iter_docs

from corehq import toggles
from corehq.feature_previews import USE_LOCATION_DISPLAY_NAME
from corehq.apps.custom_data_fields.edit_entity import (
CUSTOM_DATA_FIELD_PREFIX,
CustomDataEditor,
Expand All @@ -33,7 +32,6 @@
from corehq.apps.users.models import CommCareUser
from corehq.apps.users.util import user_display_string
from corehq.util.quickcache import quickcache
from corehq.util.global_request import get_request_domain

from .models import (
LocationFixtureConfiguration,
Expand Down Expand Up @@ -63,11 +61,10 @@ def render(self, name, value, attrs=None, renderer=None):
location_ids = to_list(value) if value else []
locations = list(SQLLocation.active_objects
.filter(domain=self.domain, location_id__in=location_ids))
use_location_display_name = USE_LOCATION_DISPLAY_NAME.enabled(get_request_domain())

initial_data = [{
'id': loc.location_id,
'text': loc.display_name if use_location_display_name else loc.get_path_display(),
'tooltip': loc.get_path_display() if use_location_display_name else loc.display_name,
'text': loc.get_path_display(),
} for loc in locations]

return get_template(self.template).render({
Expand Down
16 changes: 4 additions & 12 deletions corehq/apps/locations/static/locations/js/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ hqDefine("locations/js/widgets", [
_.each($source.select2('data'), function (result) {
const fullLengthName = result.text || result.name;
const truncatedName = truncateLocationName(fullLengthName, $select);
var $option = new Option(truncatedName, result.id);
$option.setAttribute('title', result.tooltip || result.title);
$select.append($option);
$select.append(new Option(truncatedName, result.id));
});
}

Expand Down Expand Up @@ -98,9 +96,7 @@ hqDefine("locations/js/widgets", [
},
},
templateResult: function (result) {
var $option = new Option(result.text);
$option.setAttribute('title', result.tooltip);
return $option;
return result.text || result.name;
},
templateSelection: function (result) {
const fullLengthName = result.text || result.name;
Expand All @@ -115,9 +111,7 @@ hqDefine("locations/js/widgets", [
initial = [initial];
}
_.each(initial, function (result) {
var $option = new Option(result.text, result.id);
$option.setAttribute('title', result.tooltip);
$select.append($option);
$select.append(new Option(result.text, result.id));
});
$select.val(_.pluck(initial, 'id')).trigger('change');
}
Expand All @@ -144,9 +138,7 @@ hqDefine("locations/js/widgets", [
// This custom event is fired in autocomplete_select_widget.html
if ($source.hasClass("select2-hidden-accessible")) {
updateSelect2($source, $select);
var $option = new Option(value.text, value.id);
$option.setAttribute('title', value.tooltip);
$select.append($option);
$select.append(new Option(value.text, value.id));
$select.val(value.id).trigger("change");
} else {
$source.on('select-ready', function () {
Expand Down
3 changes: 1 addition & 2 deletions corehq/apps/reports/filters/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def get_options(self, show_more=False):
)
results = [
{'id': entry[0], 'text': entry[1]} if len(entry) == 2 else
{'id': entry[0], 'text': entry[1], 'is_active': entry[2]} if len(entry) == 3 else
{'id': entry[0], 'text': entry[1], 'is_active': entry[2], 'tooltip': entry[3]} for entry
{'id': entry[0], 'text': entry[1], 'is_active': entry[2]} for entry
in options
]

Expand Down
8 changes: 2 additions & 6 deletions corehq/apps/reports/filters/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from memoized import memoized

from corehq import toggles
from corehq.feature_previews import USE_LOCATION_DISPLAY_NAME
from corehq.apps.domain.models import Domain
from corehq.apps.enterprise.models import EnterprisePermissions
from corehq.apps.es import filters
Expand All @@ -21,7 +20,6 @@
from corehq.apps.users.models import CommCareUser, UserHistory, WebUser
from corehq.apps.users.util import cached_user_id_to_user_display
from corehq.const import USER_DATETIME_FORMAT
from corehq.util.global_request import get_request_domain
from corehq.util.timezones.conversions import ServerTime
from corehq.util.timezones.utils import get_timezone_for_user

Expand Down Expand Up @@ -140,13 +138,11 @@ def user_type_tuple(self, t):

def location_tuple(self, location):
location_id = location.location_id
use_location_display_name = USE_LOCATION_DISPLAY_NAME.enabled(get_request_domain())
text = location.display_name if use_location_display_name else location.get_path_display()
tooltip = location.get_path_display() if use_location_display_name else location.display_name
text = location.get_path_display()
if self.namespace_locations:
location_id = f'l__{location_id}'
text = f'{text} [location]'
return (location_id, text, None, tooltip)
return (location_id, text)

@property
@memoized
Expand Down
6 changes: 1 addition & 5 deletions corehq/apps/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@
from corehq.apps.user_importer.helpers import UserChangeLogger
from corehq.const import LOADTEST_HARD_LIMIT, USER_CHANGE_VIA_WEB
from corehq.pillows.utils import MOBILE_USER_TYPE, WEB_USER_TYPE
from corehq.feature_previews import USE_LOCATION_DISPLAY_NAME
from corehq.toggles import (
LOCATION_HAS_USERS,
TWO_STAGE_USER_PROVISIONING,
TWO_STAGE_USER_PROVISIONING_BY_SMS,
)
from corehq.util.global_request import get_request_domain

from ..hqwebapp.signals import clear_login_attempts
from .audit.change_messages import UserChangeMessage
Expand Down Expand Up @@ -1127,11 +1125,9 @@ def render(self, name, value, attrs=None, renderer=None):
if value:
try:
loc = SQLLocation.objects.get(location_id=value)
use_location_display_name = USE_LOCATION_DISPLAY_NAME.enabled(get_request_domain())
initial_data = {
'id': loc.location_id,
'text': loc.display_name if use_location_display_name else loc.get_path_display(),
'tooltip': loc.get_path_display() if use_location_display_name else loc.display_name,
'text': loc.get_path_display(),
}
except SQLLocation.DoesNotExist:
pass
Expand Down
9 changes: 0 additions & 9 deletions corehq/feature_previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ def previews_enabled_for_domain(domain):
)
)

USE_LOCATION_DISPLAY_NAME = FeaturePreview(
slug='use_location_display_name',
label=_('Use location name'),
description=_(
"This setting changes the location dropdown to display location name instead of "
"the full location path."
)
)


def enable_callcenter(domain_name, checked):
from corehq.apps.domain.models import Domain
Expand Down

0 comments on commit e981a4e

Please sign in to comment.