diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/constants.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/constants.js index 8f33a2b790c9..ba05ba5989f0 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/constants.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/constants.js @@ -30,6 +30,12 @@ hqDefine("cloudcare/js/formplayer/constants", function () { ENTITIES: "entities", QUERY: "query", + // values are snake case as recommended for Datadog tags + queryInitiatedBy: { + DYNAMIC_SEARCH: 'dynamic_search', + FIELD_CHANGE: "field_change", + }, + SMALL_SCREEN_WIDTH_PX: 992, BREADCRUMB_HEIGHT_PX: 46.125, diff --git a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js index 437235349281..05344ea9219c 100644 --- a/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js +++ b/corehq/apps/cloudcare/static/cloudcare/js/formplayer/menus/api.js @@ -172,7 +172,7 @@ hqDefine("cloudcare/js/formplayer/menus/api", function () { var callStartTime = performance.now(); menus.fetch($.extend(true, {}, options)).always(function () { - if (data.query_data && data.query_data.results && data.query_data.results.initiatedBy === "dynamicSearch") { + if (data.query_data && data.query_data.results && data.query_data.results.initiatedBy === constants.queryInitiatedBy.DYNAMIC_SEARCH) { var callEndTime = performance.now(); var callResponseTime = callEndTime - callStartTime; $.ajax(initialPageData.reverse('api_histogram_metrics'), { 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 a5a268627276..c83de350b53e 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 @@ -6,7 +6,8 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { var kissmetrics = hqImport("analytix/js/kissmetrix"), cloudcareUtils = hqImport("cloudcare/js/utils"), markdown = hqImport("cloudcare/js/markdown"), - constants = hqImport("cloudcare/js/form_entry/const"), + formEntryConstants = hqImport("cloudcare/js/form_entry/const"), + formplayerConstants = hqImport("cloudcare/js/formplayer/constants"), formEntryUtils = hqImport("cloudcare/js/form_entry/utils"), FormplayerFrontend = hqImport("cloudcare/js/formplayer/app"), formplayerUtils = hqImport("cloudcare/js/formplayer/utils/utils"), @@ -128,7 +129,7 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { geocoderOnClearCallback = function (addressTopic) { return function () { kissmetrics.track.event("Accessibility Tracking - Geocoder Interaction in Case Search"); - $.publish(addressTopic, constants.NO_ANSWER); + $.publish(addressTopic, formEntryConstants.NO_ANSWER); }; }, updateReceiver = function (element) { @@ -137,8 +138,8 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { var receiveExpression = element.data().receive; var receiveField = receiveExpression.split("-")[1]; var value = null; - if (broadcastObj === undefined || broadcastObj === constants.NO_ANSWER) { - value = constants.NO_ANSWER; + if (broadcastObj === undefined || broadcastObj === formEntryConstants.NO_ANSWER) { + value = formEntryConstants.NO_ANSWER; } else if (broadcastObj[receiveField]) { value = broadcastObj[receiveField]; } else { @@ -400,7 +401,7 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { // Geocoder doesn't have a real value, doesn't need to be sent to formplayer return; } - this.parentView.notifyFieldChange(e, this, useDynamicSearch); + this.parentView.notifyFieldChange(e, this, useDynamicSearch, formplayerConstants.queryInitiatedBy.FIELD_CHANGE); }, toggleBlankSearch: function (e) { @@ -664,10 +665,10 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { return answers; }, - notifyFieldChange: function (e, changedChildView, useDynamicSearch) { + notifyFieldChange: function (e, changedChildView, useDynamicSearch, initiatedBy) { e.preventDefault(); var self = this; - self.validateFieldChange(changedChildView).always(function (response) { + self.validateFieldChange(changedChildView, initiatedBy).always(function (response) { var $fields = $(".query-field"); for (var i = 0; i < response.models.length; i++) { var choices = response.models[i].get('itemsetChoices'); @@ -742,15 +743,15 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { } }); if (invalidRequiredFields.length === 0) { - self.performSubmit("dynamicSearch"); + self.performSubmit(formplayerConstants.queryInitiatedBy.DYNAMIC_SEARCH); } }, - validateFieldChange: function (changedChildView) { + validateFieldChange: function (changedChildView, initiatedBy) { var self = this; var promise = $.Deferred(); - self._updateModelsForValidation().done(function (response) { + self._updateModelsForValidation(initiatedBy).done(function (response) { //Gather error messages self._getChildren().forEach(function (childView) { //Filter out empty required fields and check for validity @@ -800,7 +801,7 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { return promise; }, - _updateModelsForValidation: function () { + _updateModelsForValidation: function (initiatedBy) { var self = this; var promise = $.Deferred(); self.updateModelsForValidation = promise; @@ -810,7 +811,7 @@ hqDefine("cloudcare/js/formplayer/menus/views/query", function () { inputs: self.getAnswers(), execute: false, forceManualSearch: true, - + initiatedBy: initiatedBy, }); var fetchingPrompts = FormplayerFrontend.getChannel().request("app:select:menus", urlObject); $.when(fetchingPrompts).done(function (response) {