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.

PRDecorationTabs.tsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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 BoxedTabs from 'sonar-ui-common/components/controls/BoxedTabs';
  22. import { translate } from 'sonar-ui-common/helpers/l10n';
  23. import { getBaseUrl } from 'sonar-ui-common/helpers/urls';
  24. import { withAppState } from '../../../../components/hoc/withAppState';
  25. import { AlmSettingsBindingDefinitions, ALM_KEYS } from '../../../../types/alm-settings';
  26. import AzureTab from './AzureTab';
  27. import BitbucketTab from './BitbucketTab';
  28. import DeleteModal from './DeleteModal';
  29. import GithubTab from './GithubTab';
  30. import GitlabTab from './GitlabTab';
  31. export interface PRDecorationTabsProps {
  32. appState: Pick<T.AppState, 'multipleAlmEnabled'>;
  33. currentAlm: ALM_KEYS;
  34. definitionKeyForDeletion?: string;
  35. definitions: AlmSettingsBindingDefinitions;
  36. loading: boolean;
  37. onCancel: () => void;
  38. onConfirmDelete: (definitionKey: string) => void;
  39. onDelete: (definitionKey: string) => void;
  40. onSelectAlm: (alm: ALM_KEYS) => void;
  41. onUpdateDefinitions: () => void;
  42. projectCount?: number;
  43. }
  44. export const almName = {
  45. [ALM_KEYS.AZURE]: 'Azure DevOps Server',
  46. [ALM_KEYS.BITBUCKET]: 'Bitbucket Server',
  47. [ALM_KEYS.GITHUB]: 'GitHub',
  48. [ALM_KEYS.GITLAB]: 'GitLab'
  49. };
  50. export function PRDecorationTabs(props: PRDecorationTabsProps) {
  51. const {
  52. appState: { multipleAlmEnabled },
  53. definitionKeyForDeletion,
  54. definitions,
  55. currentAlm,
  56. loading,
  57. projectCount
  58. } = props;
  59. return (
  60. <>
  61. <header className="page-header">
  62. <h1 className="page-title">{translate('settings.pr_decoration.title')}</h1>
  63. </header>
  64. <div className="markdown small spacer-top big-spacer-bottom">
  65. {translate('settings.pr_decoration.description')}
  66. </div>
  67. <BoxedTabs
  68. onSelect={props.onSelectAlm}
  69. selected={currentAlm}
  70. tabs={[
  71. {
  72. key: ALM_KEYS.GITHUB,
  73. label: (
  74. <>
  75. <img
  76. alt="github"
  77. className="spacer-right"
  78. height={16}
  79. src={`${getBaseUrl()}/images/alm/github.svg`}
  80. />
  81. {almName[ALM_KEYS.GITHUB]}
  82. </>
  83. )
  84. },
  85. {
  86. key: ALM_KEYS.BITBUCKET,
  87. label: (
  88. <>
  89. <img
  90. alt="bitbucket"
  91. className="spacer-right"
  92. height={16}
  93. src={`${getBaseUrl()}/images/alm/bitbucket.svg`}
  94. />
  95. {almName[ALM_KEYS.BITBUCKET]}
  96. </>
  97. )
  98. },
  99. {
  100. key: ALM_KEYS.AZURE,
  101. label: (
  102. <>
  103. <img
  104. alt="azure"
  105. className="spacer-right"
  106. height={16}
  107. src={`${getBaseUrl()}/images/alm/azure.svg`}
  108. />
  109. {almName[ALM_KEYS.AZURE]}
  110. </>
  111. )
  112. },
  113. {
  114. key: ALM_KEYS.GITLAB,
  115. label: (
  116. <>
  117. <img
  118. alt="gitlab"
  119. className="spacer-right"
  120. height={16}
  121. src={`${getBaseUrl()}/images/alm/gitlab.svg`}
  122. />
  123. {almName[ALM_KEYS.GITLAB]}
  124. </>
  125. )
  126. }
  127. ]}
  128. />
  129. <div className="boxed-group boxed-group-inner">
  130. {currentAlm === ALM_KEYS.AZURE && (
  131. <AzureTab
  132. definitions={definitions.azure}
  133. loading={loading}
  134. multipleAlmEnabled={Boolean(multipleAlmEnabled)}
  135. onDelete={props.onDelete}
  136. onUpdateDefinitions={props.onUpdateDefinitions}
  137. />
  138. )}
  139. {currentAlm === ALM_KEYS.BITBUCKET && (
  140. <BitbucketTab
  141. definitions={definitions.bitbucket}
  142. loading={loading}
  143. multipleAlmEnabled={Boolean(multipleAlmEnabled)}
  144. onDelete={props.onDelete}
  145. onUpdateDefinitions={props.onUpdateDefinitions}
  146. />
  147. )}
  148. {currentAlm === ALM_KEYS.GITHUB && (
  149. <GithubTab
  150. definitions={definitions.github}
  151. loading={loading}
  152. multipleAlmEnabled={Boolean(multipleAlmEnabled)}
  153. onDelete={props.onDelete}
  154. onUpdateDefinitions={props.onUpdateDefinitions}
  155. />
  156. )}
  157. {currentAlm === ALM_KEYS.GITLAB && (
  158. <GitlabTab
  159. definitions={definitions.gitlab}
  160. loading={loading}
  161. multipleAlmEnabled={Boolean(multipleAlmEnabled)}
  162. onDelete={props.onDelete}
  163. onUpdateDefinitions={props.onUpdateDefinitions}
  164. />
  165. )}
  166. </div>
  167. {definitionKeyForDeletion && (
  168. <DeleteModal
  169. id={definitionKeyForDeletion}
  170. onCancel={props.onCancel}
  171. onDelete={props.onConfirmDelete}
  172. projectCount={projectCount}
  173. />
  174. )}
  175. </>
  176. );
  177. }
  178. export default withAppState(PRDecorationTabs);