Exemple #1
0
const ImporterStore = createReducerStore( function( state, payload ) {
	let { action } = payload,
		newState;

	switch ( action.type ) {
		case IMPORTS_STORE_RESET:
			// this is here to enable
			// unit-testing the store
			newState = initialState;
			break;

		case IMPORTS_FETCH:
			newState = state.setIn( [ 'api', 'isFetching' ], true );
			break;

		case IMPORTS_FETCH_FAILED:
			newState = state
				.setIn( [ 'api', 'isFetching' ], false )
				.updateIn( [ 'api', 'retryCount' ], increment );
			break;

		case IMPORTS_FETCH_COMPLETED:
			newState = state
				.setIn( [ 'api', 'isFetching' ], false )
				.setIn( [ 'api', 'isHydrated' ], true )
				.setIn( [ 'api', 'retryCount' ], 0 );
			break;

		case IMPORTS_IMPORT_CANCEL:
		case IMPORTS_IMPORT_RESET:
			// Remove the specified importer from the list of current importers
			newState = state.update( 'importers', importers => {
				return importers.filterNot( importer => importer.get( 'importerId' ) === action.importerId );
			} );
			break;

		case IMPORTS_UPLOAD_FAILED:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.UPLOAD_FAILURE )
				.setIn( [ 'importers', action.importerId, 'errorData' ], { type: 'uploadError', description: action.error } );
			break;

		case IMPORTS_UPLOAD_COMPLETED:
			newState = state
				.deleteIn( [ 'importers' ], action.importerId )
				.setIn( [ 'importers', action.importerStatus.importerId ], Immutable.fromJS( action.importerStatus ) );
			break;

		case IMPORTS_AUTHORS_START_MAPPING:
			newState = state.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.MAP_AUTHORS );
			break;

		case IMPORTS_AUTHORS_SET_MAPPING:
			newState = state.updateIn( [ 'importers', action.importerId, 'customData', 'sourceAuthors' ], authors => (
				authors.map( author => {
					if ( action.sourceAuthor.id !== author.get( 'id' ) ) {
						return author;
					}

					return author.set( 'mappedTo', action.targetAuthor );
				} )
			) );
			break;

		case IMPORTS_IMPORT_RECEIVE:
			newState = state.setIn( [ 'api', 'isHydrated' ], true );

			if ( newState.getIn( [ 'importerLocks', action.importerStatus.importerId ], false ) ) {
				break;
			}

			if ( action.importerStatus.importerState === appStates.DEFUNCT ) {
				newState = newState
					.deleteIn( [ 'importers', action.importerStatus.importerId ] );
				break;
			}

			newState = newState
				.setIn( [ 'importers', action.importerStatus.importerId ], Immutable.fromJS( action.importerStatus ) )
				.update( 'importers', importers => importers.filterNot( shouldRemove ) );
			break;

		case IMPORTS_UPLOAD_SET_PROGRESS:
			newState = state.setIn( [ 'importers', action.importerId, 'percentComplete' ],
				action.uploadLoaded / ( action.uploadTotal + Number.EPSILON ) * 100
			);
			break;

		case IMPORTS_IMPORT_START:
			const newImporter = Immutable.fromJS( {
				importerId: action.importerId,
				type: action.importerType,
				importerState: appStates.READY_FOR_UPLOAD,
				site: { ID: action.siteId }
			} );

			newState = state
				.update( 'count', count => count + 1 )
				.setIn( [ 'importers', action.importerId ], newImporter );
			break;

		case IMPORTS_START_IMPORTING:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.IMPORTING );
			break;

		case IMPORTS_UPLOAD_START:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.UPLOADING )
				.setIn( [ 'importers', action.importerId, 'filename' ], action.filename );
			break;

		default:
			newState = state;
			break;
	}

	newState = adjustImporterLock( newState, payload );

	return newState;
}, initialState );
Exemple #2
0
	goToLogin();
}

