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.

ListItem.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 * as React from 'react';
  21. import Issue from '../../../components/issue/Issue';
  22. import { BranchLike } from '../../../types/branch-like';
  23. import { Query } from '../utils';
  24. import ComponentBreadcrumbs from './ComponentBreadcrumbs';
  25. interface Props {
  26. branchLike: BranchLike | undefined;
  27. checked: boolean;
  28. component: T.Component | undefined;
  29. issue: T.Issue;
  30. onChange: (issue: T.Issue) => void;
  31. onCheck: ((issueKey: string) => void) | undefined;
  32. onClick: (issueKey: string) => void;
  33. onFilterChange: (changes: Partial<Query>) => void;
  34. onPopupToggle: (issue: string, popupName: string, open?: boolean) => void;
  35. openPopup: string | undefined;
  36. previousIssue: T.Issue | undefined;
  37. selected: boolean;
  38. }
  39. export default class ListItem extends React.PureComponent<Props> {
  40. handleFilter = (property: string, issue: T.Issue) => {
  41. const { onFilterChange } = this.props;
  42. const issuesReset = { issues: [] };
  43. if (property.startsWith('tag###')) {
  44. const tag = property.substr(6);
  45. onFilterChange({ ...issuesReset, tags: [tag] });
  46. } else {
  47. switch (property) {
  48. case 'type':
  49. onFilterChange({ ...issuesReset, types: [issue.type] });
  50. break;
  51. case 'severity':
  52. onFilterChange({ ...issuesReset, severities: [issue.severity] });
  53. break;
  54. case 'status':
  55. onFilterChange({ ...issuesReset, statuses: [issue.status] });
  56. break;
  57. case 'resolution':
  58. if (issue.resolution) {
  59. onFilterChange({ ...issuesReset, resolved: true, resolutions: [issue.resolution] });
  60. } else {
  61. onFilterChange({ ...issuesReset, resolved: false, resolutions: [] });
  62. }
  63. break;
  64. case 'assignee':
  65. if (issue.assignee) {
  66. onFilterChange({ ...issuesReset, assigned: true, assignees: [issue.assignee] });
  67. } else {
  68. onFilterChange({ ...issuesReset, assigned: false, assignees: [] });
  69. }
  70. break;
  71. case 'rule':
  72. onFilterChange({ ...issuesReset, rules: [issue.rule] });
  73. break;
  74. case 'project':
  75. onFilterChange({ ...issuesReset, projects: [issue.projectKey] });
  76. break;
  77. case 'file':
  78. onFilterChange({ ...issuesReset, files: [issue.componentUuid] });
  79. }
  80. }
  81. };
  82. render() {
  83. const { branchLike, component, issue, previousIssue } = this.props;
  84. const displayComponent = !previousIssue || previousIssue.component !== issue.component;
  85. return (
  86. <li className="issues-workspace-list-item">
  87. {displayComponent && (
  88. <div className="issues-workspace-list-component note">
  89. <ComponentBreadcrumbs component={component} issue={this.props.issue} />
  90. </div>
  91. )}
  92. <Issue
  93. branchLike={branchLike}
  94. checked={this.props.checked}
  95. issue={issue}
  96. onChange={this.props.onChange}
  97. onCheck={this.props.onCheck}
  98. onClick={this.props.onClick}
  99. onFilter={this.handleFilter}
  100. onPopupToggle={this.props.onPopupToggle}
  101. openPopup={this.props.openPopup}
  102. selected={this.props.selected}
  103. />
  104. </li>
  105. );
  106. }
  107. }