/* * SonarQube * Copyright (C) 2009-2023 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 classNames from 'classnames'; import * as React from 'react'; import Link from '../../../components/common/Link'; import LinkIcon from '../../../components/icons/LinkIcon'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { queryToSearch } from '../../../helpers/urls'; import { WebApi } from '../../../types/types'; 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: WebApi.Action; domain: 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 && }
); } }