From 935e9bacca1583c3e8f2e5bbcab344e3949579f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 28 Jul 2017 15:25:06 +0100 Subject: [PATCH] feat(cp-frontend): sort services by name --- .../src/components/services/list-item.js | 47 +++++++++---------- .../src/containers/services/list.js | 25 +++++++--- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/packages/cp-frontend/src/components/services/list-item.js b/packages/cp-frontend/src/components/services/list-item.js index 48efcb9a..38ed6855 100644 --- a/packages/cp-frontend/src/components/services/list-item.js +++ b/packages/cp-frontend/src/components/services/list-item.js @@ -1,6 +1,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; +import forceArray from 'force-array'; +import sortBy from 'lodash.sortby'; import { InstancesIcon, HealthyIcon, UnhealthyIcon } from 'joyent-ui-toolkit'; import Status from './status'; @@ -35,21 +37,27 @@ const ServiceListItem = ({ service = {}, isChild = false }) => { - const isServiceInactive = service.status !== 'ACTIVE'; - - const children = service.children - ? service.children.map(service => - - ) - : null; + const handleCardOptionsClick = evt => { + onQuickActionsClick(evt, service); + }; + const children = forceArray(service.children); + const isServiceInactive = service.status && service.status !== 'ACTIVE'; const to = `/deployment-groups/${deploymentGroup}/services/${service.slug}`; + const instancesCount = children.length + ? children.reduce((count, child) => count + child.instances.length, 0) + : service.instances.length; + + const childrenItems = sortBy(children, ['slug']).map(service => + + ); + const title = isChild ? {service.name} @@ -69,17 +77,6 @@ const ServiceListItem = ({ ); - const handleCardOptionsClick = evt => { - onQuickActionsClick(evt, service); - }; - - const instancesCount = service.children - ? service.children.reduce( - (count, child) => count + child.instances.length, - 0 - ) - : service.instances.length; - const header = !isChild ? {title} @@ -113,9 +110,9 @@ const ServiceListItem = ({ color="dark" />; - const view = children + const view = childrenItems.length ? - {children} + {childrenItems} : {isChild && title} diff --git a/packages/cp-frontend/src/containers/services/list.js b/packages/cp-frontend/src/containers/services/list.js index 36317813..209e4dd4 100644 --- a/packages/cp-frontend/src/containers/services/list.js +++ b/packages/cp-frontend/src/containers/services/list.js @@ -3,6 +3,7 @@ import { compose, graphql } from 'react-apollo'; import { connect } from 'react-redux'; import styled from 'styled-components'; import forceArray from 'force-array'; +import sortBy from 'lodash.sortby'; import ServicesQuery from '@graphql/Services.gql'; import ServicesRestartMutation from '@graphql/ServicesRestartMutation.gql'; @@ -46,16 +47,15 @@ class ServiceList extends Component { startServices } = this.props; - if ( - (loading && !forceArray(services).length) || - (deploymentGroup.status === 'PROVISIONING' && !services.length) - ) { + if (loading) { return ( - + ); - } else if (error) { + } + + if (error) { return ( @@ -63,6 +63,17 @@ class ServiceList extends Component { ); } + if ( + deploymentGroup.status === 'PROVISIONING' && + !forceArray(services).length + ) { + return ( + + + + ); + } + const handleQuickActionsClick = (evt, service) => { const list = this._refs.container; const listRect = list.getBoundingClientRect(); @@ -109,7 +120,7 @@ class ServiceList extends Component { toggleServicesQuickActions({ show: false }); }; - const serviceList = services.map(service => { + const serviceList = sortBy(services, ['slug']).map(service => { return (