const AuthStore = createReducerStore( function( state, payload ) {
	let stateChanges;
	const { action } = payload;

	switch ( action.type ) {
		case ActionTypes.AUTH_RESET:
			stateChanges = initialState;
			break;
		case ActionTypes.AUTH_LOGIN:
			stateChanges = { inProgress: true, errorLevel: false, errorMessage: false };
			break;
		case ActionTypes.RECEIVE_AUTH_LOGIN:
			if ( action.error ) {
				stateChanges = handleAuthError( action.error, action.data );
			} else {
				handleLogin( action.data );
			}
			break;
	}

	if ( stateChanges ) {
		return Object.assign( {}, state, stateChanges );
	}

	return state;
}, initialState );

export default AuthStore;
Exemple #3
0
const ImporterStore = createReducerStore( function( state, payload ) {
	let { action } = payload,
		newState;

	switch ( action.type ) {
		case actionTypes.RESET_STORE:
			return initialState;

		case actionTypes.DEV_SET_STATE:
			// Convert the importer list into an object
			action.newState.importers = action.newState.importers
					.reduce( ( total, importer ) => Object.assign( total, { [ importer.id ]: importer } ), {} );

			newState = Immutable.fromJS( action.newState );
			newState = Immutable.is( state, newState ) ? state : newState;
			break;

		case actionTypes.API_REQUEST:
			newState = state.setIn( [ 'api', 'isFetching' ], true );
			break;

		case actionTypes.API_FAILURE:
			newState = state
				.setIn( [ 'api', 'isFetching' ], false )
				.updateIn( [ 'api', 'retryCount' ], increment );
			break;

		case actionTypes.API_SUCCESS:
			newState = state
				.setIn( [ 'api', 'isFetching' ], false )
				.setIn( [ 'api', 'isHydrated' ], true )
				.setIn( [ 'api', 'retryCount' ], 0 );
			break;

		case actionTypes.CANCEL_IMPORT:
		case actionTypes.RESET_IMPORT:
			// Remove the specified importer from the list of current importers
			newState = state.update( 'importers', importers => {
				return importers.filterNot( importer => importer.get( 'importerId' ) === action.importerId );
			} );
			break;

		case actionTypes.FAIL_UPLOAD:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.UPLOAD_FAILURE )
				.setIn( [ 'importers', action.importerId, 'errorData' ], { type: 'uploadError', description: action.error } );
			break;

		case actionTypes.FINISH_UPLOAD:
			newState = state
				.deleteIn( [ 'importers' ], action.importerId )
				.setIn( [ 'importers', action.importerStatus.importerId ], Immutable.fromJS( action.importerStatus ) );
			break;

		case actionTypes.START_MAPPING_AUTHORS:
			newState = state.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.MAP_AUTHORS );
			break;

		case actionTypes.MAP_AUTHORS:
			newState = state.updateIn( [ 'importers', action.importerId, 'customData', 'sourceAuthors' ], authors => (
				authors.map( author => {
					if ( action.sourceAuthor.id !== author.get( 'id' ) ) {
						return author;
					}

					return author.set( 'mappedTo', action.targetAuthor );
				} )
			) );
			break;

		case actionTypes.RECEIVE_IMPORT_STATUS:
			newState = state.setIn( [ 'api', 'isHydrated' ], true );

			if ( newState.getIn( [ 'importerLocks', action.importerStatus.importerId ], false ) ) {
				break;
			}

			if ( action.importerStatus.importerState === appStates.DEFUNCT ) {
				newState = newState
					.deleteIn( [ 'importers', action.importerStatus.importerId ] );
				break;
			}

			newState = newState
				.setIn( [ 'importers', action.importerStatus.importerId ], Immutable.fromJS( action.importerStatus ) )
				.update( 'importers', importers => importers.filterNot( shouldRemove ) );
			break;

		case actionTypes.SET_UPLOAD_PROGRESS:
			newState = state.setIn( [ 'importers', action.importerId, 'percentComplete' ],
				action.uploadLoaded / ( action.uploadTotal + Number.EPSILON ) * 100
			);
			break;

		case actionTypes.START_IMPORT:
			const newImporter = Immutable.fromJS( {
				importerId: action.importerId,
				type: action.importerType,
				importerState: appStates.READY_FOR_UPLOAD,
				site: { ID: action.siteId }
			} );

			newState = state
				.update( 'count', count => count + 1 )
				.setIn( [ 'importers', action.importerId ], newImporter );
			break;

		case actionTypes.START_IMPORTING:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.IMPORTING );
			break;

		case actionTypes.START_UPLOAD:
			newState = state
				.setIn( [ 'importers', action.importerId, 'importerState' ], appStates.UPLOADING )
				.setIn( [ 'importers', action.importerId, 'filename' ], action.filename );
			break;

		default:
			newState = state;
			break;
	}

	newState = adjustImporterLock( newState, payload );

	return newState;
}, initialState );
Exemple #4
0
import {createReducerStore} from 'lib/store';
import {actions as ActionTypes} from './constants';
import i18n from 'lib/mixins/i18n';

