Permalink
Browse files

Remove stats tracking code (#2278)

  • Loading branch information...
nylen committed Aug 10, 2017
1 parent 0dbc2c1 commit a6d1761159b1dec7788dba785bce502e27dceb47
View
@@ -4,11 +4,6 @@
import { parse as hpqParse } from 'hpq';
import { mapValues, reduce, pickBy } from 'lodash';
/**
* WordPress dependencies
*/
import { bumpStat } from '@wordpress/utils';
/**
* Internal dependencies
*/
@@ -168,7 +163,6 @@ export function createBlockWithFallback( name, rawContent, attributes ) {
// Convert 'core/text' blocks in existing content to the new
// 'core/paragraph'.
if ( name === 'core/text' ) {
bumpStat( 'block_auto_convert', 'core-text-to-paragraph' );
name = 'core/paragraph';
}
View
@@ -3,6 +3,7 @@ export { default as Button } from './button';
export { default as ClipboardButton } from './clipboard-button';
export { default as Dashicon } from './dashicon';
export { default as DropZone } from './drop-zone';
export { default as DropdownMenu } from './dropdown-menu';
export { default as ExternalLink } from './external-link';
export { default as FormFileUpload } from './form-file-upload';
export { default as FormToggle } from './form-toggle';
@@ -12,16 +13,15 @@ export { default as KeyboardShortcuts } from './keyboard-shortcuts';
export { default as Notice } from './notice';
export { default as NoticeList } from './notice/list';
export { default as Panel } from './panel';
export { default as PanelHeader } from './panel/header';
export { default as PanelBody } from './panel/body';
export { default as PanelHeader } from './panel/header';
export { default as PanelRow } from './panel/row';
export { default as Placeholder } from './placeholder';
export { default as Popover } from './popover';
export { default as ResponsiveWrapper } from './responsive-wrapper';
export { default as SandBox } from './sandbox';
export { default as Spinner } from './spinner';
export { default as Toolbar } from './toolbar';
export { default as DropdownMenu } from './dropdown-menu';
export { default as Popover } from './popover';
// Higher-Order Components
export { default as withFocusReturn } from './higher-order/with-focus-return';
@@ -1,110 +0,0 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';
import clickOutside from 'react-click-outside';
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Button, Popover } from '@wordpress/components';
import { bumpStat } from '@wordpress/utils';
/**
* Internal dependencies
*/
import './style.scss';
import { removeNotice } from '../actions';
export const TRACKING_PROMPT_NOTICE_ID = 'notice:enable-tracking-prompt';
export class EnableTrackingPrompt extends Component {
constructor() {
super();
this.state = {
showInfoPopover: false,
};
this.dismissTrackingPrompt = this.dismissTrackingPrompt.bind( this );
this.toggleInfoPopover = this.toggleInfoPopover.bind( this );
this.handleClickOutside = this.handleClickOutside.bind( this );
}
dismissTrackingPrompt( enableTracking ) {
window.setUserSetting(
'gutenberg_tracking',
enableTracking ? 'on' : 'off'
);
if ( enableTracking ) {
bumpStat( 'tracking', 'opt-in' );
}
this.props.removeNotice( TRACKING_PROMPT_NOTICE_ID );
}
toggleInfoPopover( event ) {
event.stopPropagation();
this.setState( {
showInfoPopover: ! this.state.showInfoPopover,
} );
}
handleClickOutside() {
this.setState( {
showInfoPopover: false,
} );
}
render() {
return (
// Ignore reason: This event handler exists only to catch click
// events in the notice but outside the "More info" popover.
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/onclick-has-role
<div
className="enable-tracking-prompt"
onClick={ this.handleClickOutside }
>
<p className="enable-tracking-prompt__message">
{ __( 'Can Gutenberg collect data about your usage of the editor?' ) }
</p>
<div className="enable-tracking-prompt__buttons">
<Button
isPrimary
isSmall
onClick={ () => this.dismissTrackingPrompt( true ) }
>
{ __( 'Yes' ) }
</Button>
<Button
isSecondary
isSmall
onClick={ () => this.dismissTrackingPrompt( false ) }
>
{ __( 'No' ) }
</Button>
<span className="enable-tracking-prompt__more-info">
<Button
onClick={ this.toggleInfoPopover }
aria-expanded={ this.state.showInfoPopover }
>
{ __( 'More info' ) }
</Button>
{ this.state.showInfoPopover && (
<Popover
position="bottom right"
className="enable-tracking-prompt__clarification"
>
{ __( 'Usage data is completely anonymous, does not include your post content, and will only be used to improve the editor.' ) }
</Popover>
) }
</span>
</div>
</div>
);
}
}
export default connect(
undefined,
{ removeNotice }
)( clickOutside( EnableTrackingPrompt ) );
@@ -1,40 +0,0 @@
.enable-tracking-prompt {
.enable-tracking-prompt__message {
font-weight: bold;
}
.enable-tracking-prompt__buttons {
margin: 0.5em 0; // matches `.notice p` from core
.button {
margin-right: 6px;
}
.enable-tracking-prompt__more-info {
position: relative; // for popover
.components-button {
// Match selected `.button-small` styles from core
display: inline-block;
height: 24px;
line-height: 22px;
border-radius: 2px;
border: 1px solid transparent;
cursor: pointer;
&:hover, &:focus {
color: $blue-wordpress-700;
}
&:focus {
border-color: #5b9dd9;
box-shadow: 0 0 3px rgba( 0, 115, 170, .8 );
}
}
}
}
.enable-tracking-prompt__clarification {
text-align: left;
.components-popover__content {
padding: 6px;
}
}
}
@@ -1,119 +0,0 @@
/**
* External dependencies
*/
import { mount } from 'enzyme';
import clickOutside from 'react-click-outside';
/**
* Internal dependencies
*/
import {
EnableTrackingPrompt,
TRACKING_PROMPT_NOTICE_ID,
} from '../';
describe( 'EnableTrackingPrompt', () => {
const originalSetUserSetting = window.setUserSetting;
const originalDocumentAddEventListener = document.addEventListener;
let eventMap = {};
let removeNotice;
beforeEach( () => {
window.setUserSetting = jest.fn();
document.addEventListener = jest.fn( ( event, cb ) => {
eventMap[ event ] = cb;
} );
removeNotice = jest.fn();
} );
afterEach( () => {
window.setUserSetting = originalSetUserSetting;
document.addEventListener = originalDocumentAddEventListener;
eventMap = {};
} );
it( 'should render a prompt with Yes, No, and More info buttons', () => {
const prompt = mount(
<EnableTrackingPrompt />
);
const buttons = prompt.find( 'Button' );
expect( buttons.length ).toBe( 3 );
expect( buttons.at( 0 ).text() ).toBe( 'Yes' );
expect( buttons.at( 1 ).text() ).toBe( 'No' );
expect( buttons.at( 2 ).text() ).toBe( 'More info' );
expect( window.setUserSetting )
.not.toHaveBeenCalled();
expect( removeNotice )
.not.toHaveBeenCalled();
} );
it( 'should enable tracking when clicking Yes', () => {
const prompt = mount(
<EnableTrackingPrompt removeNotice={ removeNotice } />
);
const buttonYes = prompt.find( 'Button' )
.filterWhere( node => node.text() === 'Yes' );
buttonYes.simulate( 'click' );
expect( window.setUserSetting )
.toHaveBeenCalledWith( 'gutenberg_tracking', 'on' );
expect( removeNotice )
.toHaveBeenCalledWith( TRACKING_PROMPT_NOTICE_ID );
} );
it( 'should disable tracking when clicking No', () => {
const prompt = mount(
<EnableTrackingPrompt removeNotice={ removeNotice } />
);
const buttonNo = prompt.find( 'Button' )
.filterWhere( node => node.text() === 'No' );
buttonNo.simulate( 'click' );
expect( window.setUserSetting )
.toHaveBeenCalledWith( 'gutenberg_tracking', 'off' );
expect( removeNotice )
.toHaveBeenCalledWith( TRACKING_PROMPT_NOTICE_ID );
} );
it( 'should show and hide a popover when clicking More info', () => {
const EnableTrackingPromptWrapped = clickOutside( EnableTrackingPrompt );
const prompt = mount(
<EnableTrackingPromptWrapped removeNotice={ removeNotice } />
);
expect( prompt.find( 'Popover' ).length ).toBe( 0 );
const buttonMoreInfo = prompt.find( 'Button' )
.filterWhere( node => node.text() === 'More info' );
// Click the "More info" button to show the info popover
buttonMoreInfo.simulate( 'click' );
expect( prompt.find( 'Popover' ).length ).toBe( 1 );
// Click the "More info" button to hide the info popover
buttonMoreInfo.simulate( 'click' );
expect( prompt.find( 'Popover' ).length ).toBe( 0 );
// Click the "More info" button to show the info popover
buttonMoreInfo.simulate( 'click' );
expect( prompt.find( 'Popover' ).length ).toBe( 1 );
// Click inside the prompt to hide the info popover
prompt.simulate( 'click' );
expect( prompt.find( 'Popover' ).length ).toBe( 0 );
// Click the "More info" button to show the info popover
buttonMoreInfo.simulate( 'click' );
expect( prompt.find( 'Popover' ).length ).toBe( 1 );
// Click outside the prompt to hide the info popover
eventMap.click( { target: document.body } );
expect( prompt.find( 'Popover' ).length ).toBe( 0 );
expect( window.setUserSetting )
.not.toHaveBeenCalled();
expect( removeNotice )
.not.toHaveBeenCalled();
} );
} );
View
@@ -20,8 +20,7 @@ import { settings } from '@wordpress/date';
import './assets/stylesheets/main.scss';
import Layout from './layout';
import { createReduxStore } from './state';
import { undo, createInfoNotice } from './actions';
import EnableTrackingPrompt, { TRACKING_PROMPT_NOTICE_ID } from './enable-tracking-prompt';
import { undo } from './actions';
import EditorSettingsProvider from './settings/provider';
/**
@@ -96,13 +95,6 @@ export function createEditorInstance( id, post, userSettings ) {
settings: editorSettings,
} );
if ( window.getUserSetting( 'gutenberg_tracking' ) === '' ) {
store.dispatch( createInfoNotice( <EnableTrackingPrompt />, {
id: TRACKING_PROMPT_NOTICE_ID,
isDismissible: false, // This notice has its own dismiss logic.
} ) );
}
preparePostState( store, post );
render(
View
@@ -10,7 +10,6 @@ import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { IconButton } from '@wordpress/components';
import { createBlock } from '@wordpress/blocks';
import { bumpStat } from '@wordpress/utils';
/**
* Internal dependencies
@@ -58,13 +57,14 @@ class Inserter extends Component {
insertBlock( name ) {
if ( name ) {
const { insertionPoint, onInsertBlock } = this.props;
const {
insertionPoint,
onInsertBlock,
} = this.props;
onInsertBlock(
name,
insertionPoint
);
bumpStat( 'add_block_inserter', name.replace( /\//g, '__' ) );
bumpStat( 'add_block_total', name.replace( /\//g, '__' ) );
}
this.close();
@@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { serialize, getDefaultBlock, createBlock } from '@wordpress/blocks';
import { IconButton } from '@wordpress/components';
import { keycodes, bumpStat } from '@wordpress/utils';
import { keycodes } from '@wordpress/utils';
/**
* Internal dependencies
@@ -201,8 +201,6 @@ class VisualEditorBlockList extends Component {
insertBlock( name ) {
const newBlock = createBlock( name );
this.props.onInsertBlock( newBlock );
bumpStat( 'add_block_quick', name.replace( /\//g, '__' ) );
bumpStat( 'add_block_total', name.replace( /\//g, '__' ) );
}
toggleContinueWritingControls( showContinueWritingControls ) {
Oops, something went wrong.

0 comments on commit a6d1761

Please sign in to comment.