Skip to content

Commit

Permalink
EPMRPP-64481 Repair analytics when it turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsterGet committed Aug 5, 2021
1 parent db8fc32 commit 4a6da37
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { analyticsEnabledSelector } from 'controllers/appInfo';
import { AnalyticsWrapper } from 'components/main/analytics/AnalyticsWrapper';
import { AnalyticsWrapper, EmptyAnalyticsWrapper } from 'components/main/analytics';
import { fetchInitialDataAction, initialDataReadySelector } from 'controllers/initialData';

@connect(
Expand Down Expand Up @@ -61,13 +61,9 @@ export class InitialDataContainer extends Component {
}

render() {
const { isAnalyticsEnabled } = this.props;
const component = isAnalyticsEnabled ? (
<AnalyticsWrapper>{this.props.children}</AnalyticsWrapper>
) : (
this.props.children
);
const { isAnalyticsEnabled, isInitialDataReady, children } = this.props;
const Analytics = isAnalyticsEnabled ? AnalyticsWrapper : EmptyAnalyticsWrapper;

return this.props.isInitialDataReady ? component : <span>Loading...</span>;
return isInitialDataReady ? <Analytics>{children}</Analytics> : <span>Loading...</span>;
}
}
12 changes: 12 additions & 0 deletions app/src/components/main/analytics/EmptyAnalyticsWrapper.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PropTypes from 'prop-types';
import track from 'react-tracking';

const AnalyticsWrapper = ({ children }) => children;
AnalyticsWrapper.propTypes = {
children: PropTypes.node,
};
AnalyticsWrapper.defaultProps = {
children: null,
};

export const EmptyAnalyticsWrapper = track()(AnalyticsWrapper);
1 change: 1 addition & 0 deletions app/src/components/main/analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
*/

