]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19986 Do not load tags for bulk issue change modal when re-indexing
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Fri, 21 Jul 2023 09:41:01 +0000 (11:41 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 21 Jul 2023 20:03:17 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/components/BulkChangeModal.tsx
server/sonar-web/src/main/js/apps/issues/components/__tests__/BulkChangeModal-it.tsx

index bc3150259378911a0dddcaa2f17efe98f30f22af..bbe8bcc8a46df6bcdeea6cf57c417344467deafc 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
 import {
   ButtonPrimary,
   Checkbox,
@@ -96,9 +97,14 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
   }
 
   componentDidMount() {
+    const { needIssueSync } = this.props;
+
     this.mounted = true;
 
-    Promise.all([this.loadIssues(), searchIssueTags({})]).then(
+    Promise.all([
+      this.loadIssues(),
+      needIssueSync ? Promise.resolve([]) : searchIssueTags({}),
+    ]).then(
       ([{ issues, paging }, tags]) => {
         if (this.mounted) {
           if (issues.length > MAX_PAGE_SIZE) {
@@ -185,6 +191,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
     const issueKeys = this.state.issues.map((issue) => issue.key);
 
     this.setState({ submitting: true });
+
     bulkChangeIssues(issueKeys, query).then(
       () => {
         this.setState({ submitting: false });
@@ -200,6 +207,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
 
   getAvailableTransitions(issues: Issue[]) {
     const transitions: Dict<number> = {};
+
     issues.forEach((issue) => {
       if (issue.transitions) {
         issue.transitions.forEach((t) => {
@@ -211,6 +219,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
         });
       }
     });
+
     return sortBy(Object.keys(transitions)).map((transition) => ({
       transition,
       count: transitions[transition],
@@ -239,6 +248,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
     <FormField htmlFor={`issues-bulk-change-${field}`} label={translate(label)}>
       <div className="sw-flex sw-items-center sw-justify-between">
         {input}
+
         {affected !== undefined && (
           <LightLabel>
             ({translateWithParameters('issue_bulk_change.x_issues', affected)})
@@ -282,7 +292,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
     const options: LabelValueSelectOption<IssueType>[] = types.map((type) => ({
       label: translate('issue.type', type),
       value: type,
-      Icon: <IssueTypeIcon height={16} type={type} />,
+      Icon: <IssueTypeIcon type={type} />,
     }));
 
     const input = (
@@ -311,7 +321,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
     const options: LabelValueSelectOption<IssueSeverity>[] = SEVERITIES.map((severity) => ({
       label: translate('severity', severity),
       value: severity,
-      Icon: <IssueSeverityIcon height={16} severity={severity} />,
+      Icon: <IssueSeverityIcon severity={severity} />,
     }));
 
     const input = (
@@ -399,13 +409,13 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
 
     return (
       <FormField
-        label={translate('issue.comment.formlink')}
-        htmlFor="comment"
         help={
           <div className="-sw-mt-1" title={translate('issue_bulk_change.comment.help')}>
             <HelperHintIcon />
           </div>
         }
+        htmlFor="comment"
+        label={translate('issue.comment.formlink')}
       >
         <textarea
           id="comment"
@@ -457,11 +467,14 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
           {this.renderTypeField()}
           {this.renderSeverityField()}
           {!needIssueSync && this.renderTagsField(InputField.addTags, 'issue.add_tags', true)}
+
           {!needIssueSync &&
             this.renderTagsField(InputField.removeTags, 'issue.remove_tags', false)}
+
           {this.renderTransitionsField()}
           {this.renderCommentField()}
           {issues.length > 0 && this.renderNotificationsField()}
+
           {issues.length === 0 && (
             <FlagMessage variant="warning">{translate('issue_bulk_change.no_match')}</FlagMessage>
           )}
@@ -477,7 +490,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
 
     return (
       <Modal
-        onClose={this.props.onClose}
+        body={this.renderForm()}
         headerTitle={
           loading
             ? translate('bulk_change')
@@ -485,13 +498,13 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
         }
         isScrollable
         loading={submitting}
-        body={this.renderForm()}
+        onClose={this.props.onClose}
         primaryButton={
           <ButtonPrimary
-            id="bulk-change-submit"
+            disabled={!canSubmit || submitting || issues.length === 0}
             form="bulk-change-form"
+            id="bulk-change-submit"
             type="submit"
-            disabled={!canSubmit || submitting || issues.length === 0}
           >
             {translate('apply')}
           </ButtonPrimary>
@@ -503,7 +516,7 @@ export class BulkChangeModal extends React.PureComponent<Props, State> {
 }
 
 function hasAction(action: string) {
-  return (issue: Issue) => issue.actions && issue.actions.includes(action);
+  return (issue: Issue) => issue.actions?.includes(action);
 }
 
 export default withBranchStatusRefresh(BulkChangeModal);
index aec43a577d0a4d0d1859fe9681345914f4115765..1d59ba20401841107bafc6cbc3b993c64d8e5f9e 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+
 import { act, screen } from '@testing-library/react';
 import userEvent from '@testing-library/user-event';
 import * as React from 'react';
@@ -33,8 +34,8 @@ import { CurrentUser } from '../../../../types/users';
 import BulkChangeModal, { MAX_PAGE_SIZE } from '../BulkChangeModal';
 
 jest.mock('../../../../api/issues', () => ({
-  searchIssueTags: jest.fn().mockResolvedValue(['tag1', 'tag2']),
   bulkChangeIssues: jest.fn().mockResolvedValue({}),
+  searchIssueTags: jest.fn().mockResolvedValue(['tag1', 'tag2']),
 }));
 
 afterEach(() => {
@@ -49,14 +50,17 @@ it('should display error message when no issues available', async () => {
 
 it('should display warning when too many issues are passed', async () => {
   const issues: Issue[] = [];
+
   for (let i = MAX_PAGE_SIZE + 1; i > 0; i--) {
     issues.push(mockIssue());
   }
-  renderBulkChangeModal(issues);
+
+  renderBulkChangeModal(issues, { needIssueSync: true });
 
   expect(
     await screen.findByText(`issue_bulk_change.form.title.${MAX_PAGE_SIZE}`)
   ).toBeInTheDocument();
+
   expect(await screen.findByText('issue_bulk_change.max_issues_reached')).toBeInTheDocument();
 });
 
@@ -108,16 +112,17 @@ it('should disable the submit button unless some change is configured', async ()
 it('should properly submit', async () => {
   const onDone = jest.fn();
   const user = userEvent.setup();
+
   renderBulkChangeModal(
     [
       mockIssue(false, {
-        key: 'issue1',
         actions: ['assign', 'set_transition', 'set_tags', 'set_type', 'set_severity', 'comment'],
+        key: 'issue1',
         transitions: ['Transition1', 'Transition2'],
       }),
       mockIssue(false, {
-        key: 'issue2',
         actions: ['assign', 'set_transition', 'set_tags', 'set_type', 'set_severity', 'comment'],
+        key: 'issue2',
         transitions: ['Transition1', 'Transition2'],
       }),
     ],
@@ -137,6 +142,7 @@ it('should properly submit', async () => {
   await user.click(
     await screen.findByRole('combobox', { name: 'issue_bulk_change.assignee.change' })
   );
+
   await user.click(await screen.findByText('Toto'));
 
   // Transition
@@ -175,14 +181,15 @@ it('should properly submit', async () => {
 
   expect(bulkChangeIssues).toHaveBeenCalledTimes(1);
   expect(onDone).toHaveBeenCalledTimes(1);
+
   expect(bulkChangeIssues).toHaveBeenCalledWith(['issue1', 'issue2'], {
+    add_tags: 'tag1,tag2',
     assign: 'toto',
     comment: 'some comment',
-    set_severity: 'BLOCKER',
-    add_tags: 'tag1,tag2',
     do_transition: 'Transition2',
-    set_type: IssueType.CodeSmell,
     sendNotifications: true,
+    set_severity: 'BLOCKER',
+    set_type: IssueType.CodeSmell,
   });
 });