const { isCompleted, hasFailures } = this.props.indexationContext.status;
if (!isCompleted) {
- IndexationNotificationHelper.markInProgressNotificationAsDisplayed();
+ IndexationNotificationHelper.markCompletedNotificationAsToDisplay();
this.setState({
notificationType: hasFailures
? IndexationNotificationType.InProgressWithFailure
this.setState({
notificationType: IndexationNotificationType.Completed
});
+ IndexationNotificationHelper.markCompletedNotificationAsDisplayed();
} else {
this.setState({ notificationType: undefined });
}
}
- handleDismissCompletedNotification = () => {
- IndexationNotificationHelper.markCompletedNotificationAsDismissed();
- this.refreshNotification();
- };
-
render() {
const { notificationType } = this.state;
const {
type={notificationType}
percentCompleted={percentCompleted}
isSystemAdmin={this.isSystemAdmin}
- onDismissCompletedNotification={this.handleDismissCompletedNotification}
/>
);
}
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;
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()
+ );
}
}
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';
type: IndexationNotificationType;
percentCompleted: number;
isSystemAdmin: boolean;
- onDismissCompletedNotification: VoidFunction;
}
const NOTIFICATION_VARIANTS: { [key in IndexationNotificationType]: AlertProps['variant'] } = {
);
}
-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) {
import { IndexationNotificationType } from '../../../../types/indexation';
import { IndexationNotification } from '../IndexationNotification';
import IndexationNotificationHelper from '../IndexationNotificationHelper';
-import IndexationNotificationRenderer from '../IndexationNotificationRenderer';
beforeEach(() => jest.clearAllMocks());
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
);
});
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();
});
});
indexationContext: { status: { isCompleted: false, percentCompleted: 23, hasFailures: false } }
});
- expect(IndexationNotificationHelper.markInProgressNotificationAsDisplayed).toHaveBeenCalled();
+ expect(IndexationNotificationHelper.markCompletedNotificationAsToDisplay).toHaveBeenCalled();
expect(wrapper.state().notificationType).toBe(IndexationNotificationType.InProgress);
});
indexationContext: { status: { isCompleted: false, percentCompleted: 23, hasFailures: true } }
});
- expect(IndexationNotificationHelper.markInProgressNotificationAsDisplayed).toHaveBeenCalled();
+ expect(IndexationNotificationHelper.markCompletedNotificationAsToDisplay).toHaveBeenCalled();
expect(wrapper.state().notificationType).toBe(IndexationNotificationType.InProgressWithFailure);
});
});
it('should properly handle the flag to show the completed banner', () => {
- IndexationNotificationHelper.markInProgressNotificationAsDisplayed();
+ IndexationNotificationHelper.markCompletedNotificationAsToDisplay();
expect(save).toHaveBeenCalledWith(expect.any(String), 'true');
expect(shouldDisplay).toBe(true);
expect(get).toHaveBeenCalled();
- IndexationNotificationHelper.markCompletedNotificationAsDismissed();
+ IndexationNotificationHelper.markCompletedNotificationAsDisplayed();
expect(remove).toHaveBeenCalled();
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
}
);
-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}
/>
);
>
indexation.completed
</span>
- <ClearButton
- className="button-tiny"
- onClick={[MockFunction]}
- title="dismiss"
- />
</div>
</Alert>
</div>
>
indexation.completed
</span>
- <ClearButton
- className="button-tiny"
- onClick={[MockFunction]}
- title="dismiss"
- />
</div>
</Alert>
</div>