]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13716 Indexation success banner should go away on a page refresh
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Wed, 5 Aug 2020 07:37:56 +0000 (09:37 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 11 Aug 2020 20:06:01 +0000 (20:06 +0000)
server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx
server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationHelper.ts
server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx
server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationHelper-test.tsx
server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotificationRenderer-test.tsx
server/sonar-web/src/main/js/app/components/indexation/__tests__/__snapshots__/IndexationNotificationRenderer-test.tsx.snap

index f83508fb0ca3b9b65da7e04fab24ca6411222dbe..afc7d7fdb095ef1492257ccb358b4c91f4056fcf 100644 (file)
@@ -62,7 +62,7 @@ export class IndexationNotification extends React.PureComponent<Props, State> {
     const { isCompleted, hasFailures } = this.props.indexationContext.status;
 
     if (!isCompleted) {
-      IndexationNotificationHelper.markInProgressNotificationAsDisplayed();
+      IndexationNotificationHelper.markCompletedNotificationAsToDisplay();
       this.setState({
         notificationType: hasFailures
           ? IndexationNotificationType.InProgressWithFailure
@@ -74,16 +74,12 @@ export class IndexationNotification extends React.PureComponent<Props, State> {
       this.setState({
         notificationType: IndexationNotificationType.Completed
       });
+      IndexationNotificationHelper.markCompletedNotificationAsDisplayed();
     } else {
       this.setState({ notificationType: undefined });
     }
   }
 
-  handleDismissCompletedNotification = () => {
-    IndexationNotificationHelper.markCompletedNotificationAsDismissed();
-    this.refreshNotification();
-  };
-
   render() {
     const { notificationType } = this.state;
     const {
@@ -101,7 +97,6 @@ export class IndexationNotification extends React.PureComponent<Props, State> {
         type={notificationType}
         percentCompleted={percentCompleted}
         isSystemAdmin={this.isSystemAdmin}
-        onDismissCompletedNotification={this.handleDismissCompletedNotification}
       />
     );
   }
index 792e7c83e6bfea9758227a1f4510ce097516c951..c97503c1010c47c9896c7e44dfa30c6332adc03b 100644 (file)
@@ -23,7 +23,8 @@ import { getIndexationStatus } from '../../../api/ce';
 import { IndexationStatus } from '../../../types/indexation';
 
 const POLLING_INTERVAL_MS = 5000;
-const LS_INDEXATION_PROGRESS_WAS_DISPLAYED = 'indexation.progress.was.displayed';
+const LS_INDEXATION_COMPLETED_NOTIFICATION_SHOULD_BE_DISPLAYED =
+  'display_indexation_completed_notification';
 
 export default class IndexationNotificationHelper {
   private static interval?: NodeJS.Timeout;
@@ -57,15 +58,17 @@ export default class IndexationNotificationHelper {
     return status;
   }
 
-  static markInProgressNotificationAsDisplayed() {
-    save(LS_INDEXATION_PROGRESS_WAS_DISPLAYED, true.toString());
+  static markCompletedNotificationAsToDisplay() {
+    save(LS_INDEXATION_COMPLETED_NOTIFICATION_SHOULD_BE_DISPLAYED, true.toString());
   }
 
-  static markCompletedNotificationAsDismissed() {
-    remove(LS_INDEXATION_PROGRESS_WAS_DISPLAYED);
+  static markCompletedNotificationAsDisplayed() {
+    remove(LS_INDEXATION_COMPLETED_NOTIFICATION_SHOULD_BE_DISPLAYED);
   }
 
   static shouldDisplayCompletedNotification() {
-    return JSON.parse(get(LS_INDEXATION_PROGRESS_WAS_DISPLAYED) || false.toString());
+    return JSON.parse(
+      get(LS_INDEXATION_COMPLETED_NOTIFICATION_SHOULD_BE_DISPLAYED) || false.toString()
+    );
   }
 }
index 791059c3e90bd280dfd69b6cc0fa10cc5bb2e2cf..a945219678f6f6adc40cac6dfce77fbe9e79bfa5 100644 (file)
@@ -21,7 +21,6 @@
 import * as React from 'react';
 import { FormattedMessage } from 'react-intl';
 import { Link } from 'react-router';
-import { ClearButton } from 'sonar-ui-common/components/controls/buttons';
 import { Alert, AlertProps } from 'sonar-ui-common/components/ui/Alert';
 import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
 import { BackgroundTaskTypes, STATUSES } from '../../../apps/background-tasks/constants';
@@ -31,7 +30,6 @@ export interface IndexationNotificationRendererProps {
   type: IndexationNotificationType;
   percentCompleted: number;
   isSystemAdmin: boolean;
-  onDismissCompletedNotification: VoidFunction;
 }
 
 const NOTIFICATION_VARIANTS: { [key in IndexationNotificationType]: AlertProps['variant'] } = {
@@ -63,17 +61,8 @@ export default function IndexationNotificationRenderer(props: IndexationNotifica
   );
 }
 
-function renderCompletedBanner(props: IndexationNotificationRendererProps) {
-  return (
-    <>
-      <span className="spacer-right">{translate('indexation.completed')}</span>
-      <ClearButton
-        className="button-tiny"
-        title={translate('dismiss')}
-        onClick={props.onDismissCompletedNotification}
-      />
-    </>
-  );
+function renderCompletedBanner(_props: IndexationNotificationRendererProps) {
+  return <span className="spacer-right">{translate('indexation.completed')}</span>;
 }
 
 function renderCompletedWithFailureBanner(props: IndexationNotificationRendererProps) {
index 2efdb483485983a51c53cca704ebd0306caab65e..2e0de221c000faa4ceec1c4d16c91639fcffa1c4 100644 (file)
@@ -24,7 +24,6 @@ import { mockCurrentUser } from '../../../../helpers/testMocks';
 import { IndexationNotificationType } from '../../../../types/indexation';
 import { IndexationNotification } from '../IndexationNotification';
 import IndexationNotificationHelper from '../IndexationNotificationHelper';
-import IndexationNotificationRenderer from '../IndexationNotificationRenderer';
 
 beforeEach(() => jest.clearAllMocks());
 
@@ -63,7 +62,7 @@ describe('Completed banner', () => {
     expect(wrapper.state().notificationType).toBe(IndexationNotificationType.Completed);
   });
 
-  it('should be hidden on dismiss action', () => {
+  it('should be hidden on refresh once displayed', () => {
     (IndexationNotificationHelper.shouldDisplayCompletedNotification as jest.Mock).mockReturnValueOnce(
       true
     );
@@ -75,14 +74,7 @@ describe('Completed banner', () => {
     });
 
     expect(wrapper.state().notificationType).toBe(IndexationNotificationType.Completed);
-
-    wrapper
-      .find(IndexationNotificationRenderer)
-      .props()
-      .onDismissCompletedNotification();
-
-    expect(IndexationNotificationHelper.markCompletedNotificationAsDismissed).toHaveBeenCalled();
-    expect(wrapper.state().notificationType).toBeUndefined();
+    expect(IndexationNotificationHelper.markCompletedNotificationAsDisplayed).toHaveBeenCalled();
   });
 });
 
@@ -99,7 +91,7 @@ it('should display the progress banner', () => {
     indexationContext: { status: { isCompleted: false, percentCompleted: 23, hasFailures: false } }
   });
 
-  expect(IndexationNotificationHelper.markInProgressNotificationAsDisplayed).toHaveBeenCalled();
+  expect(IndexationNotificationHelper.markCompletedNotificationAsToDisplay).toHaveBeenCalled();
   expect(wrapper.state().notificationType).toBe(IndexationNotificationType.InProgress);
 });
 
@@ -108,7 +100,7 @@ it('should display the progress-with-failure banner', () => {
     indexationContext: { status: { isCompleted: false, percentCompleted: 23, hasFailures: true } }
   });
 
-  expect(IndexationNotificationHelper.markInProgressNotificationAsDisplayed).toHaveBeenCalled();
+  expect(IndexationNotificationHelper.markCompletedNotificationAsToDisplay).toHaveBeenCalled();
   expect(wrapper.state().notificationType).toBe(IndexationNotificationType.InProgressWithFailure);
 });
 
index ea3d923dd8536d3a970ee8df8c030f66df794f1f..444eb0599e661de3370926513b71ba091ad2e550 100644 (file)
@@ -65,7 +65,7 @@ it('should properly start & stop polling for indexation status', async () => {
 });
 
 it('should properly handle the flag to show the completed banner', () => {
-  IndexationNotificationHelper.markInProgressNotificationAsDisplayed();
+  IndexationNotificationHelper.markCompletedNotificationAsToDisplay();
 
   expect(save).toHaveBeenCalledWith(expect.any(String), 'true');
 
@@ -75,7 +75,7 @@ it('should properly handle the flag to show the completed banner', () => {
   expect(shouldDisplay).toBe(true);
   expect(get).toHaveBeenCalled();
 
-  IndexationNotificationHelper.markCompletedNotificationAsDismissed();
+  IndexationNotificationHelper.markCompletedNotificationAsDisplayed();
 
   expect(remove).toHaveBeenCalled();
 
index ea4f06dbb921d213d323fe111ddfc117d6dc9194..175f18add64c329b570c36a8e55de0b6f6007b10 100644 (file)
@@ -20,8 +20,6 @@
 
 import { shallow } from 'enzyme';
 import * as React from 'react';
-import { ClearButton } from 'sonar-ui-common/components/controls/buttons';
-import { click } from 'sonar-ui-common/helpers/testUtils';
 import { IndexationNotificationType } from '../../../../types/indexation';
 import IndexationNotificationRenderer, {
   IndexationNotificationRendererProps
@@ -43,24 +41,12 @@ it.each([
   }
 );
 
-it('should propagate the dismiss event from completed notification', () => {
-  const onDismissCompletedNotification = jest.fn();
-  const wrapper = shallowRender({
-    type: IndexationNotificationType.Completed,
-    onDismissCompletedNotification
-  });
-
-  click(wrapper.find(ClearButton));
-  expect(onDismissCompletedNotification).toHaveBeenCalled();
-});
-
 function shallowRender(props: Partial<IndexationNotificationRendererProps> = {}) {
   return shallow<IndexationNotificationRendererProps>(
     <IndexationNotificationRenderer
       type={IndexationNotificationType.InProgress}
       percentCompleted={25}
       isSystemAdmin={false}
-      onDismissCompletedNotification={jest.fn()}
       {...props}
     />
   );
index 8c57b55f88ad3a57d2deb7961cdbae5be4c46f0d..aebc9ce3e46cad96d76a59c97319e71ffb32e1c7 100644 (file)
@@ -17,11 +17,6 @@ exports[`should render correctly for type="Completed" & isSystemAdmin=false 1`]
       >
         indexation.completed
       </span>
-      <ClearButton
-        className="button-tiny"
-        onClick={[MockFunction]}
-        title="dismiss"
-      />
     </div>
   </Alert>
 </div>
@@ -44,11 +39,6 @@ exports[`should render correctly for type="Completed" & isSystemAdmin=true 1`] =
       >
         indexation.completed
       </span>
-      <ClearButton
-        className="button-tiny"
-        onClick={[MockFunction]}
-        title="dismiss"
-      />
     </div>
   </Alert>
 </div>