/* * SonarQube * Copyright (C) 2009-2019 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; import QualifierIcon from 'sonar-ui-common/components/icons/QualifierIcon'; import { sortBy } from 'lodash'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { Button } from 'sonar-ui-common/components/controls/buttons'; import Checkbox from 'sonar-ui-common/components/controls/Checkbox'; import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip'; import SearchBox from 'sonar-ui-common/components/controls/SearchBox'; import Select from 'sonar-ui-common/components/controls/Select'; import BulkApplyTemplateModal from './BulkApplyTemplateModal'; import DeleteModal from './DeleteModal'; import DateInput from '../../components/controls/DateInput'; import { Project } from '../../api/components'; export interface Props { analyzedBefore: Date | undefined; onAllDeselected: () => void; onAllSelected: () => void; onDateChanged: (analyzedBefore: Date | undefined) => void; onDeleteProjects: () => void; onProvisionedChanged: (provisioned: boolean) => void; onQualifierChanged: (qualifier: string) => void; onVisibilityChanged: (qualifier: string) => void; onSearch: (query: string) => void; organization: T.Organization; projects: Project[]; provisioned: boolean; qualifiers: string; query: string; ready: boolean; selection: any[]; topLevelQualifiers: string[]; total: number; visibility?: T.Visibility; } interface State { bulkApplyTemplateModal: boolean; deleteModal: boolean; } const QUALIFIERS_ORDER = ['TRK', 'VW', 'APP']; export default class Search extends React.PureComponent { mounted = false; state: State = { bulkApplyTemplateModal: false, deleteModal: false }; getQualifierOptions = () => { const options = this.props.topLevelQualifiers.map(q => ({ label: translate('qualifiers', q), value: q })); return sortBy(options, option => QUALIFIERS_ORDER.indexOf(option.value)); }; onCheck = (checked: boolean) => { if (checked) { this.props.onAllSelected(); } else { this.props.onAllDeselected(); } }; handleDeleteClick = () => { this.setState({ deleteModal: true }); }; closeDeleteModal = () => { this.setState({ deleteModal: false }); }; handleDeleteConfirm = () => { this.closeDeleteModal(); this.props.onDeleteProjects(); }; handleBulkApplyTemplateClick = () => { this.setState({ bulkApplyTemplateModal: true }); }; closeBulkApplyTemplateModal = () => { this.setState({ bulkApplyTemplateModal: false }); }; handleQualifierChange = ({ value }: { value: string }) => this.props.onQualifierChanged(value); handleVisibilityChange = ({ value }: { value: string }) => this.props.onVisibilityChanged(value); renderCheckbox = () => { const isAllChecked = this.props.projects.length > 0 && this.props.selection.length === this.props.projects.length; const thirdState = this.props.projects.length > 0 && this.props.selection.length > 0 && this.props.selection.length < this.props.projects.length; const checked = isAllChecked || thirdState; return ( ); }; renderQualifierOption = (option: { label: string; value: string }) => ( {option.label} ); renderQualifierFilter = () => { const options = this.getQualifierOptions(); if (options.length < 2) { return null; } return ( ); }; renderTypeFilter = () => this.props.qualifiers === 'TRK' ? ( {translate('provisioning.only_provisioned')} ) : null; renderDateFilter = () => { return ( ); }; render() { return (
{this.renderQualifierFilter()} {this.renderDateFilter()} {this.renderVisibilityFilter()} {this.renderTypeFilter()}
{this.props.ready ? this.renderCheckbox() : } {this.props.qualifiers === 'TRK' && ( )}
{this.state.bulkApplyTemplateModal && ( )} {this.state.deleteModal && ( )}
); } }