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.

ChangeDefaultVisibilityForm.tsx 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 { RadioButtonGroup } from '@sonarsource/echoes-react';
  21. import { ButtonPrimary, FlagMessage, Modal } from 'design-system';
  22. import React, { useState } from 'react';
  23. import { translate } from '../../helpers/l10n';
  24. import { useGithubProvisioningEnabledQuery } from '../../queries/identity-provider/github';
  25. import { Visibility } from '../../types/component';
  26. export interface Props {
  27. defaultVisibility: Visibility;
  28. onClose: () => void;
  29. onConfirm: (visiblity: Visibility) => void;
  30. }
  31. const FORM_ID = 'change-default-visibility-form';
  32. export default function ChangeDefaultVisibilityForm(props: Readonly<Props>) {
  33. const [visibility, setVisibility] = useState(props.defaultVisibility);
  34. const { data: githubProbivisioningEnabled } = useGithubProvisioningEnabledQuery();
  35. const handleConfirmClick = (event: React.FormEvent<HTMLFormElement>) => {
  36. event.preventDefault();
  37. props.onConfirm(visibility);
  38. props.onClose();
  39. };
  40. const handleVisibilityChange = (visibility: Visibility) => {
  41. setVisibility(visibility);
  42. };
  43. const header = translate('settings.projects.change_visibility_form.header');
  44. const body = (
  45. <form id={FORM_ID} onSubmit={handleConfirmClick}>
  46. <RadioButtonGroup
  47. id="settings-projects-visibility-radio"
  48. options={Object.values(Visibility).map((visibilityValue) => ({
  49. label: translate('visibility', visibilityValue),
  50. helpText: translate('visibility', visibilityValue, 'description.short'),
  51. value: visibilityValue,
  52. }))}
  53. value={visibility}
  54. onChange={handleVisibilityChange}
  55. />
  56. <FlagMessage variant="warning">
  57. {translate(
  58. `settings.projects.change_visibility_form.warning${
  59. githubProbivisioningEnabled ? '.github' : ''
  60. }`,
  61. )}
  62. </FlagMessage>
  63. </form>
  64. );
  65. return (
  66. <Modal
  67. isScrollable={false}
  68. isOverflowVisible
  69. headerTitle={header}
  70. onClose={props.onClose}
  71. body={body}
  72. primaryButton={
  73. <ButtonPrimary form={FORM_ID} autoFocus type="submit">
  74. {translate('settings.projects.change_visibility_form.submit')}
  75. </ButtonPrimary>
  76. }
  77. secondaryButtonLabel={translate('cancel')}
  78. />
  79. );
  80. }