Skip to content

Commit

Permalink
fix and improvements to layout components
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Aug 26, 2024
1 parent 4ab7f34 commit 9bc4a9b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions addon/components/layout/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class LayoutHeaderComponent extends Component {
];

// If registry bridge is booted add to static items
if (this.hasExtension('@fleetbase/registry-bridge')) {
if (this.hasExtension('@fleetbase/registry-bridge-engine')) {
staticMenuItems.pushObject({
id: 'explore-extensions',
route: 'console.extensions',
Expand Down Expand Up @@ -292,6 +292,6 @@ export default class LayoutHeaderComponent extends Component {
}

hasExtension(extensionName) {
return this.extensions.find(({ name }) => name === extensionName);
return this.extensions.find(({ name }) => name === extensionName) !== undefined;
}
}
42 changes: 29 additions & 13 deletions addon/components/layout/sidebar/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class LayoutSidebarItemComponent extends Component {
@tracked doesntHavePermissions = false;
@tracked visible = true;

constructor(owner, { dropdownButtonRenderInPlace = true, permission = null, disabled = false, visible = true }) {
constructor (owner, { dropdownButtonRenderInPlace = true, permission = null, disabled = false, visible = true }) {
super(...arguments);

this.active = this.checkIfActive();
Expand All @@ -34,30 +34,46 @@ export default class LayoutSidebarItemComponent extends Component {
router.on('routeDidChange', this.trackActiveFlag);
}

willDestroy() {
willDestroy () {
super.willDestroy(...arguments);
const router = this.getRouter();
router.off('routeDidChange', this.trackActiveFlag);
}

@action trackActiveFlag() {
@action trackActiveFlag () {
this.active = this.checkIfActive();
}

@action checkIfActive() {
const { route, onClick, item } = this.args;
@action checkIfActive () {
const { route, onClick, item, model } = this.args;
const router = this.getRouter();
const currentRoute = router.currentRouteName;
const currentURL = router.currentURL;
const isInteractive = isBlank(route) && typeof onClick === 'function';
const isCurrentRoute = typeof route === 'string' && currentRoute.startsWith(route);
const isCurrentURL = currentURL === window.location.pathname;

if (isInteractive && !isBlank(item)) {
return isMenuItemActive(item.section, item.slug, item.view);
}

return typeof route === 'string' && currentRoute.startsWith(route);
// If model provided use the pathname to determine in addition
if (model) {
const routeHasModelParam = router.currentRoute.paramNames.length > 0;
if (routeHasModelParam) {
const routeModelParam = router.currentRoute.paramNames[0];
const routeModelParamValue = model[routeModelParam] ?? '';

return isCurrentRoute && isCurrentURL && currentURL.includes(routeModelParamValue);
}

return isCurrentRoute && isCurrentURL;
}

return isCurrentRoute;
}

@action onClick(event) {
@action onClick (event) {
if (this.isPointerWithinDropdownButton(event)) {
event.preventDefault();
return;
Expand Down Expand Up @@ -106,7 +122,7 @@ export default class LayoutSidebarItemComponent extends Component {
}
}

@action onDropdownItemClick(action, dd) {
@action onDropdownItemClick (action, dd) {
const context = this.getDropdownContext(action);

if (typeof dd.actions === 'object' && typeof dd.actions.close === 'function') {
Expand All @@ -122,7 +138,7 @@ export default class LayoutSidebarItemComponent extends Component {
}
}

getDropdownContext(action) {
getDropdownContext (action) {
let context = null;

if (action && action.context) {
Expand All @@ -136,13 +152,13 @@ export default class LayoutSidebarItemComponent extends Component {
return context;
}

@action onRegisterAPI() {
@action onRegisterAPI () {
if (typeof this.args.registerAPI === 'function') {
this.args.registerAPI(...arguments);
}
}

@action onDropdownButtonInsert(dropdownButtonNode) {
@action onDropdownButtonInsert (dropdownButtonNode) {
if (dropdownButtonNode) {
this.dropdownButtonNode = dropdownButtonNode;

Expand All @@ -152,7 +168,7 @@ export default class LayoutSidebarItemComponent extends Component {
}
}

isPointerWithinDropdownButton({ target }) {
isPointerWithinDropdownButton ({ target }) {
const isTargetDropdownItem = target.classList.contains('next-dd-item');

if (this.dropdownButtonNode) {
Expand All @@ -167,7 +183,7 @@ export default class LayoutSidebarItemComponent extends Component {
return false;
}

getRouter() {
getRouter () {
return this.router ?? this.hostRouter;
}
}

0 comments on commit 9bc4a9b

Please sign in to comment.