/* * SonarQube * Copyright (C) 2009-2019 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as classNames from 'classnames'; import * as React from 'react'; import { Link } from 'react-router'; import LinkIcon from 'sonar-ui-common/components/icons/LinkIcon'; import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; import { getActionKey, serializeQuery } from '../utils'; import ActionChangelog from './ActionChangelog'; import DeprecatedBadge from './DeprecatedBadge'; import InternalBadge from './InternalBadge'; import Params from './Params'; import ResponseExample from './ResponseExample'; interface Props { action: T.WebApi.Action; domain: T.WebApi.Domain; showDeprecated: boolean; showInternal: boolean; } interface State { showChangelog: boolean; showParams: boolean; showResponse: boolean; } export default class Action extends React.PureComponent { state: State = { showChangelog: false, showParams: false, showResponse: false }; handleShowParamsClick = (e: React.SyntheticEvent) => { e.preventDefault(); this.setState(state => ({ showChangelog: false, showResponse: false, showParams: !state.showParams })); }; handleShowResponseClick = (e: React.SyntheticEvent) => { e.preventDefault(); this.setState(state => ({ showChangelog: false, showParams: false, showResponse: !state.showResponse })); }; handleChangelogClick = (e: React.SyntheticEvent) => { e.preventDefault(); this.setState(state => ({ showChangelog: !state.showChangelog, showParams: false, showResponse: false })); }; renderTabs() { const { action } = this.props; const { showChangelog, showParams, showResponse } = this.state; if (action.params || action.hasResponseExample || action.changelog.length > 0) { return ( ); } return null; } render() { const { action, domain } = this.props; const { showChangelog, showParams, showResponse } = this.state; const verb = action.post ? 'POST' : 'GET'; const actionKey = getActionKey(domain.path, action.key); return (

{verb}   {actionKey}

{action.internal && ( )} {action.since && ( {translateWithParameters('since_x', action.since)} )} {action.deprecatedSince && ( )}
{this.renderTabs()} {showParams && action.params && ( )} {showResponse && action.hasResponseExample && ( )} {showChangelog && }
); } }