const initialState = { };

const Store = createReducerStore(function(state, payload) {
	let stateChanges;
	const { action } = payload;


  switch (action.type) {
    case ActionTypes.ADD_ITEM:
      stateChanges = Object.assign({}, state, {
        // isGlobalSettingFetching: true
      });
      break;
    }
  return Object.assign({}, state, stateChanges);
}, initialState);

export default Store;
Exemple #5
0
/**
 * Internal dependencies
 */
import { createReducerStore } from 'lib/store';
import { reducer, initialState } from 'lib/invites/reducers/invites-list';

const InvitesStore = createReducerStore( reducer, initialState );

InvitesStore.getInvites = ( siteId ) => InvitesStore.get().getIn( [ 'list', siteId ] );

export default InvitesStore;
/**
 * Internal dependencies
 */
import { createReducerStore } from 'lib/store';
import { reducer, initialState } from 'lib/invites/reducers/invites-create-validation';

const InvitesCreateValidationStore = createReducerStore( reducer, initialState );

InvitesCreateValidationStore.getSuccess = ( siteId, role ) => InvitesCreateValidationStore.get().getIn( [ 'success', siteId, role ] );
InvitesCreateValidationStore.getErrors = ( siteId, role ) => InvitesCreateValidationStore.get().getIn( [ 'errors', siteId, role ] );

export default InvitesCreateValidationStore;
Exemple #7
0
/** @format */

/**
 * Internal dependencies
 */

import { createReducerStore } from 'lib/store';
import { initialDomainState, reducer } from './reducer';

const NameserversStore = createReducerStore( reducer );

NameserversStore.getByDomainName = function( domainName ) {
	const state = this.get();

	return state[ domainName ] || initialDomainState;
};

export default NameserversStore;
Exemple #8
0
 */
var createReducerStore = require( 'lib/store' ).createReducerStore,
	ActionTypes = require( './constants' ).action;

/**
 * Module variables
 */
var initialState = [];

var HappinessEngineersStore = createReducerStore( function( state, payload ) {
	var action = payload.action,
		newState;
	debug( 'register event Type', action.type, payload );

	switch ( action.type ) {
		case ActionTypes.SET_HAPPPINESS_ENGINEERS:
			newState = action.happinessEngineers;
			break;
		default:
			return state;
	}

	return newState;
}, initialState );

HappinessEngineersStore.getHappinessEngineers = function() {
	return HappinessEngineersStore.get();
};

module.exports = HappinessEngineersStore;
Exemple #9
0
/** @format */
/**
 * Internal dependencies
 */
import { createReducerStore } from 'lib/store';
import { initialDomainState, reducer } from './reducer';

const EmailForwardingStore = createReducerStore( reducer );

EmailForwardingStore.getByDomainName = function( domainName ) {
	const state = this.get();

	return state[ domainName ] || initialDomainState;
};

export default EmailForwardingStore;
Exemple #10
0
/**
 * Internal dependencies
 */
