diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps/web-api/components/Menu.js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/web-api/components/Menu.js | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/server/sonar-web/src/main/js/apps/web-api/components/Menu.js b/server/sonar-web/src/main/js/apps/web-api/components/Menu.js index 260587ce4ee..b2bea00727f 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/Menu.js +++ b/server/sonar-web/src/main/js/apps/web-api/components/Menu.js @@ -17,53 +17,63 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +// @flow import React from 'react'; import { Link } from 'react-router'; import classNames from 'classnames'; +import DeprecatedBadge from './DeprecatedBadge'; import InternalBadge from './InternalBadge'; import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; import { getActionKey, isDomainPathActive } from '../utils'; +import type { Domain as DomainType } from '../../../api/web-api'; -export default function Menu ({ domains, showInternal, showOnlyDeprecated, searchQuery, splat }) { - const filteredDomains = (domains || []) +type Props = { + domains: Array<DomainType>, + showDeprecated: boolean, + showInternal: boolean, + searchQuery: string, + splat: string +}; + +export default class Menu extends React.PureComponent { + props: Props; + + render () { + const { domains, showInternal, showDeprecated, searchQuery, splat } = this.props; + const filteredDomains = (domains || []) .map(domain => { const filteredActions = domain.actions - .filter(action => { - return showInternal || !action.internal; - }) - .filter(action => { - return !showOnlyDeprecated || (showOnlyDeprecated && action.deprecatedSince); - }) - .filter(action => { - const actionKey = getActionKey(domain.path, action.key); - return actionKey.indexOf(searchQuery) !== -1; - }); + .filter(action => showInternal || !action.internal) + .filter(action => showDeprecated || !action.deprecatedSince) + .filter(action => getActionKey(domain.path, action.key).indexOf(searchQuery) !== -1); return { ...domain, filteredActions }; }) .filter(domain => domain.filteredActions.length); - return ( + return ( <div className="api-documentation-results panel"> <TooltipsContainer> <div className="list-group"> {filteredDomains.map(domain => ( - <Link - key={domain.path} - className={classNames('list-group-item', { 'active': isDomainPathActive(domain.path, splat) })} - to={'/web_api/' + domain.path}> - <h3 className="list-group-item-heading"> - {domain.path} - {domain.internal && ( - <InternalBadge/> - )} - </h3> - <p className="list-group-item-text"> - {domain.description} - </p> - </Link> + <Link + key={domain.path} + className={classNames('list-group-item', { + active: isDomainPathActive(domain.path, splat) + })} + to={'/web_api/' + domain.path}> + <h3 className="list-group-item-heading"> + {domain.path} + {domain.deprecated && <DeprecatedBadge/>} + {domain.internal && <InternalBadge/>} + </h3> + <p className="list-group-item-text"> + {domain.description} + </p> + </Link> ))} </div> </TooltipsContainer> </div> - ); + ); + } } |