2017-04-18 02:49:06 -07:00
|
|
|
import Ember from 'ember';
|
|
|
|
import connect from 'ember-redux/components/connect';
|
|
|
|
|
2017-04-21 15:55:24 -07:00
|
|
|
const { Component } = Ember;
|
2017-04-18 02:49:06 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A Selector function that takes the Redux Store and applies
|
|
|
|
* store state to props
|
|
|
|
* @param {Object} datasets is the slice of the store containing datasets
|
|
|
|
* and related state
|
2017-04-21 15:55:24 -07:00
|
|
|
* @return {{datasets: (any[]|Array), isFetching: boolean}}
|
2017-04-18 02:49:06 -07:00
|
|
|
*/
|
|
|
|
const stateToComputed = ({ datasets }) => {
|
2017-04-21 15:55:24 -07:00
|
|
|
const { byPage, byId, currentPage, isFetching = false } = datasets;
|
2017-04-18 02:49:06 -07:00
|
|
|
// List of datasets for the current Page
|
2017-04-21 15:55:24 -07:00
|
|
|
const pagedDatasetIds = byPage[currentPage] || [];
|
2017-04-18 02:49:06 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
// Takes the normalized list of ids and maps to dataset objects
|
2017-04-21 15:55:24 -07:00
|
|
|
datasets: pagedDatasetIds.map(datasetId => byId[datasetId]),
|
|
|
|
isFetching
|
2017-04-18 02:49:06 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(stateToComputed)(Component.extend({}));
|