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.

MonorepoConnectionSelector.tsx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 { Title } from 'design-system/lib';
  21. import React from 'react';
  22. import { FormattedMessage } from 'react-intl';
  23. import { GroupBase } from 'react-select';
  24. import { LabelValueSelectOption } from '../../../../helpers/search';
  25. import { AlmKeys } from '../../../../types/alm-settings';
  26. import { DopSetting } from '../../../../types/dop-translation';
  27. import DopSettingDropdown from '../components/DopSettingDropdown';
  28. import MonorepoNoOrganisations from './MonorepoNoOrganisations';
  29. import { MonorepoOrganisationSelector } from './MonorepoOrganisationSelector';
  30. import { MonorepoRepositorySelector } from './MonorepoRepositorySelector';
  31. interface Props {
  32. almKey: AlmKeys;
  33. alreadyBoundProjects: {
  34. projectId: string;
  35. projectName: string;
  36. }[];
  37. dopSettings: DopSetting[];
  38. error: boolean;
  39. isFetchingAlreadyBoundProjects: boolean;
  40. isLoadingAlreadyBoundProjects: boolean;
  41. loadingBindings: boolean;
  42. loadingOrganizations?: boolean;
  43. loadingRepositories: boolean;
  44. onSearchRepositories: (query: string) => void;
  45. onSelectDopSetting: (instance: DopSetting) => void;
  46. onSelectOrganization?: (organizationKey: string) => void;
  47. onSelectRepository: (repositoryKey: string) => void;
  48. organizationOptions?: LabelValueSelectOption[];
  49. personalAccessTokenComponent?: React.ReactNode;
  50. repositoryOptions?: LabelValueSelectOption[] | GroupBase<LabelValueSelectOption>[];
  51. repositorySearchQuery: string;
  52. selectedDopSetting?: DopSetting;
  53. selectedOrganization?: LabelValueSelectOption;
  54. selectedRepository?: LabelValueSelectOption;
  55. showPersonalAccessToken?: boolean;
  56. showOrganizations?: boolean;
  57. }
  58. export function MonorepoConnectionSelector({
  59. almKey,
  60. alreadyBoundProjects,
  61. dopSettings,
  62. error,
  63. isFetchingAlreadyBoundProjects,
  64. isLoadingAlreadyBoundProjects,
  65. loadingOrganizations,
  66. loadingRepositories,
  67. onSearchRepositories,
  68. onSelectDopSetting,
  69. onSelectOrganization,
  70. onSelectRepository,
  71. organizationOptions,
  72. personalAccessTokenComponent,
  73. repositoryOptions,
  74. repositorySearchQuery,
  75. selectedDopSetting,
  76. selectedOrganization,
  77. selectedRepository,
  78. showPersonalAccessToken,
  79. showOrganizations,
  80. }: Readonly<Props>) {
  81. return (
  82. <div className="sw-flex sw-flex-col sw-gap-6">
  83. <Title>
  84. <FormattedMessage
  85. id={
  86. showOrganizations
  87. ? 'onboarding.create_project.monorepo.choose_organization_and_repository'
  88. : 'onboarding.create_project.monorepo.choose_repository'
  89. }
  90. />
  91. </Title>
  92. <DopSettingDropdown
  93. almKey={almKey}
  94. dopSettings={dopSettings}
  95. selectedDopSetting={selectedDopSetting}
  96. onChangeSetting={onSelectDopSetting}
  97. />
  98. {showPersonalAccessToken ? (
  99. personalAccessTokenComponent
  100. ) : (
  101. <>
  102. {showOrganizations && error && selectedDopSetting && !loadingOrganizations && (
  103. <MonorepoNoOrganisations almKey={almKey} />
  104. )}
  105. {showOrganizations && organizationOptions && (
  106. <div className="sw-flex sw-flex-col">
  107. <MonorepoOrganisationSelector
  108. almKey={almKey}
  109. error={error}
  110. organizationOptions={organizationOptions}
  111. loadingOrganizations={loadingOrganizations}
  112. onSelectOrganization={onSelectOrganization}
  113. selectedOrganization={selectedOrganization}
  114. />
  115. </div>
  116. )}
  117. <div className="sw-flex sw-flex-col">
  118. <MonorepoRepositorySelector
  119. almKey={almKey}
  120. alreadyBoundProjects={alreadyBoundProjects}
  121. error={error}
  122. isFetchingAlreadyBoundProjects={isFetchingAlreadyBoundProjects}
  123. isLoadingAlreadyBoundProjects={isLoadingAlreadyBoundProjects}
  124. loadingRepositories={loadingRepositories}
  125. onSelectRepository={onSelectRepository}
  126. onSearchRepositories={onSearchRepositories}
  127. repositoryOptions={repositoryOptions}
  128. repositorySearchQuery={repositorySearchQuery}
  129. selectedOrganization={selectedOrganization}
  130. selectedRepository={selectedRepository}
  131. showOrganizations={showOrganizations}
  132. />
  133. </div>
  134. </>
  135. )}
  136. </div>
  137. );
  138. }