Skip to content

Commit

Permalink
feat: visually denote active persistent menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
Jtang-1 committed Aug 29, 2024
1 parent 772c987 commit 12d01d1
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 12d01d1

Please sign in to comment.