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.

ProjectLinkRow.tsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 {
  21. ActionCell,
  22. ContentCell,
  23. DestructiveIcon,
  24. Link,
  25. Note,
  26. TableRow,
  27. TrashIcon,
  28. } from 'design-system';
  29. import * as React from 'react';
  30. import isValidUri from '../../app/utils/isValidUri';
  31. import ConfirmButton from '../../components/controls/ConfirmButton';
  32. import { translate, translateWithParameters } from '../../helpers/l10n';
  33. import { getLinkName, isProvided } from '../../helpers/projectLinks';
  34. import { ProjectLink } from '../../types/types';
  35. interface Props {
  36. link: ProjectLink;
  37. onDelete: (linkId: string) => Promise<void>;
  38. }
  39. export default class LinkRow extends React.PureComponent<Props> {
  40. renderNameForProvided = (link: ProjectLink) => {
  41. return (
  42. <div>
  43. <div>
  44. <span>{getLinkName(link)}</span>
  45. </div>
  46. <Note className="sw-mt-1">
  47. <span>{`sonar.links.${link.type}`}</span>
  48. </Note>
  49. </div>
  50. );
  51. };
  52. renderDeleteButton = (link: ProjectLink) => {
  53. if (isProvided(link)) {
  54. return null;
  55. }
  56. return (
  57. <ConfirmButton
  58. confirmButtonText={translate('delete')}
  59. confirmData={link.id}
  60. isDestructive
  61. modalBody={translateWithParameters(
  62. 'project_links.are_you_sure_to_delete_x_link',
  63. link.name ?? '',
  64. )}
  65. modalHeader={translate('project_links.delete_project_link')}
  66. onConfirm={this.props.onDelete}
  67. >
  68. {({ onClick }) => (
  69. <DestructiveIcon
  70. Icon={TrashIcon}
  71. aria-label={translateWithParameters('project_links.delete_x_link', link.name ?? '')}
  72. onClick={onClick}
  73. size="small"
  74. />
  75. )}
  76. </ConfirmButton>
  77. );
  78. };
  79. render() {
  80. const { link } = this.props;
  81. return (
  82. <TableRow data-name={link.name}>
  83. <ContentCell>
  84. {isProvided(link) ? (
  85. this.renderNameForProvided(link)
  86. ) : (
  87. <div>
  88. <span>{link.name}</span>
  89. </div>
  90. )}
  91. </ContentCell>
  92. <ContentCell>
  93. {isValidUri(link.url) ? (
  94. <Link to={link.url} target="_blank">
  95. {link.url}
  96. </Link>
  97. ) : (
  98. link.url
  99. )}
  100. </ContentCell>
  101. <ActionCell>{this.renderDeleteButton(link)}</ActionCell>
  102. </TableRow>
  103. );
  104. }
  105. }