diff --git a/frontend/src/component/archive/archive-list-container.js b/frontend/src/component/archive/archive-list-container.js index b1c884d258..5c12f58e06 100644 --- a/frontend/src/component/archive/archive-list-container.js +++ b/frontend/src/component/archive/archive-list-container.js @@ -2,73 +2,9 @@ import { connect } from 'react-redux'; import FeatureListComponent from './../feature/list-component'; import { fetchArchive, revive } from './../../store/archive-actions'; import { updateSettingForGroup } from './../../store/settings/actions'; +import { mapStateToPropsConfigurable } from '../feature/list-container'; -const mapStateToProps = state => { - const featureMetrics = state.featureMetrics.toJS(); - const settings = state.settings.toJS().feature || {}; - let features = state.archive.get('list').toArray(); - if (settings.filter) { - try { - const regex = new RegExp(settings.filter, 'i'); - features = features.filter( - feature => - regex.test(feature.name) || - regex.test(feature.description) || - feature.strategies.some(s => s && s.name && regex.test(s.name)) - ); - } catch (e) { - // Invalid filter regex - } - } - - if (!settings.sort) { - settings.sort = 'name'; - } - - if (settings.sort === 'enabled') { - features = features.sort( - (a, b) => - // eslint-disable-next-line - a.enabled === b.enabled ? 0 : a.enabled ? -1 : 1 - ); - } else if (settings.sort === 'created') { - features = features.sort((a, b) => (new Date(a.createdAt) > new Date(b.createdAt) ? -1 : 1)); - } else if (settings.sort === 'name') { - features = features.sort((a, b) => { - if (a.name < b.name) { - return -1; - } - if (a.name > b.name) { - return 1; - } - return 0; - }); - } else if (settings.sort === 'strategies') { - features = features.sort((a, b) => (a.strategies.length > b.strategies.length ? -1 : 1)); - } else if (settings.sort === 'metrics') { - const target = settings.showLastHour ? featureMetrics.lastHour : featureMetrics.lastMinute; - - features = features.sort((a, b) => { - if (!target[a.name]) { - return 1; - } - if (!target[b.name]) { - return -1; - } - if (target[a.name].yes > target[b.name].yes) { - return -1; - } - return 1; - }); - } - - return { - features, - featureMetrics, - settings, - }; -}; - +const mapStateToProps = mapStateToPropsConfigurable(false); const mapDispatchToProps = { fetchArchive, revive, diff --git a/frontend/src/component/feature/list-component.jsx b/frontend/src/component/feature/list-component.jsx index 118260df96..3b38518ddc 100644 --- a/frontend/src/component/feature/list-component.jsx +++ b/frontend/src/component/feature/list-component.jsx @@ -115,6 +115,7 @@ export default class FeatureListComponent extends React.Component { metricsLastHour={featureMetrics.lastHour[feature.name]} metricsLastMinute={featureMetrics.lastMinute[feature.name]} feature={feature} + toggleFeature={toggleFeature} revive={revive} /> ))} diff --git a/frontend/src/component/feature/list-container.jsx b/frontend/src/component/feature/list-container.jsx index 412b50376c..3ca68741f1 100644 --- a/frontend/src/component/feature/list-container.jsx +++ b/frontend/src/component/feature/list-container.jsx @@ -4,10 +4,10 @@ import { updateSettingForGroup } from '../../store/settings/actions'; import FeatureListComponent from './list-component'; -const mapStateToProps = state => { +export const mapStateToPropsConfigurable = isFeature => state => { const featureMetrics = state.featureMetrics.toJS(); const settings = state.settings.toJS().feature || {}; - let features = state.features.toJS(); + let features = isFeature ? state.features.toJS() : state.archive.get('list').toArray(); if (settings.filter) { try { const regex = new RegExp(settings.filter, 'i'); @@ -69,7 +69,7 @@ const mapStateToProps = state => { settings, }; }; - +const mapStateToProps = mapStateToPropsConfigurable(true); const mapDispatchToProps = { toggleFeature, fetchFeatureToggles,