From 8c09160693b7c1d51bf08f0a69c9b84daea2509d Mon Sep 17 00:00:00 2001 From: vsandvold Date: Tue, 14 Feb 2017 11:05:34 +0100 Subject: [PATCH] makes name default sorting --- .../src/component/feature/list-component.jsx | 4 +- .../src/component/feature/list-container.jsx | 64 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/frontend/src/component/feature/list-component.jsx b/frontend/src/component/feature/list-component.jsx index 6d22646955..ab59ba754a 100644 --- a/frontend/src/component/feature/list-component.jsx +++ b/frontend/src/component/feature/list-component.jsx @@ -66,7 +66,7 @@ export default class FeatureListComponent extends React.PureComponent { - + this.toggleMetrics()} @@ -79,7 +79,7 @@ export default class FeatureListComponent extends React.PureComponent { this.setSort(e.target.getAttribute('data-target'))} style={{ width: '168px' }}> - Name + Name Enabled Created Strategies diff --git a/frontend/src/component/feature/list-container.jsx b/frontend/src/component/feature/list-container.jsx index 6ed902ca72..7cdbadd14f 100644 --- a/frontend/src/component/feature/list-container.jsx +++ b/frontend/src/component/feature/list-container.jsx @@ -21,38 +21,40 @@ const mapStateToProps = (state) => { ); } - if (settings.sort) { - 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; + if (!settings.sort) { + settings.sort = 'name'; + } - 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; - }); - } + 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 {