From 1f271fd894cdc74682b801cbc202309b120a3738 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Tue, 30 Jan 2018 16:02:17 +0100 Subject: [PATCH] Add back missing action to bulk unassign issues --- .../apps/issues/components/BulkChangeModal.js | 84 +++++++-------- .../src/main/js/apps/issues/utils.js | 2 +- .../{SearchSelect.js => SearchSelect.tsx} | 100 +++++++++--------- ...chSelect-test.js => SearchSelect-test.tsx} | 2 +- ...est.js.snap => SearchSelect-test.tsx.snap} | 1 - .../__snapshots__/FacetFooter-test.js.snap | 2 - 6 files changed, 89 insertions(+), 102 deletions(-) rename server/sonar-web/src/main/js/components/controls/{SearchSelect.js => SearchSelect.tsx} (58%) rename server/sonar-web/src/main/js/components/controls/__tests__/{SearchSelect-test.js => SearchSelect-test.tsx} (98%) rename server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/{SearchSelect-test.js.snap => SearchSelect-test.tsx.snap} (96%) diff --git a/server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.js b/server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.js index 6ac8ce8b88f..c5d585adcf3 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.js +++ b/server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.js @@ -109,44 +109,40 @@ export default class BulkChangeModal extends React.PureComponent { this.mounted = false; } + loadIssues = () => this.props.fetchIssues({ additionalFields: 'actions,transitions', ps: 250 }); + + getDefaultAssignee = () => { + const { currentUser } = this.props; + const { issues } = this.state; + const options = []; + + if (currentUser.isLoggedIn) { + const canBeAssignedToMe = + issues.filter(issue => issue.assignee !== currentUser.login).length > 0; + if (canBeAssignedToMe) { + options.push({ + avatar: currentUser.avatar, + label: currentUser.name, + value: currentUser.login + }); + } + } + + const canBeUnassigned = issues.filter(issue => issue.assignee).length > 0; + if (canBeUnassigned) { + options.push({ label: translate('unassigned'), value: '' }); + } + + return options; + }; + handleCloseClick = (e /*: Event & { target: HTMLElement } */) => { e.preventDefault(); e.target.blur(); this.props.onClose(); }; - loadIssues = () => { - return this.props.fetchIssues({ additionalFields: 'actions,transitions', ps: 250 }); - }; - - handleAssigneeSearch = (query /*: string */) => { - if (query.length > 1) { - return searchAssignees(query, this.state.organization); - } else { - const { currentUser } = this.props; - const { issues } = this.state; - const options = []; - - if (currentUser.isLoggedIn) { - const canBeAssignedToMe = - issues.filter(issue => issue.assignee !== currentUser.login).length > 0; - if (canBeAssignedToMe) { - options.push({ - email: currentUser.email, - label: currentUser.name, - value: currentUser.login - }); - } - } - - const canBeUnassigned = issues.filter(issue => issue.assignee).length > 0; - if (canBeUnassigned) { - options.push({ label: translate('unassigned'), value: '' }); - } - - return Promise.resolve(options); - } - }; + handleAssigneeSearch = (query /*: string */) => searchAssignees(query, this.state.organization); handleAssigneeSelect = (assignee /*: string */) => { this.setState({ assignee }); @@ -270,19 +266,16 @@ export default class BulkChangeModal extends React.PureComponent { ); - renderAssigneeOption = (option /*: { avatar?: string, email?: string, label: string } */) => ( - - {option.avatar != null && ( - - )} - {option.label} - - ); + renderAssigneeOption = (option /*: { avatar?: string, email?: string, label: string } */) => { + return ( + + {option.avatar != null && ( + + )} + {option.label} + + ); + }; renderAssigneeField = () => { const affected /*: number */ = this.state.issues.filter(hasAction('assign')).length; @@ -293,6 +286,7 @@ export default class BulkChangeModal extends React.PureComponent { const input = ( { diff --git a/server/sonar-web/src/main/js/components/controls/SearchSelect.js b/server/sonar-web/src/main/js/components/controls/SearchSelect.tsx similarity index 58% rename from server/sonar-web/src/main/js/components/controls/SearchSelect.js rename to server/sonar-web/src/main/js/components/controls/SearchSelect.tsx index bed2a3acd1b..07f9b2dac2a 100644 --- a/server/sonar-web/src/main/js/components/controls/SearchSelect.js +++ b/server/sonar-web/src/main/js/components/controls/SearchSelect.tsx @@ -17,51 +17,40 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// @flow -import React from 'react'; +import * as React from 'react'; import { debounce } from 'lodash'; import Select from '../../components/controls/Select'; import { translate, translateWithParameters } from '../../helpers/l10n'; -/*:: -type Option = { label: string, value: string }; -*/ - -/*:: -type Props = {| - autofocus: boolean, - minimumQueryLength: number, - onSearch: (query: string) => Promise>, - onSelect: (value: string) => void, - renderOption?: (option: Object) => React.Element<*>, - resetOnBlur: boolean, - value?: string -|}; -*/ +interface Option { + label: string; + value: string; +} -/*:: -type State = { - loading: boolean, - options: Array