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.

AvailableSinceFacet.tsx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { DatePicker, FacetBox } from 'design-system';
  21. import * as React from 'react';
  22. import { WrappedComponentProps, injectIntl } from 'react-intl';
  23. import { translate, translateWithParameters } from '../../../helpers/l10n';
  24. import { Query } from '../query';
  25. interface Props {
  26. onChange: (changes: Partial<Query>) => void;
  27. onToggle: (property: keyof Query) => void;
  28. open: boolean;
  29. value?: Date;
  30. }
  31. class AvailableSinceFacet extends React.PureComponent<Props & WrappedComponentProps> {
  32. property: keyof Query = 'availableSince';
  33. handleHeaderClick = () => {
  34. this.props.onToggle(this.property);
  35. };
  36. handleClear = () => {
  37. this.props.onChange({ availableSince: undefined });
  38. };
  39. handlePeriodChange = (date: Date | undefined) => {
  40. this.props.onChange({ availableSince: date });
  41. };
  42. render() {
  43. const { open, value } = this.props;
  44. const headerId = `facet_${this.property}`;
  45. const count = value ? 1 : undefined;
  46. return (
  47. <FacetBox
  48. className="it__search-navigator-facet-box"
  49. clearIconLabel={translate('clear')}
  50. data-property={this.property}
  51. id={headerId}
  52. name={translate('coding_rules.facet.available_since')}
  53. onClear={this.handleClear}
  54. onClick={this.handleHeaderClick}
  55. open={open}
  56. count={count}
  57. countLabel={count ? translateWithParameters('x_selected', count) : undefined}
  58. >
  59. {open && (
  60. <DatePicker
  61. name="available-since"
  62. clearButtonLabel={translate('clear')}
  63. onChange={this.handlePeriodChange}
  64. placeholder={translate('date')}
  65. value={value}
  66. showClearButton
  67. alignRight
  68. size="auto"
  69. />
  70. )}
  71. </FacetBox>
  72. );
  73. }
  74. }
  75. export default injectIntl(AvailableSinceFacet);