import React from 'react';
import { Link } from 'react-router';
import classNames from 'classnames';
-
import InternalBadge from './InternalBadge';
import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin';
-import { getActionKey } from '../utils';
+import { getActionKey, isDomainPathActive } from '../utils';
export default function Menu ({ domains, showInternal, showOnlyDeprecated, searchQuery, splat }) {
const filteredDomains = (domains || [])
{filteredDomains.map(domain => (
<Link
key={domain.path}
- className={classNames('list-group-item', { 'active': splat.indexOf(domain.path) === 0 })}
+ className={classNames('list-group-item', { 'active': isDomainPathActive(domain.path, splat) })}
to={domain.path}>
<h3 className="list-group-item-heading">
{domain.path}
import Search from './Search';
import Domain from './Domain';
import { getActionKey } from '../utils';
+import { isDomainPathActive } from '../utils';
export default class WebApiApp extends React.Component {
state = {
const { splat } = this.props.params;
const { router } = this.context;
const { domains } = this.state;
- const domain = domains.find(domain => splat.indexOf(domain.path) === 0);
+ const domain = domains.find(domain => isDomainPathActive(domain.path, splat));
const showInternal = !this.state.showInternal;
if (domain && domain.internal && !showInternal) {
const { splat } = this.props.params;
const { domains, showInternal, showOnlyDeprecated, searchQuery } = this.state;
- const domain = domains.find(domain => splat.indexOf(domain.path) === 0);
+ const domain = domains.find(domain => isDomainPathActive(domain.path, splat));
return (
<div className="search-navigator sticky">
export function getActionKey (domain, action) {
return domain + '/' + action;
}
+
+export const isDomainPathActive = (path, splat) => {
+ const pathTokens = path.split('/');
+ const splatTokens = splat.split('/');
+
+ if (pathTokens.length > splatTokens.length) {
+ return false;
+ }
+
+ for (let i = 0; i < pathTokens.length; i++) {
+ if (pathTokens[i] !== splatTokens[i]) {
+ return false;
+ }
+ }
+
+ return true;
+};