Skip to content

Commit

Permalink
Merge pull request #11660 from andrewballantyne/support-startsWith-na…
Browse files Browse the repository at this point in the history
…v-property

Bug 2090895: Support startsWith Nav Extension property
  • Loading branch information
openshift-ci[bot] committed Jun 17, 2022
2 parents 7500dbd + ebe1717 commit 855b4e3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions frontend/public/components/nav/NavLink.tsx
Expand Up @@ -12,8 +12,9 @@ export class NavLink<P extends NavLinkProps> extends React.PureComponent<P> {
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
static isActive(...args): boolean {
throw new Error('not implemented');
static isActive(props: NavLinkProps, location: string, activeNamespace?: string): boolean {
const { startsWith } = props;
return startsWith?.some((path) => location.startsWith(path));
}

get to(): string {
Expand Down
6 changes: 5 additions & 1 deletion frontend/public/components/nav/NavLinkHref.tsx
Expand Up @@ -7,7 +7,11 @@ import { formatNamespacedRouteForHref, formatNamespacedRouteForResource } from '
export class NavLinkHref extends NavLink<NavLinkHrefProps> {
static isActive(props, resourcePath) {
const noNSHref = stripNS(props.href);
return resourcePath === noNSHref || _.startsWith(resourcePath, `${noNSHref}/`);
return (
NavLink.isActive(props, resourcePath) ||
resourcePath === noNSHref ||
_.startsWith(resourcePath, `${noNSHref}/`)
);
}

get to() {
Expand Down
1 change: 1 addition & 0 deletions frontend/public/components/nav/NavLinkResourceCluster.tsx
Expand Up @@ -13,6 +13,7 @@ export class NavLinkResourceCluster extends NavLink<NavLinkResourceClusterProps>
);
}
return (
NavLink.isActive(props, resourcePath) ||
resourcePath === props.resource ||
_.startsWith(resourcePath, `${props.resource}/`) ||
matchesModel(resourcePath, props.model)
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/components/nav/NavLinkResourceNS.tsx
Expand Up @@ -14,7 +14,7 @@ export class NavLinkResourceNS extends NavLink<NavLinkResourceNSProps> {
return matchesExtensionModel(resourcePath, props.model);
}
const href = stripNS(formatNamespacedRouteForResource(props.resource, activeNamespace));
return matchesPath(resourcePath, href);
return NavLink.isActive(props, resourcePath) || matchesPath(resourcePath, href);
}

get to() {
Expand Down
10 changes: 4 additions & 6 deletions frontend/public/components/nav/NavLinkRoot.tsx
Expand Up @@ -26,13 +26,11 @@ const navLinkRootMapStateToProps = (
state: RootState,
{ component: Component, ...props }: NavLinkRootProps,
): NavLinkRootStateProps => {
const activeNamespace = getActiveNamespace(state);
const location = stripNS(state.UI.get('location'));
return {
activeNamespace: getActiveNamespace(state),
isActive: Component.isActive(
props,
stripNS(state.UI.get('location')),
getActiveNamespace(state),
),
activeNamespace,
isActive: Component.isActive(props, location, activeNamespace),
};
};

Expand Down

0 comments on commit 855b4e3

Please sign in to comment.