Skip to content

Commit

Permalink
Merge pull request #35071 from dimagi/jt/visually-denote-current-pers…
Browse files Browse the repository at this point in the history
…isent-menu

Visually Denote Active Persistent Menu Item
  • Loading branch information
Jtang-1 authored Aug 30, 2024
2 parents 0784740 + 12d01d1 commit 8b7b7cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", [
if (!appPreview && menuResponse.persistentMenu) {
FormplayerFrontend.regions.getRegion('persistentMenu').show(
views.PersistentMenuView({
collection: _toMenuCommands(menuResponse.persistentMenu, []),
collection: _toMenuCommands(menuResponse.persistentMenu, [], menuResponse.selections),
}).render());
} else {
FormplayerFrontend.regions.getRegion('persistentMenu').empty();
Expand All @@ -170,7 +170,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", [
}
};

var _toMenuCommands = function (menuCommands, priorSelections) {
var _toMenuCommands = function (menuCommands, priorSelections, activeSelection) {
return new Backbone.Collection(_.map(menuCommands, function (menuCommand) {
const command = _.pick(menuCommand, [
'index',
Expand All @@ -181,7 +181,10 @@ hqDefine("cloudcare/js/formplayer/menus/controller", [
]);
// Store an array of the commands needed to navigate to each nested menu item
command.selections = priorSelections.concat([command.index]);
command.commands = _toMenuCommands(command.commands, command.selections);
if (JSON.stringify(command.selections) === JSON.stringify(activeSelection)) {
command.isActiveSelection = true;
}
command.commands = _toMenuCommands(command.commands, command.selections, activeSelection);
return new Backbone.Model(command);
}));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1499,10 +1499,11 @@ hqDefine("cloudcare/js/formplayer/menus/views", [
templateContext: function () {
const appId = formplayerUtils.currentUrlToObject().appId,
imageUri = this.model.get('imageUri'),
icons = {JUMP: 'fa-pencil', NEXT: 'fa-regular fa-folder', ENTITY_SELECT: 'fa-list-ul'};
icons = {JUMP: 'fa-pencil', NEXT: 'fa-regular fa-folder', ENTITY_SELECT: 'fa-list-ul'};
return {
imageUri: imageUri ? FormplayerFrontend.getChannel().request('resourceMap', imageUri, appId) : "",
iconClass: icons[this.model.get('navigationState')] || 'fa-arrow-up-right-from-square',
isActive: this.model.get('isActiveSelection'),
};
},
onRender: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h5 class="offcanvas-title position-relative" id="persistent-menu-label">
<% } else { %>
<i class="fa <%- iconClass %> persistent-menu-image" aria-hidden="true"></i>
<% } %>
<a class="align-middle stretched-link text-reset" href="#"
<a class="align-middle stretched-link text-reset <%= isActive ? 'fw-bold' : '' %>" href="#"
data-bs-toggle="offcanvas" data-bs-target="#persistent-menu-container">
<%- displayText %>
</a>
Expand Down

0 comments on commit 8b7b7cb

Please sign in to comment.