You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThresholdInput.tsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import Select from 'sonar-ui-common/components/controls/Select';
  22. interface Props {
  23. name: string;
  24. value: string;
  25. metric: T.Metric;
  26. onChange: (value: string) => void;
  27. }
  28. export default class ThresholdInput extends React.PureComponent<Props> {
  29. handleChange = (e: React.SyntheticEvent<HTMLInputElement>) => {
  30. this.props.onChange(e.currentTarget.value);
  31. };
  32. handleSelectChange = (option: { value: string } | null) => {
  33. if (option) {
  34. this.props.onChange(option.value);
  35. } else {
  36. this.props.onChange('');
  37. }
  38. };
  39. renderRatingInput() {
  40. const { name, value } = this.props;
  41. const options = [
  42. { label: 'A', value: '1' },
  43. { label: 'B', value: '2' },
  44. { label: 'C', value: '3' },
  45. { label: 'D', value: '4' }
  46. ];
  47. return (
  48. <Select
  49. className="input-tiny text-middle"
  50. clearable={true}
  51. id="condition-threshold"
  52. name={name}
  53. onChange={this.handleSelectChange}
  54. options={options}
  55. placeholder=""
  56. searchable={false}
  57. value={value}
  58. />
  59. );
  60. }
  61. render() {
  62. const { name, value, metric } = this.props;
  63. if (metric.type === 'RATING') {
  64. return this.renderRatingInput();
  65. }
  66. return (
  67. <input
  68. className="input-tiny text-middle"
  69. data-type={metric.type}
  70. id="condition-threshold"
  71. name={name}
  72. onChange={this.handleChange}
  73. type="text"
  74. value={value}
  75. />
  76. );
  77. }
  78. }