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.

MonorepoOrganisationSelector.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 { DarkLabel, FlagMessage, InputSelect } from 'design-system';
  22. import React from 'react';
  23. import { FormattedMessage, useIntl } from 'react-intl';
  24. import { useAppState } from '../../../../app/components/app-state/withAppStateContext';
  25. import { LabelValueSelectOption } from '../../../../helpers/search';
  26. import { AlmKeys } from '../../../../types/alm-settings';
  27. interface Props {
  28. almKey: AlmKeys;
  29. error: boolean;
  30. loadingOrganizations?: boolean;
  31. onSelectOrganization?: (organizationKey: string) => void;
  32. organizationOptions: LabelValueSelectOption[];
  33. selectedOrganization?: LabelValueSelectOption;
  34. }
  35. export function MonorepoOrganisationSelector({
  36. almKey,
  37. error,
  38. loadingOrganizations,
  39. onSelectOrganization,
  40. organizationOptions,
  41. selectedOrganization,
  42. }: Readonly<Props>) {
  43. const { formatMessage } = useIntl();
  44. const { canAdmin } = useAppState();
  45. return (
  46. !error && (
  47. <>
  48. <DarkLabel htmlFor={`${almKey}-monorepo-choose-organization`} className="sw-mb-2">
  49. <FormattedMessage id="onboarding.create_project.monorepo.choose_organization" />
  50. </DarkLabel>
  51. <Spinner isLoading={loadingOrganizations && !error}>
  52. {organizationOptions.length > 0 ? (
  53. <InputSelect
  54. size="full"
  55. isSearchable
  56. inputId={`${almKey}-monorepo-choose-organization`}
  57. options={organizationOptions}
  58. onChange={({ value }: LabelValueSelectOption) => {
  59. if (onSelectOrganization) {
  60. onSelectOrganization(value);
  61. }
  62. }}
  63. placeholder={formatMessage({
  64. id: 'onboarding.create_project.monorepo.choose_organization.placeholder',
  65. })}
  66. value={selectedOrganization}
  67. />
  68. ) : (
  69. !loadingOrganizations && (
  70. <FlagMessage variant="error" className="sw-mb-2">
  71. <span>
  72. {canAdmin ? (
  73. <FormattedMessage
  74. id="onboarding.create_project.monorepo.no_orgs_admin"
  75. defaultMessage={formatMessage({
  76. id: 'onboarding.create_project.monorepo.no_orgs_admin',
  77. })}
  78. values={{
  79. almKey,
  80. link: (
  81. <Link to="/admin/settings?category=almintegration">
  82. <FormattedMessage id="onboarding.create_project.monorepo.warning.message_admin.link" />
  83. </Link>
  84. ),
  85. }}
  86. />
  87. ) : (
  88. <FormattedMessage id="onboarding.create_project.monorepo.no_orgs" />
  89. )}
  90. </span>
  91. </FlagMessage>
  92. )
  93. )}
  94. </Spinner>
  95. </>
  96. )
  97. );
  98. }