Skip to content

Commit

Permalink
Fix: Prevent _customRouteId from being ignored, allow hidden content …
Browse files Browse the repository at this point in the history
…objects (fixes #68 #69)
  • Loading branch information
oliverfoster authored Jun 25, 2024
2 parents 330a72b + 46cd185 commit 7182f8f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* A sentence describing each fix

### Update
* A sentence describing each udpate
* A sentence describing each update

### New
* A sentence describing each new feature
Expand Down
19 changes: 9 additions & 10 deletions js/PageNavModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ class PageNavModel extends ComponentModel {
if (!buttonConfig._isEnabled) continue;

// Get models, skipping any undefined types (ex. deprecated button types)
let buttonModel = buttonTypeModels[type];
if (!buttonModel) continue;

// Find buttonModel from config._customRouteId if not found in defined type
if (buttonConfig._customRouteId) {
buttonModel = data.findById(buttonConfig._customRouteId);
}
const buttonModel = buttonConfig._customRouteId
? data.findById(buttonConfig._customRouteId)
: buttonTypeModels[type];

if (!buttonModel) continue;

// Convert found buttonModel to json if exists or create an 'undefined' json
item = buttonModel ? buttonModel.toJSON() : { _isHidden: true };
Expand Down Expand Up @@ -106,8 +105,8 @@ class PageNavModel extends ComponentModel {
let hasFoundCurrentPage = false;

for (const page of pages.reverse()) {
const isNotAvailable = !page.get('_isAvailable');
if (isNotAvailable) continue;
const isNotShown = !page.get('_isAvailable') || page.get('_isHidden');
if (isNotShown) continue;

if (!hasFoundCurrentPage) {
hasFoundCurrentPage = page.get('_id') === currentPageId;
Expand All @@ -127,8 +126,8 @@ class PageNavModel extends ComponentModel {
let hasFoundCurrentPage = false;

for (const page of pages) {
const isNotAvailable = !page.get('_isAvailable');
if (isNotAvailable) continue;
const isNotShown = !page.get('_isAvailable') || page.get('_isHidden');
if (isNotShown) continue;

if (!hasFoundCurrentPage) {
hasFoundCurrentPage = page.get('_id') === currentPageId;
Expand Down
6 changes: 2 additions & 4 deletions js/PageNavView.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class PageNavView extends ComponentView {
return;
}

// Check if locked
const isLocked = item._isHidden || item._isLocked;
if (isLocked) return;
if (item._isLocked) return;

this.navigateTo(item._id);
};
Expand All @@ -67,7 +65,7 @@ class PageNavView extends ComponentView {
setupTooltips() {
const items = this.model.get('_items');
items.forEach(item => {
if (!item._tooltip || item._isHidden) return;
if (!item._tooltip) return;

tooltips.register({
_id: item._tooltipId,
Expand Down
6 changes: 2 additions & 4 deletions templates/pageNavItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function PageNavItem(props) {
_iconClass,
_id,
_index,
_isHidden,
_tooltipId,
ariaLabel,
locked,
Expand All @@ -27,17 +26,16 @@ export default function PageNavItem(props) {
_iconClass && 'btn-icon has-icon',
_iconAlignment && `has-icon-${_iconAlignment}`,
text && 'btn-text has-text',
_isHidden && 'is-hidden',
locked && 'is-locked',
(_isHidden || locked) && 'is-disabled',
locked && 'is-disabled',
_classes
])}
role="link"
data-type={type}
data-id={_id}
data-item-index={_index}
data-tooltip-id={_tooltipId}
disabled={_isHidden || locked}
disabled={locked}
aria-label={`${locked ? globals._accessibility._ariaLabels.locked + '. ' : ''}${compile(ariaLabel, props)}`}
onClick={onButtonClick}
>
Expand Down

0 comments on commit 7182f8f

Please sign in to comment.