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.

BitbucketProjectAccordion.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 { Accordion, FlagMessage, Link } from 'design-system';
  21. import * as React from 'react';
  22. import { FormattedMessage } from 'react-intl';
  23. import { queryToSearchString } from '~sonar-aligned/helpers/urls';
  24. import { translate, translateWithParameters } from '../../../../helpers/l10n';
  25. import { getBaseUrl } from '../../../../helpers/system';
  26. import { BitbucketProject, BitbucketRepository } from '../../../../types/alm-integration';
  27. import AlmRepoItem from '../components/AlmRepoItem';
  28. import { CreateProjectModes } from '../types';
  29. export interface BitbucketProjectAccordionProps {
  30. onClick?: () => void;
  31. onImportRepository: (repository: BitbucketRepository) => void;
  32. open: boolean;
  33. project?: BitbucketProject;
  34. repositories: BitbucketRepository[];
  35. showingAllRepositories: boolean;
  36. }
  37. export default function BitbucketProjectAccordion(props: BitbucketProjectAccordionProps) {
  38. const { open, project, repositories, showingAllRepositories } = props;
  39. const repositoryCount = repositories.length;
  40. const title = project?.name ?? translate('search_results');
  41. return (
  42. <Accordion
  43. className="sw-mb-6"
  44. onClick={
  45. props.onClick
  46. ? props.onClick
  47. : () => {
  48. /* noop */
  49. }
  50. }
  51. open={open}
  52. header={title}
  53. >
  54. {open && (
  55. <>
  56. <div className="sw-mb-4">
  57. {repositoryCount === 0 && (
  58. <FlagMessage variant="warning">
  59. <span>
  60. <FormattedMessage
  61. defaultMessage={translate('onboarding.create_project.no_bbs_repos')}
  62. id="onboarding.create_project.no_bbs_repos"
  63. values={{
  64. link: (
  65. <Link
  66. to={{
  67. pathname: '/projects/create',
  68. search: queryToSearchString({
  69. mode: CreateProjectModes.BitbucketServer,
  70. resetPat: 1,
  71. }),
  72. }}
  73. >
  74. {translate('onboarding.create_project.update_your_token')}
  75. </Link>
  76. ),
  77. }}
  78. />
  79. </span>
  80. </FlagMessage>
  81. )}
  82. <ul className="sw-flex sw-flex-col sw-gap-3">
  83. {repositories.map((r) => (
  84. <AlmRepoItem
  85. key={r.name}
  86. almKey={r.name}
  87. almIconSrc={`${getBaseUrl()}/images/alm/bitbucket.svg`}
  88. sqProjectKey={r.sqProjectKey}
  89. onImport={() => props.onImportRepository(r)}
  90. primaryTextNode={<span>{r.name}</span>}
  91. />
  92. ))}
  93. </ul>
  94. </div>
  95. {!showingAllRepositories && repositoryCount > 0 && (
  96. <FlagMessage variant="warning">
  97. {translateWithParameters(
  98. 'onboarding.create_project.only_showing_X_first_repos',
  99. repositoryCount,
  100. )}
  101. </FlagMessage>
  102. )}
  103. </>
  104. )}
  105. </Accordion>
  106. );
  107. }