Skip to content

Commit

Permalink
Merge pull request #33876 from dimagi/rc/hide-cancel-search-buttons
Browse files Browse the repository at this point in the history
Hide Search and Clear buttons
  • Loading branch information
Robert-Costello committed Dec 18, 2023
2 parents 4d6b0cf + e88d2e2 commit 3e11c9e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ hqDefine("cloudcare/js/formplayer/constants", function () {
FORMAT_ADDRESS_POPUP: "AddressPopup",
FORMAT_CLICKABLE_ICON: "ClickableIcon",

ENTITIES: "entities",
QUERY: "query",

SMALL_SCREEN_WIDTH_PX: 992,

BREADCRUMB_HEIGHT_PX: 46.125,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
formplayerUtils = hqImport("cloudcare/js/formplayer/utils/utils"),
menusUtils = hqImport("cloudcare/js/formplayer/menus/utils"),
views = hqImport("cloudcare/js/formplayer/menus/views"),
toggles = hqImport("hqwebapp/js/toggles"),
QueryListView = hqImport("cloudcare/js/formplayer/menus/views/query"),
initialPageData = hqImport("hqwebapp/js/initial_page_data").get,
Collection = hqImport("cloudcare/js/formplayer/menus/collections");
Expand Down Expand Up @@ -107,9 +106,9 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
var showMenu = function (menuResponse) {
var menuListView = menusUtils.getMenuView(menuResponse);
var appPreview = FormplayerFrontend.currentUser.displayOptions.singleAppMode;
var sidebarEnabled = toggles.toggleEnabled('SPLIT_SCREEN_CASE_SEARCH') && !appPreview;

if (sidebarEnabled && menuResponse.type === "query") {
var queryResponse = menuResponse.queryResponse;
var sidebarEnabled = !appPreview && menusUtils.isSidebarEnabled(menuResponse);
if (sidebarEnabled && menuResponse.type === constants.QUERY) {
var menuData = menusUtils.getMenuData(menuResponse);
menuData["triggerEmptyCaseList"] = true;
menuData["sidebarEnabled"] = true;
Expand All @@ -126,8 +125,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
FormplayerFrontend.regions.getRegion('persistentCaseTile').empty();
}

var queryResponse = menuResponse.queryResponse;
if (sidebarEnabled && menuResponse.type === "entities" && queryResponse) {
if (sidebarEnabled && menuResponse.type === constants.ENTITIES && queryResponse) {
var queryCollection = new Collection(queryResponse.displays);
FormplayerFrontend.regions.getRegion('sidebar').show(
QueryListView({
Expand All @@ -139,7 +137,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
disableDynamicSearch: !sessionStorage.submitPerformed,
}).render()
);
} else if (sidebarEnabled && menuResponse.type === "query") {
} else if (sidebarEnabled && menuResponse.type === constants.QUERY) {
FormplayerFrontend.regions.getRegion('sidebar').show(
QueryListView({
collection: menuResponse,
Expand All @@ -161,7 +159,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
if (isFormEntry) {
menusUtils.showMenuDropdown(menuResponse.langs, initialPageData('lang_code_name_mapping'));
}
if (menuResponse.type === "entities") {
if (menuResponse.type === constants.ENTITIES) {
menusUtils.showMenuDropdown();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ hqDefine("cloudcare/js/formplayer/menus/utils", function () {
QueryView = hqImport("cloudcare/js/formplayer/menus/views/query"),
toggles = hqImport("hqwebapp/js/toggles"),
utils = hqImport("cloudcare/js/formplayer/utils/utils"),
views = hqImport("cloudcare/js/formplayer/menus/views");
views = hqImport("cloudcare/js/formplayer/menus/views"),
constants = hqImport("cloudcare/js/formplayer/constants");

var recordPosition = function (position) {
sessionStorage.locationLat = position.coords.latitude;
Expand Down Expand Up @@ -96,11 +97,11 @@ hqDefine("cloudcare/js/formplayer/menus/utils", function () {

if (langs && langs.length > 1) {
langModels = _.map(langs, function (lang) {
let matchingLanguage = langCodeNameMapping[lang];
return {
lang_code: lang,
lang_label: matchingLanguage ? matchingLanguage : lang,
};
let matchingLanguage = langCodeNameMapping[lang];
return {
lang_code: lang,
lang_label: matchingLanguage ? matchingLanguage : lang,
};
});
langCollection = new Backbone.Collection(langModels);
} else {
Expand Down Expand Up @@ -156,14 +157,23 @@ hqDefine("cloudcare/js/formplayer/menus/utils", function () {
}
};

var isSidebarEnabled = function (menuResponse) {
const splitScreenCaseSearchEnabled = toggles.toggleEnabled('SPLIT_SCREEN_CASE_SEARCH');
if (menuResponse.type === constants.QUERY) {
return splitScreenCaseSearchEnabled && menuResponse.models && menuResponse.models.length > 0;
} else if (menuResponse.type === constants.ENTITIES) {
return splitScreenCaseSearchEnabled && menuResponse.queryResponse && menuResponse.queryResponse.displays.length > 0;
}
};

var getMenuView = function (menuResponse) {
var menuData = getMenuData(menuResponse);
var urlObject = utils.currentUrlToObject();

sessionStorage.queryKey = menuResponse.queryKey;
if (menuResponse.type === "commands") {
return views.MenuListView(menuData);
} else if (menuResponse.type === "query") {
} else if (menuResponse.type === constants.QUERY) {
var props = {
domain: FormplayerFrontend.getChannel().request('currentUser').domain,
};
Expand All @@ -177,13 +187,13 @@ hqDefine("cloudcare/js/formplayer/menus/utils", function () {
forceManualSearch: false,
});
return QueryView(menuData);
} else if (menuResponse.type === "entities") {
} else if (menuResponse.type === constants.ENTITIES) {
var searchText = urlObject.search;
var event = "Viewed Case List";
if (searchText) {
event = "Searched Case List";
}
if (menuResponse.queryResponse) {
if (isSidebarEnabled(menuResponse)) {
menuData.sidebarEnabled = true;
}
var eventData = {
Expand Down Expand Up @@ -213,5 +223,6 @@ hqDefine("cloudcare/js/formplayer/menus/utils", function () {
showBreadcrumbs: showBreadcrumbs,
showMenuDropdown: showMenuDropdown,
startOrStopLocationWatching: startOrStopLocationWatching,
isSidebarEnabled: isSidebarEnabled,
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ hqDefine("cloudcare/js/formplayer/spec/split_screen_case_search_spec", function
});

it('should show sidebar and main regions with query type split screen case search', function () {
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, { 'type': 'query' });
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, { 'type': 'query' , 'models': [{}]});
Controller.showMenu(responseWithTypeQuery);

assert.isTrue(stubs.regions['sidebar'].show.called);
assert.isTrue(stubs.regions['main'].show.called);
});

it('should explicitly set sidebarEnabled and triggerEmptyCaseList with query type split screen case search', function () {
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, { 'type': 'query' });
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, { 'type': 'query', 'models': [{}] });
Controller.showMenu(responseWithTypeQuery);

assert.isTrue(stubs.regions['main'].show.called);
Expand All @@ -83,6 +83,22 @@ hqDefine("cloudcare/js/formplayer/spec/split_screen_case_search_spec", function
assert.isTrue(showMain.args[0].options.triggerEmptyCaseList);
});

it('should hide sidebar if there are no search inputs in query response', function () {
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, { 'type': 'query'});
Controller.showMenu(responseWithTypeQuery);

assert.isTrue(stubs.regions['sidebar'].empty.called);
});

it('should hide sidebar if there are no search inputs in entities response', function () {
let queryResponse = splitScreenCaseListResponse.queryResponse;
queryResponse = _.extend({}, queryResponse, {'displays': {}});
const responseWithTypeQuery = _.extend({}, splitScreenCaseListResponse, {'queryResponse': queryResponse});
Controller.showMenu(responseWithTypeQuery);

assert.isTrue(stubs.regions['sidebar'].empty.called);
});

it('should empty sidebar if in app preview', function () {
FormplayerFrontend.currentUser.displayOptions.singleAppMode = true;
Controller.showMenu(splitScreenCaseListResponse);
Expand Down

0 comments on commit 3e11c9e

Please sign in to comment.