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.

AdditionalCategories.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 * as React from 'react';
  21. import { translate } from '../../../helpers/l10n';
  22. import { ExtendedSettingDefinition } from '../../../types/settings';
  23. import { Component } from '../../../types/types';
  24. import {
  25. ALM_INTEGRATION_CATEGORY,
  26. ANALYSIS_SCOPE_CATEGORY,
  27. LANGUAGES_CATEGORY,
  28. NEW_CODE_PERIOD_CATEGORY,
  29. PULL_REQUEST_DECORATION_BINDING_CATEGORY
  30. } from '../constants';
  31. import AlmIntegration from './almIntegration/AlmIntegration';
  32. import { AnalysisScope } from './AnalysisScope';
  33. import Languages from './Languages';
  34. import NewCodePeriod from './NewCodePeriod';
  35. import PullRequestDecorationBinding from './pullRequestDecorationBinding/PRDecorationBinding';
  36. export interface AdditionalCategoryComponentProps {
  37. categories: string[];
  38. definitions: ExtendedSettingDefinition[];
  39. component: Component | undefined;
  40. selectedCategory: string;
  41. }
  42. export interface AdditionalCategory {
  43. availableGlobally: boolean;
  44. availableForProject: boolean;
  45. displayTab: boolean;
  46. key: string;
  47. name: string;
  48. renderComponent: (props: AdditionalCategoryComponentProps) => React.ReactNode;
  49. requiresBranchesEnabled?: boolean;
  50. }
  51. export const ADDITIONAL_CATEGORIES: AdditionalCategory[] = [
  52. {
  53. key: LANGUAGES_CATEGORY,
  54. name: translate('property.category.languages'),
  55. renderComponent: getLanguagesComponent,
  56. availableGlobally: true,
  57. availableForProject: true,
  58. displayTab: true
  59. },
  60. {
  61. key: NEW_CODE_PERIOD_CATEGORY,
  62. name: translate('settings.new_code_period.category'),
  63. renderComponent: getNewCodePeriodComponent,
  64. availableGlobally: true,
  65. availableForProject: false,
  66. displayTab: true
  67. },
  68. {
  69. key: ANALYSIS_SCOPE_CATEGORY,
  70. name: translate('property.category.exclusions'),
  71. renderComponent: getAnalysisScopeComponent,
  72. availableGlobally: true,
  73. availableForProject: true,
  74. displayTab: false
  75. },
  76. {
  77. key: ALM_INTEGRATION_CATEGORY,
  78. name: translate('property.category.almintegration'),
  79. renderComponent: getAlmIntegrationComponent,
  80. availableGlobally: true,
  81. availableForProject: false,
  82. displayTab: true
  83. },
  84. {
  85. key: PULL_REQUEST_DECORATION_BINDING_CATEGORY,
  86. name: translate('settings.pr_decoration.binding.category'),
  87. renderComponent: getPullRequestDecorationBindingComponent,
  88. availableGlobally: false,
  89. availableForProject: true,
  90. displayTab: true,
  91. requiresBranchesEnabled: true
  92. }
  93. ];
  94. function getLanguagesComponent(props: AdditionalCategoryComponentProps) {
  95. return <Languages {...props} />;
  96. }
  97. function getNewCodePeriodComponent() {
  98. return <NewCodePeriod />;
  99. }
  100. function getAnalysisScopeComponent(props: AdditionalCategoryComponentProps) {
  101. return <AnalysisScope {...props} />;
  102. }
  103. function getAlmIntegrationComponent(props: AdditionalCategoryComponentProps) {
  104. return <AlmIntegration {...props} />;
  105. }
  106. function getPullRequestDecorationBindingComponent(props: AdditionalCategoryComponentProps) {
  107. return props.component && <PullRequestDecorationBinding component={props.component} />;
  108. }