}
/>
<Connect(GlobalMessages) />
- <withIndexationContext(IndexationNotification) />
+ <Connect(withCurrentUser(withIndexationContext(IndexationNotification))) />
<ChildComponent />
</Connect(withAppState(IndexationContextProvider))>
</Workspace>
*/
import * as React from 'react';
+import { withCurrentUser } from '../../../components/hoc/withCurrentUser';
import withIndexationContext, {
WithIndexationContextProps
} from '../../../components/hoc/withIndexationContext';
+import { hasGlobalPermission, isLoggedIn } from '../../../helpers/users';
import './IndexationNotification.css';
import IndexationNotificationHelper from './IndexationNotificationHelper';
import IndexationNotificationRenderer from './IndexationNotificationRenderer';
+interface Props extends WithIndexationContextProps {
+ currentUser: T.CurrentUser;
+}
+
interface State {
progression?: IndexationProgression;
}
Completed
}
-export class IndexationNotification extends React.PureComponent<WithIndexationContextProps, State> {
- state: State = {
- progression: undefined
- };
+export class IndexationNotification extends React.PureComponent<Props, State> {
+ state: State;
+ isSystemAdmin = false;
+
+ constructor(props: Props) {
+ super(props);
+
+ this.state = { progression: undefined };
+ this.isSystemAdmin =
+ isLoggedIn(this.props.currentUser) && hasGlobalPermission(this.props.currentUser, 'admin');
+ }
componentDidMount() {
this.refreshNotification();
progression={progression}
percentCompleted={percentCompleted ?? 0}
onDismissCompletedNotification={this.handleDismissCompletedNotification}
+ displayBackgroundTaskLink={this.isSystemAdmin}
/>
);
}
}
-export default withIndexationContext(IndexationNotification);
+export default withCurrentUser(withIndexationContext(IndexationNotification));
*/
import * as React from 'react';
+import { FormattedMessage } from 'react-intl';
+import { Link } from 'react-router';
import { ButtonLink } from 'sonar-ui-common/components/controls/buttons';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
+import { BackgroundTaskTypes } from '../../../apps/background-tasks/constants';
import { IndexationProgression } from './IndexationNotification';
export interface IndexationNotificationRendererProps {
progression: IndexationProgression;
percentCompleted: number;
onDismissCompletedNotification: VoidFunction;
+ displayBackgroundTaskLink?: boolean;
}
export default function IndexationNotificationRenderer(props: IndexationNotificationRendererProps) {
- const { progression, percentCompleted } = props;
+ const { progression, percentCompleted, displayBackgroundTaskLink } = props;
const inProgress = progression === IndexationProgression.InProgress;
<span className="spacer-left">
{translateWithParameters('indexation.in_progress.details', percentCompleted)}
</span>
+ {displayBackgroundTaskLink && (
+ <span className="spacer-left">
+ <FormattedMessage
+ id="indexation.in_progress.admin_details"
+ defaultMessage={translate('indexation.in_progress.admin_details')}
+ values={{
+ link: (
+ <Link
+ to={{
+ pathname: '/admin/background_tasks',
+ query: { taskType: BackgroundTaskTypes.IssueSync }
+ }}>
+ {translate('background_tasks.page')}
+ </Link>
+ )
+ }}
+ />
+ </span>
+ )}
</>
) : (
<>
import { shallow } from 'enzyme';
import * as React from 'react';
+import { mockCurrentUser } from '../../../../helpers/testMocks';
import { IndexationNotification, IndexationProgression } from '../IndexationNotification';
import IndexationNotificationHelper from '../IndexationNotificationHelper';
import IndexationNotificationRenderer from '../IndexationNotificationRenderer';
function shallowRender(props?: Partial<IndexationNotification['props']>) {
return shallow<IndexationNotification>(
- <IndexationNotification indexationContext={{ status: { isCompleted: false } }} {...props} />
+ <IndexationNotification
+ currentUser={mockCurrentUser()}
+ indexationContext={{ status: { isCompleted: false } }}
+ {...props}
+ />
);
}
it('should render correctly', () => {
expect(shallowRender()).toMatchSnapshot('in-progress');
+ expect(shallowRender({ displayBackgroundTaskLink: true })).toMatchSnapshot('in-progress-admin');
expect(shallowRender({ progression: IndexationProgression.Completed })).toMatchSnapshot(
'completed'
);
</Alert>
</div>
`;
+
+exports[`should render correctly: in-progress-admin 1`] = `
+<div
+ className="indexation-notification-wrapper"
+>
+ <Alert
+ className="indexation-notification-banner"
+ display="banner"
+ variant="warning"
+ >
+ <div
+ className="display-flex-center"
+ >
+ <span>
+ indexation.in_progress
+ </span>
+ <i
+ className="spinner spacer-left"
+ />
+ <span
+ className="spacer-left"
+ >
+ indexation.in_progress.details.25
+ </span>
+ <span
+ className="spacer-left"
+ >
+ <FormattedMessage
+ defaultMessage="indexation.in_progress.admin_details"
+ id="indexation.in_progress.admin_details"
+ values={
+ Object {
+ "link": <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/admin/background_tasks",
+ "query": Object {
+ "taskType": "ISSUE_SYNC",
+ },
+ }
+ }
+ >
+ background_tasks.page
+ </Link>,
+ }
+ }
+ />
+ </span>
+ </div>
+ </Alert>
+</div>
+`;
CANCELED: 'CANCELED'
};
+export enum BackgroundTaskTypes {
+ Report = 'REPORT',
+ IssueSync = 'ISSUE_SYNC'
+}
+
export const ALL_TYPES = 'ALL_TYPES';
export const CURRENTS = {
#
#------------------------------------------------------------------------------
indexation.in_progress=SonarQube is reloading project data. Some projects will be unavailable until this process is complete.
-indexation.in_progress.details={0}% completed
+indexation.in_progress.details={0}% completed.
+indexation.in_progress.admin_details=See {link}.
indexation.completed=All project data has been reloaded.
#------------------------------------------------------------------------------