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.

AllCategoriesList.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 classNames from 'classnames';
  21. import { sortBy } from 'lodash';
  22. import * as React from 'react';
  23. import { IndexLink } from 'react-router';
  24. import withAppStateContext from '../../../app/components/app-state/withAppStateContext';
  25. import { getGlobalSettingsUrl, getProjectSettingsUrl } from '../../../helpers/urls';
  26. import { AppState } from '../../../types/appstate';
  27. import { Component } from '../../../types/types';
  28. import { getCategoryName } from '../utils';
  29. import { ADDITIONAL_CATEGORIES } from './AdditionalCategories';
  30. import CATEGORY_OVERRIDES from './CategoryOverrides';
  31. export interface CategoriesListProps {
  32. appState: AppState;
  33. categories: string[];
  34. component?: Component;
  35. defaultCategory: string;
  36. selectedCategory: string;
  37. }
  38. export function CategoriesList(props: CategoriesListProps) {
  39. const { appState, categories, component, defaultCategory, selectedCategory } = props;
  40. const categoriesWithName = categories
  41. .filter(key => !CATEGORY_OVERRIDES[key.toLowerCase()])
  42. .map(key => ({
  43. key,
  44. name: getCategoryName(key)
  45. }))
  46. .concat(
  47. ADDITIONAL_CATEGORIES.filter(c => c.displayTab)
  48. .filter(c =>
  49. component
  50. ? // Project settings
  51. c.availableForProject
  52. : // Global settings
  53. c.availableGlobally
  54. )
  55. .filter(c => appState.branchesEnabled || !c.requiresBranchesEnabled)
  56. );
  57. const sortedCategories = sortBy(categoriesWithName, category => category.name.toLowerCase());
  58. return (
  59. <ul className="side-tabs-menu">
  60. {sortedCategories.map(c => {
  61. const category = c.key !== defaultCategory ? c.key.toLowerCase() : undefined;
  62. return (
  63. <li key={c.key}>
  64. <IndexLink
  65. className={classNames({
  66. active: c.key.toLowerCase() === selectedCategory.toLowerCase()
  67. })}
  68. title={c.name}
  69. to={
  70. component
  71. ? getProjectSettingsUrl(component.key, category)
  72. : getGlobalSettingsUrl(category)
  73. }>
  74. {c.name}
  75. </IndexLink>
  76. </li>
  77. );
  78. })}
  79. </ul>
  80. );
  81. }
  82. export default withAppStateContext(CategoriesList);