]> source.dussan.org Git - sonarqube.git/commitdiff
fix conflicts between domain on web api page
authorStas Vilchik <vilchiks@gmail.com>
Fri, 9 Sep 2016 15:38:06 +0000 (17:38 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 9 Sep 2016 15:38:14 +0000 (17:38 +0200)
server/sonar-web/src/main/js/apps/web-api/components/Menu.js
server/sonar-web/src/main/js/apps/web-api/components/WebApiApp.js
server/sonar-web/src/main/js/apps/web-api/utils.js

index ba2938ca171b68572d00cd9a0e7e0932ea3ea5f4..af81e50fb456959d748861b110a6ceb65fee3f85 100644 (file)
 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 || [])
@@ -50,7 +49,7 @@ export default function Menu ({ domains, showInternal, showOnlyDeprecated, searc
             {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}
index 332d18f1399e5d16c7a9e7dbe6bbcb4c1ea4f32f..3ca3b93312b268c25600a340f517a71b67f58f63 100644 (file)
@@ -25,6 +25,7 @@ import Menu from './Menu';
 import Search from './Search';
 import Domain from './Domain';
 import { getActionKey } from '../utils';
+import { isDomainPathActive } from '../utils';
 
 export default class WebApiApp extends React.Component {
   state = {
@@ -104,7 +105,7 @@ export default class WebApiApp extends React.Component {
     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) {
@@ -122,7 +123,7 @@ export default class WebApiApp extends React.Component {
     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">
index 6e6de08af2db0d882994f90a21970a0af7bee692..4dd0d06d14af8b65748d9efde6f906fa96b49728 100644 (file)
 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;
+};