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.

MeasureViewSelect.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { InputSelect } from 'design-system';
  21. import * as React from 'react';
  22. import { translate } from '../../../helpers/l10n';
  23. import { MeasurePageView } from '../../../types/measures';
  24. import { Metric } from '../../../types/types';
  25. import { hasList, hasTree, hasTreemap } from '../utils';
  26. export interface MeasureViewSelectProps {
  27. className?: string;
  28. metric: Metric;
  29. handleViewChange: (view: MeasurePageView) => void;
  30. view: MeasurePageView;
  31. }
  32. interface ViewOption {
  33. label: string;
  34. value: MeasurePageView;
  35. }
  36. export default function MeasureViewSelect(props: MeasureViewSelectProps) {
  37. const { metric, view, className } = props;
  38. const options = [];
  39. if (hasTree(metric.key)) {
  40. options.push({
  41. label: translate('component_measures.tab.tree'),
  42. value: MeasurePageView.tree,
  43. });
  44. }
  45. if (hasList(metric.key)) {
  46. options.push({
  47. label: translate('component_measures.tab.list'),
  48. value: MeasurePageView.list,
  49. });
  50. }
  51. if (hasTreemap(metric.key, metric.type)) {
  52. options.push({
  53. label: translate('component_measures.tab.treemap'),
  54. value: MeasurePageView.treemap,
  55. });
  56. }
  57. const handleChange = (option: ViewOption) => {
  58. return props.handleViewChange(option.value);
  59. };
  60. return (
  61. <InputSelect
  62. size="small"
  63. aria-labelledby="measures-view-selection-label"
  64. blurInputOnSelect
  65. className={className}
  66. onChange={handleChange}
  67. options={options}
  68. isSearchable={false}
  69. value={options.find((o) => o.value === view)}
  70. />
  71. );
  72. }