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.

Search.tsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 { ButtonSecondary, InputSearch } from 'design-system';
  21. import * as React from 'react';
  22. import { translate } from '../../../helpers/l10n';
  23. import { DEFAULT_FILTERS } from '../constants';
  24. import { Query } from '../utils';
  25. import CurrentsFilter from './CurrentsFilter';
  26. import DateFilter from './DateFilter';
  27. import StatusFilter from './StatusFilter';
  28. import TypesFilter from './TypesFilter';
  29. interface Props {
  30. component?: unknown;
  31. currents: string;
  32. loading: boolean;
  33. onFilterUpdate: (changes: Partial<Query>) => void;
  34. onReload: () => void;
  35. query: string;
  36. status: string;
  37. taskType: string;
  38. maxExecutedAt: Date | undefined;
  39. minSubmittedAt: Date | undefined;
  40. types: string[];
  41. }
  42. export default class Search extends React.PureComponent<Props> {
  43. handleStatusChange = (status: string) => {
  44. this.props.onFilterUpdate({ status });
  45. };
  46. handleTypeChange = (taskType: string) => {
  47. this.props.onFilterUpdate({ taskType });
  48. };
  49. handleCurrentsChange = (currents: string) => {
  50. this.props.onFilterUpdate({ currents });
  51. };
  52. handleDateChange = (date: { maxExecutedAt?: Date; minSubmittedAt?: Date }) => {
  53. this.props.onFilterUpdate(date);
  54. };
  55. handleQueryChange = (query: string) => {
  56. this.props.onFilterUpdate({ query });
  57. };
  58. handleReload = () => {
  59. this.props.onReload();
  60. };
  61. handleReset = () => {
  62. this.props.onFilterUpdate(DEFAULT_FILTERS);
  63. };
  64. render() {
  65. const {
  66. loading,
  67. component,
  68. query,
  69. types,
  70. status,
  71. taskType,
  72. currents,
  73. minSubmittedAt,
  74. maxExecutedAt,
  75. } = this.props;
  76. return (
  77. <section className="sw-my-4">
  78. <ul className="sw-flex sw-items-center sw-flex-wrap sw-gap-4">
  79. <li>
  80. <label
  81. id="background-task-status-filter-label"
  82. className="sw-body-sm-highlight sw-mr-2"
  83. htmlFor="status-filter"
  84. >
  85. {translate('status')}
  86. </label>
  87. <StatusFilter id="status-filter" onChange={this.handleStatusChange} value={status} />
  88. </li>
  89. {types.length > 1 && (
  90. <li>
  91. <label
  92. id="background-task-type-filter-label"
  93. className="sw-body-sm-highlight sw-mr-2"
  94. htmlFor="types-filter"
  95. >
  96. {translate('type')}
  97. </label>
  98. <TypesFilter
  99. id="types-filter"
  100. onChange={this.handleTypeChange}
  101. types={types}
  102. value={taskType}
  103. />
  104. </li>
  105. )}
  106. {!component && (
  107. <li className="sw-flex sw-items-center">
  108. <label className="sw-body-sm-highlight sw-mr-2">
  109. {translate('background_tasks.currents_filter.ONLY_CURRENTS')}
  110. </label>
  111. <CurrentsFilter onChange={this.handleCurrentsChange} value={currents} />
  112. </li>
  113. )}
  114. <li className="sw-flex sw-items-center">
  115. <label className="sw-body-sm-highlight sw-mr-2">
  116. {translate('background_tasks.date_filter')}
  117. </label>
  118. <DateFilter
  119. maxExecutedAt={maxExecutedAt}
  120. minSubmittedAt={minSubmittedAt}
  121. onChange={this.handleDateChange}
  122. />
  123. </li>
  124. {!component && (
  125. <li>
  126. <InputSearch
  127. onChange={this.handleQueryChange}
  128. placeholder={translate('background_tasks.search_by_task_or_component')}
  129. value={query}
  130. />
  131. </li>
  132. )}
  133. <li>
  134. <ButtonSecondary
  135. className="js-reload sw-mr-2"
  136. disabled={loading}
  137. onClick={this.handleReload}
  138. >
  139. {translate('reload')}
  140. </ButtonSecondary>
  141. <ButtonSecondary disabled={loading} onClick={this.handleReset}>
  142. {translate('reset_verb')}
  143. </ButtonSecondary>
  144. </li>
  145. </ul>
  146. </section>
  147. );
  148. }
  149. }