woocommerce/plugins/woocommerce-admin/client/analytics/settings/historical-data/utils.js

69 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { isNil } from 'lodash';
import moment from 'moment';
export const formatParams = ( dateFormat, period, skipChecked ) => {
const params = {};
if ( skipChecked ) {
params.skip_existing = true;
}
if ( period.label !== 'all' ) {
if ( period.label === 'custom' ) {
const daysDifference = moment().diff(
moment( period.date, dateFormat ),
'days',
true
);
params.days = Math.floor( daysDifference );
} else {
params.days = parseInt( period.label, 10 );
}
}
return params;
};
export const getStatus = ( {
Migrated "import" store to "wp.data" (https://github.com/woocommerce/woocommerce-admin/pull/4982) * Migrated the "import" store to "wp.data" This commit migrates the "import" store to "wp.data" # Conflicts: # client/analytics/settings/historical-data/layout.js # packages/data/src/index.js # Conflicts: # packages/data/src/index.js # Conflicts: # packages/data/src/index.js * Added error handling This commit adds error handling to the apiFetch * Fixred reducer.js * Added reducer.js tests * Removed "endpoint" references * Tests fixed * Removed old import store files and wc-api-spec import references This commit removes old import store files and "wc-api-spec" import references # Conflicts: # client/wc-api/wc-api-spec.js # Conflicts: # client/wc-api/wc-api-spec.js * Added interval to invalidate resolution of getImportStatus * Fixed timestamp * Store dependency removed * Fixed reimport functionality # Conflicts: # client/analytics/settings/historical-data/index.js * Refactored layout.js * Refactored clearCache method * inProgress check refactored * Using activeImport from store # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed console warning # Conflicts: # client/analytics/settings/historical-data/index.js * Migration done! # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed hasImportFinished * Test fixed * Removed "setImportFinished" from actions.js and index.js * Added style to disabled button * Fixed incorrect "Finalizing" status * Fixed tests * Fixed notes update on importation start * Removed local constants * Removed css for disabled button * Typo corrected * Fixed param for getImportError method Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2020-09-01 13:21:31 +00:00
cacheNeedsClearing,
customersProgress,
customersTotal,
Migrated "import" store to "wp.data" (https://github.com/woocommerce/woocommerce-admin/pull/4982) * Migrated the "import" store to "wp.data" This commit migrates the "import" store to "wp.data" # Conflicts: # client/analytics/settings/historical-data/layout.js # packages/data/src/index.js # Conflicts: # packages/data/src/index.js # Conflicts: # packages/data/src/index.js * Added error handling This commit adds error handling to the apiFetch * Fixred reducer.js * Added reducer.js tests * Removed "endpoint" references * Tests fixed * Removed old import store files and wc-api-spec import references This commit removes old import store files and "wc-api-spec" import references # Conflicts: # client/wc-api/wc-api-spec.js # Conflicts: # client/wc-api/wc-api-spec.js * Added interval to invalidate resolution of getImportStatus * Fixed timestamp * Store dependency removed * Fixed reimport functionality # Conflicts: # client/analytics/settings/historical-data/index.js * Refactored layout.js * Refactored clearCache method * inProgress check refactored * Using activeImport from store # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed console warning # Conflicts: # client/analytics/settings/historical-data/index.js * Migration done! # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed hasImportFinished * Test fixed * Removed "setImportFinished" from actions.js and index.js * Added style to disabled button * Fixed incorrect "Finalizing" status * Fixed tests * Fixed notes update on importation start * Removed local constants * Removed css for disabled button * Typo corrected * Fixed param for getImportError method Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2020-09-01 13:21:31 +00:00
isError,
inProgress,
ordersProgress,
ordersTotal,
} ) => {
Migrated "import" store to "wp.data" (https://github.com/woocommerce/woocommerce-admin/pull/4982) * Migrated the "import" store to "wp.data" This commit migrates the "import" store to "wp.data" # Conflicts: # client/analytics/settings/historical-data/layout.js # packages/data/src/index.js # Conflicts: # packages/data/src/index.js # Conflicts: # packages/data/src/index.js * Added error handling This commit adds error handling to the apiFetch * Fixred reducer.js * Added reducer.js tests * Removed "endpoint" references * Tests fixed * Removed old import store files and wc-api-spec import references This commit removes old import store files and "wc-api-spec" import references # Conflicts: # client/wc-api/wc-api-spec.js # Conflicts: # client/wc-api/wc-api-spec.js * Added interval to invalidate resolution of getImportStatus * Fixed timestamp * Store dependency removed * Fixed reimport functionality # Conflicts: # client/analytics/settings/historical-data/index.js * Refactored layout.js * Refactored clearCache method * inProgress check refactored * Using activeImport from store # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed console warning # Conflicts: # client/analytics/settings/historical-data/index.js * Migration done! # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed hasImportFinished * Test fixed * Removed "setImportFinished" from actions.js and index.js * Added style to disabled button * Fixed incorrect "Finalizing" status * Fixed tests * Fixed notes update on importation start * Removed local constants * Removed css for disabled button * Typo corrected * Fixed param for getImportError method Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2020-09-01 13:21:31 +00:00
if ( isError ) {
return 'error';
}
if ( inProgress ) {
if (
isNil( customersProgress ) ||
isNil( ordersProgress ) ||
isNil( customersTotal ) ||
Migrated "import" store to "wp.data" (https://github.com/woocommerce/woocommerce-admin/pull/4982) * Migrated the "import" store to "wp.data" This commit migrates the "import" store to "wp.data" # Conflicts: # client/analytics/settings/historical-data/layout.js # packages/data/src/index.js # Conflicts: # packages/data/src/index.js # Conflicts: # packages/data/src/index.js * Added error handling This commit adds error handling to the apiFetch * Fixred reducer.js * Added reducer.js tests * Removed "endpoint" references * Tests fixed * Removed old import store files and wc-api-spec import references This commit removes old import store files and "wc-api-spec" import references # Conflicts: # client/wc-api/wc-api-spec.js # Conflicts: # client/wc-api/wc-api-spec.js * Added interval to invalidate resolution of getImportStatus * Fixed timestamp * Store dependency removed * Fixed reimport functionality # Conflicts: # client/analytics/settings/historical-data/index.js * Refactored layout.js * Refactored clearCache method * inProgress check refactored * Using activeImport from store # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed console warning # Conflicts: # client/analytics/settings/historical-data/index.js * Migration done! # Conflicts: # client/analytics/settings/historical-data/index.js * Fixed hasImportFinished * Test fixed * Removed "setImportFinished" from actions.js and index.js * Added style to disabled button * Fixed incorrect "Finalizing" status * Fixed tests * Fixed notes update on importation start * Removed local constants * Removed css for disabled button * Typo corrected * Fixed param for getImportError method Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2020-09-01 13:21:31 +00:00
isNil( ordersTotal ) ||
cacheNeedsClearing
) {
return 'initializing';
}
if ( customersProgress < customersTotal ) {
return 'customers';
}
if ( ordersProgress < ordersTotal ) {
return 'orders';
}
return 'finalizing';
}
if ( customersTotal > 0 || ordersTotal > 0 ) {
if (
customersProgress === customersTotal &&
ordersProgress === ordersTotal
) {
return 'finished';
}
return 'ready';
}
return 'nothing';
};