Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AlmIntegrationRenderer.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 { Link } from '@sonarsource/echoes-react';
  21. import { FlagMessage, SubTitle, ToggleButton } from 'design-system';
  22. import * as React from 'react';
  23. import { FormattedMessage } from 'react-intl';
  24. import { Image } from '../../../../components/common/Image';
  25. import { translate } from '../../../../helpers/l10n';
  26. import { isDefined } from '../../../../helpers/types';
  27. import { useGetValuesQuery } from '../../../../queries/settings';
  28. import {
  29. AlmKeys,
  30. AlmSettingsBindingDefinitions,
  31. AlmSettingsBindingStatus,
  32. } from '../../../../types/alm-settings';
  33. import { SettingsKey } from '../../../../types/settings';
  34. import { Dict } from '../../../../types/types';
  35. import { AlmTabs } from './AlmIntegration';
  36. import AlmTab from './AlmTab';
  37. import DeleteModal from './DeleteModal';
  38. export interface AlmIntegrationRendererProps {
  39. branchesEnabled: boolean;
  40. currentAlmTab: AlmTabs;
  41. definitionKeyForDeletion?: string;
  42. definitions: AlmSettingsBindingDefinitions;
  43. definitionStatus: Dict<AlmSettingsBindingStatus>;
  44. loadingAlmDefinitions: boolean;
  45. loadingProjectCount: boolean;
  46. multipleAlmEnabled: boolean;
  47. onCancelDelete: () => void;
  48. onCheckConfiguration: (definitionKey: string) => void;
  49. onConfirmDelete: (definitionKey: string) => void;
  50. onDelete: (definitionKey: string) => void;
  51. onSelectAlmTab: (alm: AlmTabs) => void;
  52. onUpdateDefinitions: () => void;
  53. projectCount?: number;
  54. }
  55. const tabs = [
  56. {
  57. label: (
  58. <>
  59. <Image alt="github" className="sw-mr-2" height={16} src="/images/alm/github.svg" />
  60. {translate('settings.almintegration.tab.github')}
  61. </>
  62. ),
  63. value: AlmKeys.GitHub,
  64. },
  65. {
  66. label: (
  67. <>
  68. <Image alt="bitbucket" className="sw-mr-2" height={16} src="/images/alm/bitbucket.svg" />
  69. {translate('settings.almintegration.tab.bitbucket')}
  70. </>
  71. ),
  72. value: AlmKeys.BitbucketServer,
  73. },
  74. {
  75. label: (
  76. <>
  77. <Image alt="azure" className="sw-mr-2" height={16} src="/images/alm/azure.svg" />
  78. {translate('settings.almintegration.tab.azure')}
  79. </>
  80. ),
  81. value: AlmKeys.Azure,
  82. },
  83. {
  84. label: (
  85. <>
  86. <Image alt="gitlab" className="sw-mr-2" height={16} src="/images/alm/gitlab.svg" />
  87. {translate('settings.almintegration.tab.gitlab')}
  88. </>
  89. ),
  90. value: AlmKeys.GitLab,
  91. },
  92. ];
  93. export default function AlmIntegrationRenderer(props: AlmIntegrationRendererProps) {
  94. const {
  95. definitionKeyForDeletion,
  96. definitions,
  97. definitionStatus,
  98. currentAlmTab,
  99. loadingAlmDefinitions,
  100. loadingProjectCount,
  101. branchesEnabled,
  102. multipleAlmEnabled,
  103. projectCount,
  104. } = props;
  105. const bindingDefinitions = {
  106. [AlmKeys.Azure]: definitions.azure,
  107. [AlmKeys.GitLab]: definitions.gitlab,
  108. [AlmKeys.GitHub]: definitions.github,
  109. [AlmKeys.BitbucketServer]: [...definitions.bitbucket, ...definitions.bitbucketcloud],
  110. };
  111. const { data, isLoading } = useGetValuesQuery([SettingsKey.ServerBaseUrl]);
  112. const hasServerBaseUrl = data?.length === 1 && data[0].value !== undefined;
  113. return (
  114. <>
  115. <header className="sw-mb-5">
  116. <SubTitle>{translate('settings.almintegration.title')}</SubTitle>
  117. </header>
  118. {!hasServerBaseUrl && !isLoading && branchesEnabled && (
  119. <FlagMessage variant="warning">
  120. <p>
  121. <FormattedMessage
  122. id="settings.almintegration.empty.server_base_url"
  123. defaultMessage={translate('settings.almintegration.empty.server_base_url')}
  124. values={{
  125. serverBaseUrl: (
  126. <Link to="/admin/settings?category=general#sonar.core.serverBaseURL">
  127. {translate('settings.almintegration.empty.server_base_url.setting_link')}
  128. </Link>
  129. ),
  130. }}
  131. />
  132. </p>
  133. </FlagMessage>
  134. )}
  135. <div className="sw-my-4">{translate('settings.almintegration.description')}</div>
  136. <div className="sw-mb-6">
  137. <ToggleButton
  138. onChange={props.onSelectAlmTab}
  139. options={tabs}
  140. role="tablist"
  141. value={currentAlmTab}
  142. />
  143. </div>
  144. <AlmTab
  145. almTab={currentAlmTab}
  146. branchesEnabled={branchesEnabled}
  147. definitions={bindingDefinitions[currentAlmTab]}
  148. definitionStatus={definitionStatus}
  149. loadingAlmDefinitions={loadingAlmDefinitions}
  150. loadingProjectCount={loadingProjectCount}
  151. multipleAlmEnabled={multipleAlmEnabled}
  152. onCheck={props.onCheckConfiguration}
  153. onDelete={props.onDelete}
  154. onUpdateDefinitions={props.onUpdateDefinitions}
  155. />
  156. {isDefined(definitionKeyForDeletion) && (
  157. <DeleteModal
  158. id={definitionKeyForDeletion}
  159. onCancel={props.onCancelDelete}
  160. onDelete={props.onConfirmDelete}
  161. projectCount={projectCount}
  162. />
  163. )}
  164. </>
  165. );
  166. }