Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 2090895: Support startsWith Nav Extension property #11660

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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