Skip to content

Commit

Permalink
Rename fetch to load
Browse files Browse the repository at this point in the history
  • Loading branch information
yscik committed Jul 22, 2020
1 parent f3466ea commit 996567b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 38 deletions.
7 changes: 3 additions & 4 deletions assets/data-port/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ const SenseiImportPage = () => {
};
}, [] );

const { fetchCurrentJobState } = useDispatch( 'sensei/import' );
const { loadCurrentJobState } = useDispatch( 'sensei/import' );

// We want to show the loading before any content.
useLayoutEffect( () => {
fetchCurrentJobState();
}, [ fetchCurrentJobState ] );
loadCurrentJobState();
}, [ loadCurrentJobState ] );

useSenseiColorTheme();

Expand Down
16 changes: 8 additions & 8 deletions assets/data-port/import/data/actions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
API_SPECIAL_ACTIVE_JOB_ID,
FETCH_FROM_API,
START_FETCH_CURRENT_JOB_STATE,
SUCCESS_FETCH_CURRENT_JOB_STATE,
ERROR_FETCH_CURRENT_JOB_STATE,
START_LOAD_CURRENT_JOB_STATE,
SUCCESS_LOAD_CURRENT_JOB_STATE,
ERROR_LOAD_CURRENT_JOB_STATE,
START_IMPORT,
SUCCESS_START_IMPORT,
ERROR_START_IMPORT,
Expand Down Expand Up @@ -41,17 +41,17 @@ export const fetchFromAPI = ( request ) => ( {
/**
* Fetch importer data for current job.
*/
export const fetchCurrentJobState = composeFetchAction(
START_FETCH_CURRENT_JOB_STATE,
export const loadCurrentJobState = composeFetchAction(
START_LOAD_CURRENT_JOB_STATE,
function* () {
const data = yield fetchFromAPI( {
path: buildJobEndpointUrl( API_SPECIAL_ACTIVE_JOB_ID ),
} );

return normalizeImportData( data );
},
SUCCESS_FETCH_CURRENT_JOB_STATE,
ERROR_FETCH_CURRENT_JOB_STATE
SUCCESS_LOAD_CURRENT_JOB_STATE,
ERROR_LOAD_CURRENT_JOB_STATE
);

/**
Expand Down Expand Up @@ -386,5 +386,5 @@ export const resetState = () => ( {
*/
export function* restartImporter() {
yield resetState();
yield fetchCurrentJobState();
yield loadCurrentJobState();
}
18 changes: 9 additions & 9 deletions assets/data-port/import/data/actions.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
API_BASE_PATH,
FETCH_FROM_API,
START_FETCH_CURRENT_JOB_STATE,
SUCCESS_FETCH_CURRENT_JOB_STATE,
ERROR_FETCH_CURRENT_JOB_STATE,
START_LOAD_CURRENT_JOB_STATE,
SUCCESS_LOAD_CURRENT_JOB_STATE,
ERROR_LOAD_CURRENT_JOB_STATE,
START_IMPORT,
SUCCESS_START_IMPORT,
ERROR_START_IMPORT,
Expand All @@ -17,7 +17,7 @@ import {

import {
fetchFromAPI,
fetchCurrentJobState,
loadCurrentJobState,
submitStartImport,
startImport,
successStartImport,
Expand Down Expand Up @@ -91,11 +91,11 @@ describe( 'Importer actions', () => {
* Fetch importer data action.
*/
it( 'Should generate the get current job state importer data action', () => {
const gen = fetchCurrentJobState();
const gen = loadCurrentJobState();

// Start fetch action.
const expectedStartFetchAction = {
type: START_FETCH_CURRENT_JOB_STATE,
type: START_LOAD_CURRENT_JOB_STATE,
};

expect( gen.next().value ).toEqual( expectedStartFetchAction );
Expand Down Expand Up @@ -131,7 +131,7 @@ describe( 'Importer actions', () => {
},
},
},
type: SUCCESS_FETCH_CURRENT_JOB_STATE,
type: SUCCESS_LOAD_CURRENT_JOB_STATE,
};

expect( gen.next( RESPONSE_FULL ).value ).toEqual(
Expand All @@ -140,7 +140,7 @@ describe( 'Importer actions', () => {
} );

it( 'Should catch error on the get current job state action', () => {
const gen = fetchCurrentJobState();
const gen = loadCurrentJobState();

// Start fetch action.
gen.next();
Expand All @@ -151,7 +151,7 @@ describe( 'Importer actions', () => {
// Error action.
const error = { code: '', message: 'Error' };
const expectedErrorAction = {
type: ERROR_FETCH_CURRENT_JOB_STATE,
type: ERROR_LOAD_CURRENT_JOB_STATE,
error,
};
expect( gen.throw( error ).value ).toEqual( expectedErrorAction );
Expand Down
9 changes: 4 additions & 5 deletions assets/data-port/import/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export const API_SPECIAL_ACTIVE_JOB_ID = 'active';
export const FETCH_FROM_API = 'FETCH_FROM_API';

/**
* Fetch action type constants.
* Load action type constants.
*/
export const START_FETCH_CURRENT_JOB_STATE = 'START_FETCH_CURRENT_JOB_STATE';
export const SUCCESS_FETCH_CURRENT_JOB_STATE =
'SUCCESS_FETCH_CURRENT_JOB_STATE';
export const ERROR_FETCH_CURRENT_JOB_STATE = 'ERROR_FETCH_CURRENT_JOB_STATE';
export const START_LOAD_CURRENT_JOB_STATE = 'START_LOAD_CURRENT_JOB_STATE';
export const SUCCESS_LOAD_CURRENT_JOB_STATE = 'SUCCESS_LOAD_CURRENT_JOB_STATE';
export const ERROR_LOAD_CURRENT_JOB_STATE = 'ERROR_LOAD_CURRENT_JOB_STATE';
export const SET_JOB_STATE = 'SET_JOB_STATE';

/**
Expand Down
12 changes: 6 additions & 6 deletions assets/data-port/import/data/reducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
START_FETCH_CURRENT_JOB_STATE,
SUCCESS_FETCH_CURRENT_JOB_STATE,
ERROR_FETCH_CURRENT_JOB_STATE,
START_LOAD_CURRENT_JOB_STATE,
SUCCESS_LOAD_CURRENT_JOB_STATE,
ERROR_LOAD_CURRENT_JOB_STATE,
START_IMPORT,
SUCCESS_START_IMPORT,
ERROR_START_IMPORT,
Expand Down Expand Up @@ -87,14 +87,14 @@ const updateLevelState = ( state, levelKey, attributes ) => ( {
*/
export default ( state = DEFAULT_STATE, action ) => {
switch ( action.type ) {
case START_FETCH_CURRENT_JOB_STATE:
case START_LOAD_CURRENT_JOB_STATE:
return {
...state,
isFetching: true,
fetchError: false,
};

case SUCCESS_FETCH_CURRENT_JOB_STATE:
case SUCCESS_LOAD_CURRENT_JOB_STATE:
return {
...merge( {}, state, action.data ),
isFetching: false,
Expand All @@ -105,7 +105,7 @@ export default ( state = DEFAULT_STATE, action ) => {
...merge( {}, state, action.data ),
};

case ERROR_FETCH_CURRENT_JOB_STATE:
case ERROR_LOAD_CURRENT_JOB_STATE:
return {
...state,
isFetching: false,
Expand Down
12 changes: 6 additions & 6 deletions assets/data-port/import/data/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import reducer from './reducer';
import {
START_FETCH_CURRENT_JOB_STATE,
SUCCESS_FETCH_CURRENT_JOB_STATE,
ERROR_FETCH_CURRENT_JOB_STATE,
START_LOAD_CURRENT_JOB_STATE,
SUCCESS_LOAD_CURRENT_JOB_STATE,
ERROR_LOAD_CURRENT_JOB_STATE,
START_IMPORT,
SUCCESS_START_IMPORT,
ERROR_START_IMPORT,
Expand All @@ -20,7 +20,7 @@ import {
describe( 'Importer reducer', () => {
it( 'Should set isFetching to true on START_FETCH_CURRENT_JOB_STATE action', () => {
const state = reducer( undefined, {
type: START_FETCH_CURRENT_JOB_STATE,
type: START_LOAD_CURRENT_JOB_STATE,
} );

expect( state.isFetching ).toBeTruthy();
Expand All @@ -32,7 +32,7 @@ describe( 'Importer reducer', () => {
};

const state = reducer( undefined, {
type: SUCCESS_FETCH_CURRENT_JOB_STATE,
type: SUCCESS_LOAD_CURRENT_JOB_STATE,
data,
} );

Expand Down Expand Up @@ -60,7 +60,7 @@ describe( 'Importer reducer', () => {
};

const state = reducer( undefined, {
type: ERROR_FETCH_CURRENT_JOB_STATE,
type: ERROR_LOAD_CURRENT_JOB_STATE,
error,
} );

Expand Down

0 comments on commit 996567b

Please sign in to comment.