Skip to content

Commit 1556b70

Browse files
author
Joel Griffith
authored
[Telemetry] Show opt-in changes for OSS users (#50831) (#50941)
* WIP: Notice banner for OSS folks * Add telemetryNotifyUserAboutOptInDefault to injected vars * add userHasSeenNotice check * More WIP on banner notice component * Text changes on screens * make userHasSeenNotice flag work * Finalzed splash text + checking new flag * Consolidating banner calls and saving status of opt-in notice * Conditionally remove the banner and add some code docs * Fixing prior welcome tests * api integration test for user has seen opt in * change post method to put in ui * unit test for get_telemetry_notify_user_about_optin_default * Ignore TS woes * Adding new tests and snapshots for opt-in banner component * Notice banner test * Translation miss * More opt-in tests * increase types usage * roll back core server api change * update snapshot * Prop name change + snapshot updates
1 parent ac37fff commit 1556b70

25 files changed

+686
-19
lines changed

src/legacy/core_plugins/kibana/public/home/components/__snapshots__/welcome.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/legacy/core_plugins/kibana/public/home/components/home.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ export class Home extends Component {
4747
constructor(props) {
4848
super(props);
4949

50-
const isWelcomeEnabled = !(chrome.getInjected('disableWelcomeScreen') || props.localStorage.getItem(KEY_ENABLE_WELCOME) === 'false');
51-
const showTelemetryDisclaimer = chrome.getInjected('allowChangingOptInStatus');
50+
const isWelcomeEnabled = !(
51+
chrome.getInjected('disableWelcomeScreen') ||
52+
props.localStorage.getItem(KEY_ENABLE_WELCOME) === 'false'
53+
);
54+
const showTelemetryDisclaimer = chrome.getInjected('telemetryNotifyUserAboutOptInDefault');
55+
5256
this.state = {
5357
// If welcome is enabled, we wait for loading to complete
5458
// before rendering. This prevents an annoying flickering
@@ -227,6 +231,7 @@ export class Home extends Component {
227231
onSkip={this.skipWelcome}
228232
urlBasePath={this.props.urlBasePath}
229233
showTelemetryDisclaimer={this.state.showTelemetryDisclaimer}
234+
onOptInSeen={this.props.onOptInSeen}
230235
/>
231236
);
232237
}
@@ -265,4 +270,5 @@ Home.propTypes = {
265270
localStorage: PropTypes.object.isRequired,
266271
urlBasePath: PropTypes.string.isRequired,
267272
mlEnabled: PropTypes.bool.isRequired,
273+
onOptInSeen: PropTypes.func.isRequired,
268274
};

src/legacy/core_plugins/kibana/public/home/components/home_app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import {
3030
} from 'react-router-dom';
3131
import { getTutorial } from '../load_tutorials';
3232
import { replaceTemplateStrings } from './tutorial/replace_template_strings';
33-
import { shouldShowTelemetryOptIn } from '../kibana_services';
33+
import { telemetryOptInProvider } from '../kibana_services';
3434
import chrome from 'ui/chrome';
3535

3636
export function HomeApp({ directories }) {
3737
const isCloudEnabled = chrome.getInjected('isCloudEnabled', false);
3838
const apmUiEnabled = chrome.getInjected('apmUiEnabled', true);
3939
const mlEnabled = chrome.getInjected('mlEnabled', false);
40+
const { setOptInNoticeSeen } = telemetryOptInProvider;
4041
const savedObjectsClient = chrome.getSavedObjectsClient();
4142

4243
const renderTutorialDirectory = (props) => {
@@ -92,7 +93,7 @@ export function HomeApp({ directories }) {
9293
find={savedObjectsClient.find}
9394
localStorage={localStorage}
9495
urlBasePath={chrome.getBasePath()}
95-
shouldShowTelemetryOptIn={shouldShowTelemetryOptIn}
96+
onOptInSeen={setOptInNoticeSeen}
9697
/>
9798
</Route>
9899
</Switch>

src/legacy/core_plugins/kibana/public/home/components/welcome.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jest.mock('../kibana_services', () => ({
3333
test('should render a Welcome screen with the telemetry disclaimer', () => {
3434
const component = shallow(
3535
// @ts-ignore
36-
<Welcome urlBase="/" onSkip={() => {}} showTelemetryDisclaimer={true} />
36+
<Welcome urlBase="/" onSkip={() => {}} showTelemetryDisclaimer={true} onOptInSeen={() => {}} />
3737
);
3838

3939
expect(component).toMatchSnapshot();
@@ -43,8 +43,19 @@ test('should render a Welcome screen with no telemetry disclaimer', () => {
4343
// @ts-ignore
4444
const component = shallow(
4545
// @ts-ignore
46-
<Welcome urlBase="/" onSkip={() => {}} showTelemetryDisclaimer={false} />
46+
<Welcome urlBase="/" onSkip={() => {}} showTelemetryDisclaimer={false} onOptInSeen={() => {}} />
4747
);
4848

4949
expect(component).toMatchSnapshot();
5050
});
51+
52+
test('fires opt-in seen when mounted', () => {
53+
const seen = jest.fn();
54+
55+
shallow(
56+
// @ts-ignore
57+
<Welcome urlBase="/" onSkip={() => {}} showTelemetryDisclaimer={true} onOptInSeen={seen} />
58+
);
59+
60+
expect(seen).toHaveBeenCalled();
61+
});

src/legacy/core_plugins/kibana/public/home/components/welcome.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { trackUiMetric, METRIC_TYPE } from '../kibana_services';
4747
interface Props {
4848
urlBasePath: string;
4949
onSkip: () => void;
50+
onOptInSeen: () => any;
5051
showTelemetryDisclaimer: boolean;
5152
}
5253

@@ -77,6 +78,7 @@ export class Welcome extends React.Component<Props> {
7778

7879
componentDidMount() {
7980
trackUiMetric(METRIC_TYPE.LOADED, 'welcomeScreenMount');
81+
this.props.onOptInSeen();
8082
document.addEventListener('keydown', this.hideOnEsc);
8183
}
8284

@@ -134,17 +136,17 @@ export class Welcome extends React.Component<Props> {
134136
>
135137
<FormattedMessage
136138
id="kbn.home.dataManagementDisclaimerPrivacyLink"
137-
defaultMessage="Privacy Policy."
139+
defaultMessage="Privacy Statement."
138140
/>
139141
</EuiLink>
140142
<FormattedMessage
141143
id="kbn.home.dataManagementDisableCollection"
142-
defaultMessage=" To disable collection, "
144+
defaultMessage=" To stop collection, "
143145
/>
144146
<EuiLink href="#/management/kibana/settings">
145147
<FormattedMessage
146148
id="kbn.home.dataManagementDisableCollectionLink"
147-
defaultMessage="click here."
149+
defaultMessage="disable usage data here."
148150
/>
149151
</EuiLink>
150152
</EuiTextColor>

src/legacy/core_plugins/telemetry/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const telemetry = (kibana: any) => {
112112
telemetryOptInStatusUrl: config.get('telemetry.optInStatusUrl'),
113113
allowChangingOptInStatus: config.get('telemetry.allowChangingOptInStatus'),
114114
telemetrySendUsageFrom: config.get('telemetry.sendUsageFrom'),
115+
telemetryNotifyUserAboutOptInDefault: false,
115116
};
116117
},
117118
hacks: ['plugins/telemetry/hacks/telemetry_init', 'plugins/telemetry/hacks/telemetry_opt_in'],

src/legacy/core_plugins/telemetry/mappings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"lastVersionChecked": {
1515
"ignore_above": 256,
1616
"type": "keyword"
17+
},
18+
"userHasSeenNotice": {
19+
"type": "boolean"
1720
}
1821
}
1922
}

src/legacy/core_plugins/telemetry/public/components/__snapshots__/opted_in_notice_banner.test.tsx.snap

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import React from 'react';
20+
import { EuiButton } from '@elastic/eui';
21+
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
22+
import { OptedInBanner } from './opted_in_notice_banner';
23+
24+
describe('OptInDetailsComponent', () => {
25+
it('renders as expected', () => {
26+
expect(shallowWithIntl(<OptedInBanner onSeenBanner={() => {}} />)).toMatchSnapshot();
27+
});
28+
29+
it('fires the "onSeenBanner" prop when a link is clicked', () => {
30+
const onLinkClick = jest.fn();
31+
const component = shallowWithIntl(<OptedInBanner onSeenBanner={onLinkClick} />);
32+
33+
const button = component.findWhere(n => n.type() === EuiButton);
34+
35+
if (!button) {
36+
throw new Error(`Couldn't find any buttons in opt-in notice`);
37+
}
38+
39+
button.simulate('click');
40+
41+
expect(onLinkClick).toHaveBeenCalled();
42+
});
43+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/* eslint @elastic/eui/href-or-on-click:0 */
21+
22+
import * as React from 'react';
23+
import { EuiButton, EuiLink, EuiCallOut, EuiSpacer } from '@elastic/eui';
24+
import { FormattedMessage } from '@kbn/i18n/react';
25+
26+
interface Props {
27+
onSeenBanner: () => any;
28+
}
29+
30+
/**
31+
* React component for displaying the Telemetry opt-in notice.
32+
*/
33+
export class OptedInBanner extends React.PureComponent<Props> {
34+
onLinkClick = () => {
35+
this.props.onSeenBanner();
36+
return;
37+
};
38+
39+
render() {
40+
return (
41+
<EuiCallOut title="Help us improve the Elastic Stack">
42+
<FormattedMessage
43+
id="telemetry.telemetryOptedInNoticeDescription"
44+
defaultMessage="To learn about how usage data helps us manage and improve our products and services, see our {privacyStatementLink}. To stop collection, {disableLink}."
45+
values={{
46+
privacyStatementLink: (
47+
<EuiLink
48+
onClick={this.onLinkClick}
49+
href="https://www.elastic.co/legal/privacy-statement"
50+
target="_blank"
51+
rel="noopener"
52+
>
53+
<FormattedMessage
54+
id="telemetry.telemetryOptedInPrivacyStatement"
55+
defaultMessage="Privacy Statement"
56+
/>
57+
</EuiLink>
58+
),
59+
disableLink: (
60+
<EuiLink href="#/management/kibana/settings" onClick={this.onLinkClick}>
61+
<FormattedMessage
62+
id="telemetry.telemetryOptedInDisableUsage"
63+
defaultMessage="disable usage data here"
64+
/>
65+
</EuiLink>
66+
),
67+
}}
68+
/>
69+
<EuiSpacer size="s" />
70+
<EuiButton size="s" onClick={this.props.onSeenBanner}>
71+
<FormattedMessage
72+
id="telemetry.telemetryOptedInDismissMessage"
73+
defaultMessage="Dismiss"
74+
/>
75+
</EuiButton>
76+
</EuiCallOut>
77+
);
78+
}
79+
}

0 commit comments

Comments
 (0)