From 33a40f59eb8af0a8705512a41efd4bf61ec722bf Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 26 Mar 2019 12:20:58 -0400 Subject: [PATCH] Remove lodash includes and reduce from address.js (re #6087) --- modules/ui/fields/address.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index f0ee18c34..d60239f53 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -1,5 +1,3 @@ -import _includes from 'lodash-es/includes'; -import _reduce from 'lodash-es/reduce'; import _uniqBy from 'lodash-es/uniqBy'; import { dispatch as d3_dispatch } from 'd3-dispatch'; @@ -113,10 +111,18 @@ export function uiFieldAddress(field, context) { function countryCallback(err, countryCode) { if (err) return; + countryCode = countryCode.toLowerCase(); - var addressFormat = dataAddressFormats.find(function (a) { - return a && a.countryCodes && _includes(a.countryCodes, countryCode.toLowerCase()); - }) || dataAddressFormats[0]; + var addressFormat; + for (var i = 0; i < dataAddressFormats.length; i++) { + var format = dataAddressFormats[i]; + if (!format.countryCodes) { + addressFormat = format; // choose the default format, keep going + } else if (format.countryCodes.indexOf(countryCode) !== -1) { + addressFormat = format; // choose the country format, stop here + break; + } + } var dropdowns = addressFormat.dropdowns || [ 'city', 'county', 'country', 'district', 'hamlet', @@ -131,7 +137,7 @@ export function uiFieldAddress(field, context) { function row(r) { // Normalize widths. - var total = _reduce(r, function(sum, key) { + var total = r.reduce(function(sum, key) { return sum + (widths[key] || 0.5); }, 0); @@ -154,7 +160,7 @@ export function uiFieldAddress(field, context) { .append('input') .property('type', 'text') .attr('placeholder', function (d) { - var localkey = d.id + '!' + countryCode.toLowerCase(); + var localkey = d.id + '!' + countryCode; var tkey = field.strings.placeholders[localkey] ? localkey : d.id; return field.t('placeholders.' + tkey); })