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.

ProjectActivityPageHeader.tsx 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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 * as classNames from 'classnames';
  22. import { translate } from 'sonar-ui-common/helpers/l10n';
  23. import Select from 'sonar-ui-common/components/controls/Select';
  24. import ProjectActivityEventSelectOption from './ProjectActivityEventSelectOption';
  25. import ProjectActivityEventSelectValue from './ProjectActivityEventSelectValue';
  26. import ProjectActivityDateInput from './ProjectActivityDateInput';
  27. import { EVENT_TYPES, APPLICATION_EVENT_TYPES, Query } from '../utils';
  28. interface Props {
  29. category?: string;
  30. from?: Date;
  31. project: Pick<T.Component, 'qualifier'>;
  32. to?: Date;
  33. updateQuery: (changes: Partial<Query>) => void;
  34. }
  35. export default class ProjectActivityPageHeader extends React.PureComponent<Props> {
  36. handleCategoryChange = (option: { value: string } | null) =>
  37. this.props.updateQuery({ category: option ? option.value : '' });
  38. render() {
  39. const isApp = this.props.project.qualifier === 'APP';
  40. const eventTypes = isApp ? APPLICATION_EVENT_TYPES : EVENT_TYPES;
  41. const options = eventTypes.map(category => ({
  42. label: translate('event.category', category),
  43. value: category
  44. }));
  45. return (
  46. <header className="page-header">
  47. {!['VW', 'SVW'].includes(this.props.project.qualifier) && (
  48. <Select
  49. className={classNames('pull-left big-spacer-right', {
  50. 'input-medium': !isApp,
  51. 'input-large': isApp
  52. })}
  53. clearable={true}
  54. onChange={this.handleCategoryChange}
  55. optionComponent={ProjectActivityEventSelectOption}
  56. options={options}
  57. placeholder={translate('project_activity.filter_events') + '...'}
  58. searchable={false}
  59. value={this.props.category}
  60. // @ts-ignore react-select typings are incorrect, they expect `props` of `valueComponent` to be exactly `Option`
  61. valueComponent={ProjectActivityEventSelectValue}
  62. />
  63. )}
  64. <ProjectActivityDateInput
  65. from={this.props.from}
  66. onChange={this.props.updateQuery}
  67. to={this.props.to}
  68. />
  69. </header>
  70. );
  71. }
  72. }