From: Wouter Admiraal Date: Fri, 14 Dec 2018 15:25:25 +0000 (+0100) Subject: SONARCLOUD-272 Update user notifications settings page X-Git-Tag: 7.6~228 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=66e365f711bccb43faeeef6e14fa3aaf167f4136;p=sonarqube.git SONARCLOUD-272 Update user notifications settings page --- diff --git a/server/sonar-web/src/main/js/app/components/notifications/NotificationsSidebar.tsx b/server/sonar-web/src/main/js/app/components/notifications/NotificationsSidebar.tsx index f267574cde8..8eeb985837a 100644 --- a/server/sonar-web/src/main/js/app/components/notifications/NotificationsSidebar.tsx +++ b/server/sonar-web/src/main/js/app/components/notifications/NotificationsSidebar.tsx @@ -114,7 +114,7 @@ interface FeatureProps { export function Feature({ feature }: FeatureProps) { return (
-
+ + {isSonarCloud() && } + ); } diff --git a/server/sonar-web/src/main/js/apps/account/notifications/SonarCloudNotifications.tsx b/server/sonar-web/src/main/js/apps/account/notifications/SonarCloudNotifications.tsx new file mode 100644 index 00000000000..175f7233f22 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/account/notifications/SonarCloudNotifications.tsx @@ -0,0 +1,87 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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 * as React from 'react'; +import { connect } from 'react-redux'; +import Checkbox from '../../../components/controls/Checkbox'; +import { translate } from '../../../helpers/l10n'; +import { getCurrentUserSetting, Store } from '../../../store/rootReducer'; +import { setCurrentUserSetting } from '../../../store/users'; + +interface Props { + notificationsOptOut?: boolean; + setCurrentUserSetting: (setting: T.CurrentUserSetting) => void; +} + +export class SonarCloudNotifications extends React.PureComponent { + handleCheckOptOut = (checked: boolean) => { + this.props.setCurrentUserSetting({ + key: 'notifications.optOut', + value: checked ? 'false' : 'true' + }); + }; + + render() { + return ( +
+

{translate('my_profile.sonarcloud_feature_notifications.title')}

+
+ + + + + + + + + + + + +
+ +

{translate('activate')}

+
{translate('my_profile.sonarcloud_feature_notifications.description')} + +
+
+
+ ); + } +} + +const mapStateToProps = (state: Store) => { + const notificationsOptOut = getCurrentUserSetting(state, 'notifications.optOut') === 'true'; + + return { + notificationsOptOut + }; +}; + +const mapDispatchToProps = { + setCurrentUserSetting +}; + +export default connect( + mapStateToProps, + mapDispatchToProps +)(SonarCloudNotifications); diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/GlobalNotifications-test.tsx b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/GlobalNotifications-test.tsx index 7f5cb7287bd..f25506fa1a2 100644 --- a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/GlobalNotifications-test.tsx +++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/GlobalNotifications-test.tsx @@ -20,8 +20,20 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import GlobalNotifications from '../GlobalNotifications'; +import { isSonarCloud } from '../../../../helpers/system'; + +jest.mock('../../../../helpers/system', () => ({ isSonarCloud: jest.fn() })); it('should match snapshot', () => { + expect(shallowRender()).toMatchSnapshot(); +}); + +it('should show SonarCloud options if in SC context', () => { + (isSonarCloud as jest.Mock).mockImplementation(() => true); + expect(shallowRender()).toMatchSnapshot(); +}); + +function shallowRender(props = {}) { const channels = ['channel1', 'channel2']; const types = ['type1', 'type2']; const notifications = [ @@ -30,15 +42,14 @@ it('should match snapshot', () => { { channel: 'channel2', type: 'type2' } ]; - expect( - shallow( - - ) - ).toMatchSnapshot(); -}); + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/SonarCloudNotifications-test.tsx b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/SonarCloudNotifications-test.tsx new file mode 100644 index 00000000000..e67695d028d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/SonarCloudNotifications-test.tsx @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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 * as React from 'react'; +import { shallow } from 'enzyme'; +import { SonarCloudNotifications } from '../SonarCloudNotifications'; + +it('should match snapshot', () => { + expect(shallowRender()).toMatchSnapshot(); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/GlobalNotifications-test.tsx.snap b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/GlobalNotifications-test.tsx.snap index 3d21dbbdf2a..ecd10ebc9fe 100644 --- a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/GlobalNotifications-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/GlobalNotifications-test.tsx.snap @@ -1,73 +1,150 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`should match snapshot 1`] = ` -
-

- my_profile.overall_notifications.title -

-
+
- + my_profile.overall_notifications.title + +
-
- - - - - - -
- -

- notification.channel.channel1 -

-
-

- notification.channel.channel2 -

-
-
-
+ + + + + + + + +
+ +

+ notification.channel.channel1 +

+
+

+ notification.channel.channel2 +

+
+ + + +`; + +exports[`should show SonarCloud options if in SC context 1`] = ` + +
+

+ my_profile.overall_notifications.title +

+
+ + + + + + + + +
+ +

+ notification.channel.channel1 +

+
+

+ notification.channel.channel2 +

+
+
+
+ +
`; diff --git a/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/SonarCloudNotifications-test.tsx.snap b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/SonarCloudNotifications-test.tsx.snap new file mode 100644 index 00000000000..571bf1aaca8 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/account/notifications/__tests__/__snapshots__/SonarCloudNotifications-test.tsx.snap @@ -0,0 +1,47 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should match snapshot 1`] = ` +
+

+ my_profile.sonarcloud_feature_notifications.title +

+
+ + + + + + + + + + + + +
+ +

+ activate +

+
+ my_profile.sonarcloud_feature_notifications.description + + +
+
+
+`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index eae4d016b97..909ad4dc927 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -7,6 +7,7 @@ action=Action actions=Actions active=Active +activate=Activate add_verb=Add admin=Admin apply=Apply @@ -1500,6 +1501,8 @@ my_profile.password.submit=Change password my_profile.password.changed=The password has been changed! my_profile.notifications.submit=Save changes my_profile.overall_notifications.title=Overall notifications +my_profile.sonarcloud_feature_notifications.title=SonarCloud new feature notifications +my_profile.sonarcloud_feature_notifications.description=Display a notification in the header when new features are deployed my_profile.per_project_notifications.title=Notifications per project my_account.page=My Account