選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BitbucketCloudProjectCreateRender.tsx 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, Spinner } from '@sonarsource/echoes-react';
  21. import { LightPrimary, Title } from 'design-system';
  22. import React, { useContext } from 'react';
  23. import { FormattedMessage } from 'react-intl';
  24. import { queryToSearchString } from '~sonar-aligned/helpers/urls';
  25. import { AvailableFeaturesContext } from '../../../../app/components/available-features/AvailableFeaturesContext';
  26. import { translate } from '../../../../helpers/l10n';
  27. import { BitbucketCloudRepository } from '../../../../types/alm-integration';
  28. import { AlmKeys, AlmSettingsInstance } from '../../../../types/alm-settings';
  29. import { Feature } from '../../../../types/features';
  30. import AlmSettingsInstanceDropdown from '../components/AlmSettingsInstanceDropdown';
  31. import WrongBindingCountAlert from '../components/WrongBindingCountAlert';
  32. import { CreateProjectModes } from '../types';
  33. import BitbucketCloudPersonalAccessTokenForm from './BitbucketCloudPersonalAccessTokenForm';
  34. import BitbucketCloudSearchForm from './BitbucketCloudSearchForm';
  35. export interface BitbucketCloudProjectCreateRendererProps {
  36. almInstances: AlmSettingsInstance[];
  37. isLastPage: boolean;
  38. loading: boolean;
  39. loadingMore: boolean;
  40. onImport: (repositorySlug: string) => void;
  41. onLoadMore: () => void;
  42. onPersonalAccessTokenCreated: () => void;
  43. onSearch: (searchQuery: string) => void;
  44. onSelectedAlmInstanceChange: (instance: AlmSettingsInstance) => void;
  45. repositories?: BitbucketCloudRepository[];
  46. resetPat: boolean;
  47. searching: boolean;
  48. searchQuery: string;
  49. selectedAlmInstance?: AlmSettingsInstance;
  50. showPersonalAccessTokenForm: boolean;
  51. }
  52. export default function BitbucketCloudProjectCreateRenderer(
  53. props: Readonly<BitbucketCloudProjectCreateRendererProps>,
  54. ) {
  55. const isMonorepoSupported = useContext(AvailableFeaturesContext).includes(
  56. Feature.MonoRepositoryPullRequestDecoration,
  57. );
  58. const {
  59. almInstances,
  60. isLastPage,
  61. selectedAlmInstance,
  62. loading,
  63. loadingMore,
  64. repositories,
  65. resetPat,
  66. searching,
  67. searchQuery,
  68. showPersonalAccessTokenForm,
  69. } = props;
  70. return (
  71. <>
  72. <header className="sw-mb-10">
  73. <Title className="sw-mb-4">
  74. {translate('onboarding.create_project.bitbucketcloud.title')}
  75. </Title>
  76. <LightPrimary className="sw-body-sm">
  77. {isMonorepoSupported ? (
  78. <FormattedMessage
  79. id="onboarding.create_project.bitbucketcloud.subtitle.with_monorepo"
  80. values={{
  81. monorepoSetupLink: (
  82. <Link
  83. to={{
  84. pathname: '/projects/create',
  85. search: queryToSearchString({
  86. mode: CreateProjectModes.BitbucketCloud,
  87. mono: true,
  88. }),
  89. }}
  90. >
  91. <FormattedMessage id="onboarding.create_project.subtitle_monorepo_setup_link" />
  92. </Link>
  93. ),
  94. }}
  95. />
  96. ) : (
  97. <FormattedMessage id="onboarding.create_project.bitbucketcloud.subtitle" />
  98. )}
  99. </LightPrimary>
  100. </header>
  101. <AlmSettingsInstanceDropdown
  102. almKey={AlmKeys.BitbucketCloud}
  103. almInstances={almInstances}
  104. selectedAlmInstance={selectedAlmInstance}
  105. onChangeConfig={props.onSelectedAlmInstanceChange}
  106. />
  107. <Spinner isLoading={loading} />
  108. {!loading && almInstances && almInstances.length === 0 && !selectedAlmInstance && (
  109. <WrongBindingCountAlert alm={AlmKeys.BitbucketCloud} />
  110. )}
  111. {!loading &&
  112. selectedAlmInstance &&
  113. (showPersonalAccessTokenForm ? (
  114. <BitbucketCloudPersonalAccessTokenForm
  115. almSetting={selectedAlmInstance}
  116. resetPat={resetPat}
  117. onPersonalAccessTokenCreated={props.onPersonalAccessTokenCreated}
  118. />
  119. ) : (
  120. <BitbucketCloudSearchForm
  121. isLastPage={isLastPage}
  122. loadingMore={loadingMore}
  123. searchQuery={searchQuery}
  124. searching={searching}
  125. onImport={props.onImport}
  126. onSearch={props.onSearch}
  127. onLoadMore={props.onLoadMore}
  128. repositories={repositories}
  129. />
  130. ))}
  131. </>
  132. );
  133. }