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.

Event.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 { DestructiveIcon, InteractiveIcon, PencilIcon, TrashIcon } from 'design-system';
  21. import * as React from 'react';
  22. import EventInner from '../../../components/activity-graph/EventInner';
  23. import Tooltip from '../../../components/controls/Tooltip';
  24. import { translate } from '../../../helpers/l10n';
  25. import { AnalysisEvent, ProjectAnalysisEventCategory } from '../../../types/project-activity';
  26. import ChangeEventForm from './forms/ChangeEventForm';
  27. import RemoveEventForm from './forms/RemoveEventForm';
  28. export interface EventProps {
  29. analysisKey: string;
  30. canAdmin?: boolean;
  31. event: AnalysisEvent;
  32. isFirst?: boolean;
  33. }
  34. function Event(props: Readonly<EventProps>) {
  35. const { analysisKey, event, canAdmin, isFirst } = props;
  36. const [changing, setChanging] = React.useState(false);
  37. const [deleting, setDeleting] = React.useState(false);
  38. const isOther = event.category === ProjectAnalysisEventCategory.Other;
  39. const isVersion = event.category === ProjectAnalysisEventCategory.Version;
  40. const canChange = isOther || isVersion;
  41. const canDelete = isOther || (isVersion && !isFirst);
  42. const showActions = canAdmin && (canChange || canDelete);
  43. return (
  44. <div className="it__project-activity-event sw-flex sw-justify-between">
  45. <EventInner event={event} />
  46. {showActions && (
  47. <div className="sw-grow-0 sw-shrink-0 sw-ml-2">
  48. {canChange && (
  49. <Tooltip overlay={translate('project_activity.events.tooltip.edit')}>
  50. <InteractiveIcon
  51. Icon={PencilIcon}
  52. aria-label={translate('project_activity.events.tooltip.edit')}
  53. data-test="project-activity__edit-event"
  54. onClick={() => setChanging(true)}
  55. stopPropagation
  56. size="small"
  57. />
  58. </Tooltip>
  59. )}
  60. {canDelete && (
  61. <Tooltip overlay={translate('project_activity.events.tooltip.delete')}>
  62. <DestructiveIcon
  63. Icon={TrashIcon}
  64. aria-label={translate('project_activity.events.tooltip.delete')}
  65. data-test="project-activity__delete-event"
  66. onClick={() => setDeleting(true)}
  67. stopPropagation
  68. size="small"
  69. />
  70. </Tooltip>
  71. )}
  72. </div>
  73. )}
  74. {changing && (
  75. <ChangeEventForm
  76. event={event}
  77. header={
  78. isVersion
  79. ? translate('project_activity.change_version')
  80. : translate('project_activity.change_custom_event')
  81. }
  82. onClose={() => setChanging(false)}
  83. />
  84. )}
  85. {deleting && (
  86. <RemoveEventForm
  87. analysisKey={analysisKey}
  88. event={event}
  89. header={
  90. isVersion
  91. ? translate('project_activity.remove_version')
  92. : translate('project_activity.remove_custom_event')
  93. }
  94. onClose={() => setDeleting(false)}
  95. removeEventQuestion={translate(
  96. `project_activity.${isVersion ? 'remove_version' : 'remove_custom_event'}.question`,
  97. )}
  98. />
  99. )}
  100. </div>
  101. );
  102. }
  103. export default React.memo(Event);