export { AnalyticsWrapper } from './AnalyticsWrapper';
export { EmptyAnalyticsWrapper } from './EmptyAnalyticsWrapper';
export { pageEventsMap } from './constants';
export { provideEcGA } from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { showScreenLockAction, hideScreenLockAction } from 'controllers/screenLo
import { showDefaultErrorNotification } from 'controllers/notification';
import { activeProjectSelector } from 'controllers/user';
import { fetchDashboardsAction } from 'controllers/dashboard';
import { analyticsEnabledSelector } from 'controllers/appInfo';
import { getWidgets } from 'pages/inside/dashboardItemPage/modals/common/widgets';
import { provideEcGA } from 'components/main/analytics';
import { activeDashboardIdSelector, pageSelector } from 'controllers/pages';
Expand All @@ -44,6 +45,7 @@ const cx = classNames.bind(styles);
projectId: activeProjectSelector(state),
activeDashboardId: activeDashboardIdSelector(state),
currentPage: pageSelector(state),
isAnalyticsEnabled: analyticsEnabledSelector(state),
}),
{
submitWidgetWizardForm: () => submit(WIDGET_WIZARD_FORM),
Expand All @@ -65,6 +67,7 @@ export class WidgetWizardContent extends Component {
showDefaultErrorNotification: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
showConfirmation: PropTypes.bool.isRequired,
isAnalyticsEnabled: PropTypes.bool.isRequired,
onConfirm: PropTypes.func,
eventsInfo: PropTypes.object,
tracking: PropTypes.shape({
Expand Down Expand Up @@ -97,13 +100,19 @@ export class WidgetWizardContent extends Component {
}

onClickNextStep = () => {
const { tracking, eventsInfo, formValues, submitWidgetWizardForm } = this.props;
const {
tracking,
eventsInfo,
formValues,
submitWidgetWizardForm,
isAnalyticsEnabled,
} = this.props;
tracking.trackEvent(eventsInfo.nextStep);
if (this.state.step === 1 && formValues.contentParameters.contentFields) {
tracking.trackEvent(eventsInfo.selectCriteria(formValues.contentParameters.contentFields));
}
submitWidgetWizardForm();
if (this.state.step === 0) {
if (isAnalyticsEnabled && this.state.step === 0) {
provideEcGA({
name: 'addProduct',
data: {
Expand All @@ -128,6 +137,7 @@ export class WidgetWizardContent extends Component {
eventsInfo: { addWidget },
projectId,
onConfirm,
isAnalyticsEnabled,
} = this.props;
const { selectedDashboard, ...rest } = formData;
const data = prepareWidgetDataForSubmit(this.preprocessOutputData(rest));
Expand All @@ -146,17 +156,20 @@ export class WidgetWizardContent extends Component {
...getDefaultWidgetConfig(data.widgetType),
};
onConfirm(newWidget, this.props.closeModal, selectedDashboard);
provideEcGA({
name: 'addProduct',
data: {
id,
name: data.widgetType,
category: `diagram/${data.contentParameters.widgetOptions.viewMode || 'unclassified'}`,
variant: this.props.currentPage,
},
action: 'add',
additionalData: { list: selectedDashboard.id },
});
if (isAnalyticsEnabled) {
provideEcGA({
name: 'addProduct',
data: {
id,
name: data.widgetType,
category: `diagram/${data.contentParameters.widgetOptions.viewMode ||
'unclassified'}`,
variant: this.props.currentPage,
},
action: 'add',
additionalData: { list: selectedDashboard.id },
});
}
})
.catch((err) => {
this.props.hideScreenLockAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { URLS } from 'common/urls';
import { CUMULATIVE_TREND } from 'common/constants/widgetTypes';
import { activeProjectSelector } from 'controllers/user';
import { showModalAction } from 'controllers/modal';
import { analyticsEnabledSelector } from 'controllers/appInfo';
import { SpinningPreloader } from 'components/preloaders/spinningPreloader';
import { DASHBOARD_PAGE_EVENTS } from 'components/main/analytics/events';
import { ErrorMessage } from 'components/main/errorMessage';
Expand Down Expand Up @@ -60,6 +61,7 @@ const SILENT_UPDATE_TIMEOUT_FULLSCREEN = 30000;
(state) => ({
activeProject: activeProjectSelector(state),
activeDashboardId: activeDashboardIdSelector(state),
isAnalyticsEnabled: analyticsEnabledSelector(state),
}),
{
showModalAction,
Expand All @@ -85,6 +87,7 @@ export class SimpleWidget extends Component {
}).isRequired,
dashboardOwner: PropTypes.string,
activeDashboardId: PropTypes.number.isRequired,
isAnalyticsEnabled: PropTypes.bool.isRequired,
};

static defaultProps = {
Expand Down Expand Up @@ -332,23 +335,27 @@ export class SimpleWidget extends Component {
};

showDeleteWidgetModal = () => {
this.props.tracking.trackEvent(DASHBOARD_PAGE_EVENTS.REMOVE_WIDGET);
const { tracking, isAnalyticsEnabled, onDelete } = this.props;

tracking.trackEvent(DASHBOARD_PAGE_EVENTS.REMOVE_WIDGET);
const onConfirm = () => {
const { widgetId, activeDashboardId } = this.props;
const {
widget: { id, widgetType, contentParameters },
} = this.state;
this.props.onDelete(widgetId);
provideEcGA({
name: 'addProduct',
data: {
id,
name: widgetType,
category: `diagram/${contentParameters.widgetOptions.viewMode || 'unclassified'}`,
},
action: 'remove',
additionalData: { list: activeDashboardId },
});
onDelete(widgetId);
if (isAnalyticsEnabled) {
provideEcGA({
name: 'addProduct',
data: {
id,
name: widgetType,
category: `diagram/${contentParameters.widgetOptions.viewMode || 'unclassified'}`,
},
action: 'remove',
additionalData: { list: activeDashboardId },
});
}
};
this.props.showModalAction({
id: 'deleteWidgetModal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export class FilterOptions extends Component {
} else if (type === OPTIONS.STATISTICS) {
optionName = this.statisticsOptions(entity);
} else {
optionName = intl.formatMessage(messages[entity.filteringField]);
optionName = messages[entity.filteringField]
? intl.formatMessage(messages[entity.filteringField])
: entity.filteringField;
}
switch (entity.condition) {
case CONDITION_GREATER_EQ:
Expand Down

0 comments on commit 4a6da37

Please sign in to comment.