Remove saga in admin

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-02-28 14:15:56 +01:00
parent 8b25ad614b
commit ca93021bd0
6 changed files with 22 additions and 88 deletions

View File

@ -5,19 +5,10 @@
*/
import {
EMIT_EVENT,
GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED,
SET_APP_ERROR,
} from './constants';
export function emitEvent(event, properties) {
return {
type: EMIT_EVENT,
event,
properties,
};
}
export function getPluginsFromMarketPlaceSucceeded(plugins) {
return {
type: GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED,

View File

@ -4,7 +4,6 @@
*
*/
export const EMIT_EVENT = 'app/Admin/EMIT_EVENT';
export const GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED =
'StrapiAdmin/Admin/GET_PLUGINS_FROM_MARKETPLACE_SUCCEEDED';
export const SET_APP_ERROR = 'StrapiAdmin/Admin/SET_APP_ERROR';

View File

@ -6,6 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
import { connect } from 'react-redux';
import { createStructuredSelector } from 'reselect';
import { bindActionCreators, compose } from 'redux';
@ -39,13 +40,10 @@ import {
updatePlugin,
} from '../App/actions';
import makeSelecApp from '../App/selectors';
import injectSaga from '../../utils/injectSaga';
import injectReducer from '../../utils/injectReducer';
import { emitEvent, setAppError } from './actions';
import { setAppError } from './actions';
import makeSelectAdmin from './selectors';
import reducer from './reducer';
import saga from './saga';
import Wrapper from './Wrapper';
import Content from './Content';
@ -57,7 +55,7 @@ export class Admin extends React.Component {
};
componentDidMount() {
this.props.emitEvent('didAccessAuthenticatedAdministration');
this.emitEvent('didAccessAuthenticatedAdministration');
}
shouldComponentUpdate(prevProps) {
@ -78,6 +76,20 @@ export class Admin extends React.Component {
this.props.setAppError();
}
emitEvent = async (event, properties) => {
const {
global: { uuid },
} = this.props;
if (uuid) {
axios.post('https://analytics.strapi.io/track', {
event,
properties,
uuid,
});
}
};
hasApluginNotReady = props => {
const {
global: { plugins },
@ -133,7 +145,6 @@ export class Admin extends React.Component {
strapiVersion,
},
disableGlobalOverlayBlocker,
emitEvent,
enableGlobalOverlayBlocker,
intl: { formatMessage, locale },
updatePlugin,
@ -152,7 +163,7 @@ export class Admin extends React.Component {
return (
<GlobalContextProvider
autoReload={autoReload}
emitEvent={emitEvent}
emitEvent={this.emitEvent}
currentEnvironment={currentEnvironment}
currentLocale={locale}
disableGlobalOverlayBlocker={disableGlobalOverlayBlocker}
@ -230,7 +241,6 @@ Admin.propTypes = {
appError: PropTypes.bool,
}).isRequired,
disableGlobalOverlayBlocker: PropTypes.func.isRequired,
emitEvent: PropTypes.func.isRequired,
enableGlobalOverlayBlocker: PropTypes.func.isRequired,
global: PropTypes.shape({
autoReload: PropTypes.bool,
@ -240,6 +250,7 @@ Admin.propTypes = {
plugins: PropTypes.object,
showGlobalAppBlocker: PropTypes.bool,
strapiVersion: PropTypes.string,
uuid: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
}).isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func,
@ -259,7 +270,6 @@ export function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
disableGlobalOverlayBlocker,
emitEvent,
enableGlobalOverlayBlocker,
setAppError,
updatePlugin,
@ -270,6 +280,5 @@ export function mapDispatchToProps(dispatch) {
const withConnect = connect(mapStateToProps, mapDispatchToProps);
const withReducer = injectReducer({ key: 'admin', reducer });
const withSaga = injectSaga({ key: 'admin', saga });
export default compose(injectIntl, withReducer, withSaga, withConnect)(Admin);
export default compose(injectIntl, withReducer, withConnect)(Admin);

View File

@ -1,31 +0,0 @@
/* eslint-disable */
import { all, fork, call, put, select, takeLatest } from 'redux-saga/effects';
import { EMIT_EVENT } from './constants';
import { makeSelectUuid } from '../App/selectors';
export function* emitter(action) {
try {
const requestURL = 'https://analytics.strapi.io/track';
const uuid = yield select(makeSelectUuid());
const { event, properties } = action;
if (uuid) {
yield call(
fetch, // eslint-disable-line no-undef
requestURL,
{
method: 'POST',
body: JSON.stringify({ event, uuid, properties }),
headers: {
'Content-Type': 'application/json',
},
}
);
}
} catch (err) {}
}
// Individual exports for testing
export default function* defaultSaga() {
yield all([fork(takeLatest, EMIT_EVENT, emitter)]);
}

View File

@ -1,19 +1,7 @@
import { emitEvent, setAppError } from '../actions';
import { EMIT_EVENT, SET_APP_ERROR } from '../constants';
import { setAppError } from '../actions';
import { SET_APP_ERROR } from '../constants';
describe('<Admin /> actions', () => {
describe('EmitEvent', () => {
it('has a type EMIT_EVENT and returns the correct data', () => {
const expected = {
type: EMIT_EVENT,
event: 'test',
properties: {},
};
expect(emitEvent('test', {})).toEqual(expected);
});
});
describe('SetAppError Action', () => {
it('has a type of SET_APP_ERROR', () => {
const expected = {

View File

@ -1,22 +0,0 @@
/**
* Test sagas
*/
/* eslint-disable redux-saga/yield-effects */
/* eslint-disable redux-saga/no-unhandled-errors */
import { all, fork, takeLatest } from 'redux-saga/effects';
import defaultSaga, { emitter } from '../saga';
import { EMIT_EVENT } from '../constants';
describe('defaultSaga Saga', () => {
const defaultSagaSaga = defaultSaga();
it('should start task to watch for GET_INIT_DATA and GET_SECURED_DATA actions', () => {
const forkDescriptor = defaultSagaSaga.next().value;
expect(forkDescriptor).toEqual(
all([fork(takeLatest, EMIT_EVENT, emitter)])
);
});
});