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.

PerspectiveSelect.tsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 { translate } from 'sonar-ui-common/helpers/l10n';
  22. import Select from 'sonar-ui-common/components/controls/Select';
  23. import PerspectiveSelectOption, { Option } from './PerspectiveSelectOption';
  24. import { VIEWS, VISUALIZATIONS } from '../utils';
  25. interface Props {
  26. className?: string;
  27. onChange: (x: { view: string; visualization?: string }) => void;
  28. view: string;
  29. visualization?: string;
  30. }
  31. export default class PerspectiveSelect extends React.PureComponent<Props> {
  32. handleChange = (option: Option) => {
  33. if (option.type === 'view') {
  34. this.props.onChange({ view: option.value });
  35. } else if (option.type === 'visualization') {
  36. this.props.onChange({ view: 'visualizations', visualization: option.value });
  37. }
  38. };
  39. render() {
  40. const { view, visualization } = this.props;
  41. const perspective = view === 'visualizations' ? visualization : view;
  42. const options = [
  43. ...VIEWS.map(opt => ({
  44. type: 'view',
  45. value: opt.value,
  46. label: translate('projects.view', opt.label)
  47. })),
  48. ...VISUALIZATIONS.map(opt => ({
  49. type: 'visualization',
  50. value: opt,
  51. label: translate('projects.visualization', opt)
  52. }))
  53. ];
  54. return (
  55. <div className={this.props.className}>
  56. <label>{translate('projects.perspective')}:</label>
  57. <Select
  58. className="little-spacer-left input-medium"
  59. clearable={false}
  60. onChange={this.handleChange}
  61. optionComponent={PerspectiveSelectOption}
  62. options={options}
  63. searchable={false}
  64. value={perspective}
  65. />
  66. </div>
  67. );
  68. }
  69. }