import { createReducerStore } from 'lib/store';
import { getInitialStateForSite, reducer } from './reducer';

const SiteRedirectStore = createReducerStore( reducer );

SiteRedirectStore.getBySite = function( siteId ) {
	const state = this.get();

	if ( ! state[ siteId ] ) {
		return getInitialStateForSite();
	}

	return state[ siteId ];
};

export default SiteRedirectStore;
Exemple #11
0
const NotificationSettingsStore = createReducerStore( ( state, payload ) => {
	const { action, data, error, source, stream, setting } = payload.action;
	const status = null;
	let newState = null;

	switch ( action ) {
		case actionTypes.SAVE_SETTINGS:
		case actionTypes.FETCH_SETTINGS:
			return state.set( 'isFetching', true ).set( 'status', status );

		case actionTypes.SAVE_SETTINGS_FAILED:
		case actionTypes.FETCH_SETTINGS_FAILED:
			return state.set( 'isFetching', false ).set( 'error', error );

		case actionTypes.SAVE_SETTINGS_COMPLETE:
		case actionTypes.FETCH_SETTINGS_COMPLETE:
			newState = Immutable.fromJS( data );
			return state
				.set( 'isFetching', false )
				.set( 'status', action === actionTypes.SAVE_SETTINGS_COMPLETE ? 'success' : null )
				.setIn( [ 'settings', 'clean' ], newState )
				.setIn( [ 'settings', 'dirty' ], newState );

		case actionTypes.TOGGLE_SETTING:
			return toggleSetting( state, source, stream, setting ).set( 'status', status );
	}

	return state;
}, Immutable.fromJS( initialState ) );
Exemple #12
0
 */
import { createReducerStore } from 'lib/store';
import { action as ActionTypes } from './constants';

/**
 * Module variables
 */
const initialState = [];

const HelpSearchStore = createReducerStore( function( state, payload ) {
	let action = payload.action,
		newState;
	debug( 'register event Type', action.type, payload );

	switch ( action.type ) {
		case ActionTypes.SET_HELP_LINKS:
			newState = action.helpLinks;
			break;
		default:
			return state;
	}

	return newState;
}, initialState );

HelpSearchStore.getHelpLinks = function() {
	return HelpSearchStore.get();
};

export default HelpSearchStore;
Exemple #13
0
/**
 * Internal dependencies
 */
import { createReducerStore } from 'lib/store';
import { getInitialStateForDomain, reducer } from './reducer';

const GoogleAppsUsersStore = createReducerStore( reducer );

GoogleAppsUsersStore.getByDomainName = function( domainName ) {
	const state = this.get();

	if ( ! state[ domainName ] ) {
		return getInitialStateForDomain();
	}

	return state[ domainName ];
};

export default GoogleAppsUsersStore;
Exemple #14
0
const olarkStore = createReducerStore( function( state, payload ) {
	let stateChanges;
	const { action } = payload;

	switch ( action.type ) {
		case ActionTypes.OLARK_USER_ELIGIBILITY:
			stateChanges = { isUserEligible: action.isUserEligible };
			break;
		case ActionTypes.OLARK_LOCALE:
			stateChanges = { locale: action.locale };
			break;
		case ActionTypes.OLARK_READY:
			stateChanges = { isOlarkReady: true };
			break;
		case ActionTypes.OLARK_OPERATORS_AWAY:
			stateChanges = { isOperatorAvailable: false };
			break;
		case ActionTypes.OLARK_OPERATORS_AVAILABLE:
			stateChanges = { isOperatorAvailable: true };
			break;
		case ActionTypes.OLARK_SET_EXPANDED:
			stateChanges = { isOlarkExpanded: action.isOlarkExpanded };
			break;
		case ActionTypes.OLARK_DETAILS:
			stateChanges = { details: action.details };
			break;
	}

	if ( stateChanges ) {
		return Object.assign( {}, state, stateChanges );
	}

	return state;
}, initialState );