*/
import styled from '@emotion/styled';
import React from 'react';
+import { registerListener, unregisterListener } from '../../helpers/globalMessages';
import { Message } from '../../types/globalMessages';
import { zIndexes } from '../theme';
-import { registerListener, unregisterListener } from '../utils/globalMessagesService';
import GlobalMessage from './GlobalMessage';
const MESSAGE_DISPLAY_TIME = 5000;
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { screen } from '@testing-library/react';
+import { addGlobalErrorMessage, addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { renderComponentApp } from '../../../helpers/testReactTestingUtils';
-import { addGlobalErrorMessage, addGlobalSuccessMessage } from '../../utils/globalMessagesService';
it('should display messages', () => {
jest.useFakeTimers();
import { injectIntl, WrappedComponentProps } from 'react-intl';
import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
import { getExtensionStart } from '../../../helpers/extensions';
+import { addGlobalErrorMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { getCurrentL10nBundle } from '../../../helpers/l10nBundle';
import { getBaseUrl } from '../../../helpers/system';
import { Dict, Extension as TypeExtension } from '../../../types/types';
import { CurrentUser } from '../../../types/users';
import * as theme from '../../theme';
-import { addGlobalErrorMessage } from '../../utils/globalMessagesService';
import withAppStateContext from '../app-state/withAppStateContext';
import withCurrentUserContext from '../current-user/withCurrentUserContext';
sortBranches
} from '../../../helpers/branch-like';
import { throwGlobalError } from '../../../helpers/error';
+import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import handleRequiredAuthentication from '../../../helpers/handleRequiredAuthentication';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import * as measures from '../../../helpers/measures';
getMeasureHistoryUrl,
getRulesUrl
} from '../../../helpers/urls';
-import { addGlobalSuccessMessage } from '../../utils/globalMessagesService';
import A11ySkipTarget from '../a11y/A11ySkipTarget';
import Suggestions from '../embed-docs-modal/Suggestions';
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import { MessageLevel } from '../../../types/globalMessages';
-import {
- addGlobalErrorMessage,
- addGlobalSuccessMessage,
- registerListener
-} from '../globalMessagesService';
-
-it('should work as expected', () => {
- const listener1 = jest.fn();
- registerListener(listener1);
-
- addGlobalErrorMessage('test');
-
- expect(listener1).toBeCalledWith(
- expect.objectContaining({ text: 'test', level: MessageLevel.Error })
- );
-
- listener1.mockClear();
- const listener2 = jest.fn();
- registerListener(listener2);
-
- addGlobalSuccessMessage('test');
-
- expect(listener1).toBeCalledWith(
- expect.objectContaining({ text: 'test', level: MessageLevel.Success })
- );
- expect(listener2).toBeCalledWith(
- expect.objectContaining({ text: 'test', level: MessageLevel.Success })
- );
-});
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-import { uniqueId } from 'lodash';
-import { parseError } from '../../helpers/request';
-import { Message, MessageLevel } from '../../types/globalMessages';
-
-const listeners: Array<(message: Message) => void> = [];
-
-export function registerListener(callback: (message: Message) => void) {
- listeners.push(callback);
-}
-
-export function unregisterListener(callback: (message: Message) => void) {
- const index = listeners.indexOf(callback);
-
- if (index > -1) {
- listeners.splice(index, 1);
- }
-}
-
-function addMessage(text: string, level: MessageLevel) {
- listeners.forEach(listener =>
- listener({
- id: uniqueId('global-message-'),
- level,
- text
- })
- );
-}
-
-export function addGlobalErrorMessage(text: string) {
- addMessage(text, MessageLevel.Error);
-}
-
-export function addGlobalErrorMessageFromAPI(param: any) {
- if (param instanceof Response) {
- return parseError(param).then(addGlobalErrorMessage, () => {
- /* ignore parsing errors */
- });
- }
- if (typeof param === 'string') {
- return Promise.resolve(param).then(addGlobalErrorMessage);
- }
-
- return Promise.resolve();
-}
-
-export function addGlobalSuccessMessage(text: string) {
- addMessage(text, MessageLevel.Success);
-}
import * as React from 'react';
import { deleteApplication } from '../../api/application';
import { deletePortfolio, deleteProject } from '../../api/components';
-import { addGlobalSuccessMessage } from '../../app/utils/globalMessagesService';
import { Button } from '../../components/controls/buttons';
import ConfirmButton from '../../components/controls/ConfirmButton';
import { Router, withRouter } from '../../components/hoc/withRouter';
+import { addGlobalSuccessMessage } from '../../helpers/globalMessages';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { isApplication, isPortfolioLike } from '../../types/component';
import { Component } from '../../types/types';
getGateForProject,
searchProjects
} from '../../api/quality-gates';
-import { addGlobalSuccessMessage } from '../../app/utils/globalMessagesService';
import handleRequiredAuthorization from '../../app/utils/handleRequiredAuthorization';
+import { addGlobalSuccessMessage } from '../../helpers/globalMessages';
import { translate } from '../../helpers/l10n';
import { Component, QualityGate } from '../../types/types';
import { USE_SYSTEM_DEFAULT } from './constants';
};
});
-jest.mock('../../../app/utils/globalMessagesService', () => ({
+jest.mock('../../../helpers/globalMessages', () => ({
addGlobalSuccessMessage: jest.fn()
}));
Profile,
searchQualityProfiles
} from '../../api/quality-profiles';
-import { addGlobalSuccessMessage } from '../../app/utils/globalMessagesService';
import handleRequiredAuthorization from '../../app/utils/handleRequiredAuthorization';
+import { addGlobalSuccessMessage } from '../../helpers/globalMessages';
import { translateWithParameters } from '../../helpers/l10n';
import { isDefined } from '../../helpers/types';
import { Component } from '../../types/types';
};
});
-jest.mock('../../../app/utils/globalMessagesService', () => ({
+jest.mock('../../../helpers/globalMessages', () => ({
addGlobalSuccessMessage: jest.fn()
}));
*/
import * as React from 'react';
import { bulkApplyTemplate, getPermissionTemplates } from '../../api/permissions';
-import { addGlobalErrorMessageFromAPI } from '../../app/utils/globalMessagesService';
import { ResetButtonLink, SubmitButton } from '../../components/controls/buttons';
import Modal from '../../components/controls/Modal';
import Select from '../../components/controls/Select';
import MandatoryFieldMarker from '../../components/ui/MandatoryFieldMarker';
import MandatoryFieldsExplanation from '../../components/ui/MandatoryFieldsExplanation';
import { toNotSoISOString } from '../../helpers/dates';
+import { addGlobalErrorMessageFromAPI } from '../../helpers/globalMessages';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { PermissionTemplate } from '../../types/types';
import * as React from 'react';
import { Helmet } from 'react-helmet-async';
import { fetchQualityGate } from '../../../api/quality-gates';
-import { addGlobalSuccessMessage } from '../../../app/utils/globalMessagesService';
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
+import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { Condition, QualityGate } from '../../../types/types';
import { addCondition, checkIfDefault, deleteCondition, replaceCondition } from '../utils';
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import {
- addGlobalErrorMessage,
- addGlobalSuccessMessage
-} from '../../../app/utils/globalMessagesService';
import { Button } from '../../../components/controls/buttons';
import { DropdownOverlay } from '../../../components/controls/Dropdown';
import Toggler from '../../../components/controls/Toggler';
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
+import { addGlobalErrorMessage, addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { openHotspot, probeSonarLintServers } from '../../../helpers/sonarlint';
import { Ide } from '../../../types/sonarlint';
import * as React from 'react';
import { assignSecurityHotspot } from '../../../../api/security-hotspots';
import withCurrentUserContext from '../../../../app/components/current-user/withCurrentUserContext';
-import { addGlobalSuccessMessage } from '../../../../app/utils/globalMessagesService';
+import { addGlobalSuccessMessage } from '../../../../helpers/globalMessages';
import { translate, translateWithParameters } from '../../../../helpers/l10n';
import { Hotspot, HotspotResolution, HotspotStatus } from '../../../../types/security-hotspots';
import { CurrentUser, isLoggedIn, UserActive } from '../../../../types/users';
import { shallow } from 'enzyme';
import * as React from 'react';
import { assignSecurityHotspot } from '../../../../../api/security-hotspots';
-import { addGlobalSuccessMessage } from '../../../../../app/utils/globalMessagesService';
+import { addGlobalSuccessMessage } from '../../../../../helpers/globalMessages';
import { mockHotspot } from '../../../../../helpers/mocks/security-hotspots';
import { mockCurrentUser, mockUser } from '../../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../../helpers/testUtils';
assignSecurityHotspot: jest.fn()
}));
-jest.mock('../../../../../app/utils/globalMessagesService', () => ({
+jest.mock('../../../../../helpers/globalMessages', () => ({
addGlobalSuccessMessage: jest.fn()
}));
import * as React from 'react';
import { logIn } from '../../../api/auth';
import { getIdentityProviders } from '../../../api/users';
-import { addGlobalErrorMessage } from '../../../app/utils/globalMessagesService';
+import { addGlobalErrorMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { getReturnUrl } from '../../../helpers/urls';
import { IdentityProvider } from '../../../types/types';
import * as React from 'react';
import { logOut } from '../../../api/auth';
import RecentHistory from '../../../app/components/RecentHistory';
-import { addGlobalErrorMessage } from '../../../app/utils/globalMessagesService';
+import { addGlobalErrorMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { getBaseUrl } from '../../../helpers/system';
import { shallow } from 'enzyme';
import * as React from 'react';
import { logOut } from '../../../../api/auth';
-import { addGlobalErrorMessage } from '../../../../app/utils/globalMessagesService';
+import { addGlobalErrorMessage } from '../../../../helpers/globalMessages';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import Logout from '../Logout';
logOut: jest.fn().mockResolvedValue(true)
}));
-jest.mock('../../../../app/utils/globalMessagesService', () => ({
+jest.mock('../../../../helpers/globalMessages', () => ({
addGlobalErrorMessage: jest.fn()
}));
*/
import * as React from 'react';
import { changePassword } from '../../../api/users';
-import { addGlobalSuccessMessage } from '../../../app/utils/globalMessagesService';
import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons';
import Modal from '../../../components/controls/Modal';
import { Alert } from '../../../components/ui/Alert';
import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker';
import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation';
import { throwGlobalError } from '../../../helpers/error';
+import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { translate } from '../../../helpers/l10n';
import { parseError } from '../../../helpers/request';
import { User } from '../../../types/users';
} from '../../api/component-report';
import withAppStateContext from '../../app/components/app-state/withAppStateContext';
import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext';
-import { addGlobalSuccessMessage } from '../../app/utils/globalMessagesService';
+import { addGlobalSuccessMessage } from '../../helpers/globalMessages';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { AppState } from '../../types/appstate';
import { Branch } from '../../types/branch-like';
import { omit } from 'lodash';
import * as React from 'react';
import ReactSelect, {
+ components,
GroupTypeBase,
IndicatorProps,
NamedProps,
+ OptionProps,
OptionTypeBase,
StylesConfig
} from 'react-select';
return <div {...props.innerProps}>×</div>;
}
+export type SelectOptionProps<T, IsMulti extends boolean> = OptionProps<T, IsMulti>;
+export const SelectOption = components.Option;
+
/* Keeping it as a class to simplify a dozen tests */
export default class Select<
Option,
subscribeToEmailReport,
unsubscribeFromEmailReport
} from '../../../api/component-report';
-import { addGlobalSuccessMessage } from '../../../app/utils/globalMessagesService';
+import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { mockBranch } from '../../../helpers/mocks/branch-like';
import { mockComponent } from '../../../helpers/mocks/component';
import { mockComponentReportStatus } from '../../../helpers/mocks/component-report';
getBaseUrl: jest.fn().mockReturnValue('baseUrl')
}));
-jest.mock('../../../app/utils/globalMessagesService', () => ({
+jest.mock('../../../helpers/globalMessages', () => ({
addGlobalSuccessMessage: jest.fn()
}));
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { addGlobalErrorMessage } from '../../app/utils/globalMessagesService';
import { throwGlobalError } from '../error';
+import { addGlobalErrorMessage } from '../globalMessages';
-jest.mock('../../app/utils/globalMessagesService', () => ({
+jest.mock('../../helpers/globalMessages', () => ({
addGlobalErrorMessage: jest.fn()
}));
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { MessageLevel } from '../../types/globalMessages';
+import {
+ addGlobalErrorMessage,
+ addGlobalSuccessMessage,
+ registerListener
+} from '../globalMessages';
+
+it('should work as expected', () => {
+ const listener1 = jest.fn();
+ registerListener(listener1);
+
+ addGlobalErrorMessage('test');
+
+ expect(listener1).toBeCalledWith(
+ expect.objectContaining({ text: 'test', level: MessageLevel.Error })
+ );
+
+ listener1.mockClear();
+ const listener2 = jest.fn();
+ registerListener(listener2);
+
+ addGlobalSuccessMessage('test');
+
+ expect(listener1).toBeCalledWith(
+ expect.objectContaining({ text: 'test', level: MessageLevel.Success })
+ );
+ expect(listener2).toBeCalledWith(
+ expect.objectContaining({ text: 'test', level: MessageLevel.Success })
+ );
+});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { addGlobalErrorMessage } from '../app/utils/globalMessagesService';
+import { addGlobalErrorMessage } from './globalMessages';
import { parseError } from './request';
export function throwGlobalError(param: Response | any): Promise<Response | any> {
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+import { uniqueId } from 'lodash';
+import { Message, MessageLevel } from '../types/globalMessages';
+import { parseError } from './request';
+
+const listeners: Array<(message: Message) => void> = [];
+
+export function registerListener(callback: (message: Message) => void) {
+ listeners.push(callback);
+}
+
+export function unregisterListener(callback: (message: Message) => void) {
+ const index = listeners.indexOf(callback);
+
+ if (index > -1) {
+ listeners.splice(index, 1);
+ }
+}
+
+function addMessage(text: string, level: MessageLevel) {
+ listeners.forEach(listener =>
+ listener({
+ id: uniqueId('global-message-'),
+ level,
+ text
+ })
+ );
+}
+
+export function addGlobalErrorMessage(text: string) {
+ addMessage(text, MessageLevel.Error);
+}
+
+export function addGlobalErrorMessageFromAPI(param: Response | string) {
+ if (param instanceof Response) {
+ return parseError(param).then(addGlobalErrorMessage, () => {
+ /* ignore parsing errors */
+ });
+ }
+ if (typeof param === 'string') {
+ return Promise.resolve(param).then(addGlobalErrorMessage);
+ }
+
+ return Promise.resolve();
+}
+
+export function addGlobalSuccessMessage(text: string) {
+ addMessage(text, MessageLevel.Success);
+}
registerExtension: (key: string, start: ExtensionStartMethod, providesCSSFile?: boolean) => void;
setWebAnalyticsPageChangeHandler: (pageHandler: (pathname: string) => void) => void;
+ t: (...keys: string[]) => string;
+ tp: (messageKey: string, ...parameters: Array<string | number>) => string;
}
import { Location, Router } from '../components/hoc/withRouter';
import { AppState } from './appstate';
import { L10nBundle } from './l10nBundle';
-import { Dict } from './types';
+import { Component, Dict } from './types';
import { CurrentUser } from './users';
export enum AdminPageExtension {
export interface ExtensionStartMethodParameter {
appState: AppState;
el: HTMLElement | undefined | null;
+ component?: Component;
currentUser: CurrentUser;
intl: IntlShape;
location: Location;