/* * 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 * as React from 'react'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { WebApi } from '../../../types/types'; import DeprecatedBadge from './DeprecatedBadge'; import InternalBadge from './InternalBadge'; interface Props { params: WebApi.Param[]; showDeprecated: boolean; showInternal: boolean; } export default class Params extends React.PureComponent { renderKey(param: WebApi.Param) { return ( {param.key} {param.internal && (
)} {param.deprecatedSince && (
)}
{param.required ? 'required' : 'optional'}
{param.since && (
{translateWithParameters('since_x', param.since)}
)} {this.props.showDeprecated && param.deprecatedKey && (
{translate('replaces')}:
{param.deprecatedKey} {param.deprecatedKeySince && (
)}
)} ); } renderConstraint(param: WebApi.Param, field: keyof WebApi.Param, label: string) { const value = param[field]; if (value !== undefined) { return (

{translate('api_documentation', label)}

{value}
); } else { return null; } } render() { const { params, showDeprecated, showInternal } = this.props; const displayedParameters = params .filter((p) => showDeprecated || !p.deprecatedSince) .filter((p) => showInternal || !p.internal); return (
{displayedParameters.map((param) => ( {this.renderKey(param)} ))}
{param.possibleValues && (

{translate('api_documentation.possible_values')}

    {param.possibleValues.map((value) => (
  • {value}
  • ))}
)} {this.renderConstraint(param, 'defaultValue', 'default_values')} {this.renderConstraint(param, 'exampleValue', 'example_values')} {this.renderConstraint(param, 'maxValuesAllowed', 'max_values')} {this.renderConstraint(param, 'minimumValue', 'min_value')} {this.renderConstraint(param, 'maximumValue', 'max_value')} {this.renderConstraint(param, 'minimumLength', 'min_length')} {this.renderConstraint(param, 'maximumLength', 'max_length')}
); } }