mirror of
https://github.com/yldio/copilot.git
synced 2024-12-01 07:30:07 +02:00
feat(cp-frontend): sort services by name
This commit is contained in:
parent
391267d609
commit
935e9bacca
@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import forceArray from 'force-array';
|
||||||
|
import sortBy from 'lodash.sortby';
|
||||||
|
|
||||||
import { InstancesIcon, HealthyIcon, UnhealthyIcon } from 'joyent-ui-toolkit';
|
import { InstancesIcon, HealthyIcon, UnhealthyIcon } from 'joyent-ui-toolkit';
|
||||||
import Status from './status';
|
import Status from './status';
|
||||||
@ -35,20 +37,26 @@ const ServiceListItem = ({
|
|||||||
service = {},
|
service = {},
|
||||||
isChild = false
|
isChild = false
|
||||||
}) => {
|
}) => {
|
||||||
const isServiceInactive = service.status !== 'ACTIVE';
|
const handleCardOptionsClick = evt => {
|
||||||
|
onQuickActionsClick(evt, service);
|
||||||
|
};
|
||||||
|
|
||||||
const children = service.children
|
const children = forceArray(service.children);
|
||||||
? service.children.map(service =>
|
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 =>
|
||||||
<ServiceListItem
|
<ServiceListItem
|
||||||
key={service.id}
|
key={service.id}
|
||||||
deploymentGroup={deploymentGroup}
|
deploymentGroup={deploymentGroup}
|
||||||
service={service}
|
service={service}
|
||||||
isChild
|
isChild
|
||||||
/>
|
/>
|
||||||
)
|
);
|
||||||
: null;
|
|
||||||
|
|
||||||
const to = `/deployment-groups/${deploymentGroup}/services/${service.slug}`;
|
|
||||||
|
|
||||||
const title = isChild
|
const title = isChild
|
||||||
? <CardTitle>
|
? <CardTitle>
|
||||||
@ -69,17 +77,6 @@ const ServiceListItem = ({
|
|||||||
</CardSubTitle>
|
</CardSubTitle>
|
||||||
);
|
);
|
||||||
|
|
||||||
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
|
const header = !isChild
|
||||||
? <StyledCardHeader>
|
? <StyledCardHeader>
|
||||||
{title}
|
{title}
|
||||||
@ -113,9 +110,9 @@ const ServiceListItem = ({
|
|||||||
color="dark"
|
color="dark"
|
||||||
/>;
|
/>;
|
||||||
|
|
||||||
const view = children
|
const view = childrenItems.length
|
||||||
? <CardGroupView>
|
? <CardGroupView>
|
||||||
{children}
|
{childrenItems}
|
||||||
</CardGroupView>
|
</CardGroupView>
|
||||||
: <CardView>
|
: <CardView>
|
||||||
{isChild && title}
|
{isChild && title}
|
||||||
|
@ -3,6 +3,7 @@ import { compose, graphql } from 'react-apollo';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import forceArray from 'force-array';
|
import forceArray from 'force-array';
|
||||||
|
import sortBy from 'lodash.sortby';
|
||||||
|
|
||||||
import ServicesQuery from '@graphql/Services.gql';
|
import ServicesQuery from '@graphql/Services.gql';
|
||||||
import ServicesRestartMutation from '@graphql/ServicesRestartMutation.gql';
|
import ServicesRestartMutation from '@graphql/ServicesRestartMutation.gql';
|
||||||
@ -46,16 +47,15 @@ class ServiceList extends Component {
|
|||||||
startServices
|
startServices
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (
|
if (loading) {
|
||||||
(loading && !forceArray(services).length) ||
|
|
||||||
(deploymentGroup.status === 'PROVISIONING' && !services.length)
|
|
||||||
) {
|
|
||||||
return (
|
return (
|
||||||
<LayoutContainer>
|
<LayoutContainer center>
|
||||||
<Loader />
|
<Loader />
|
||||||
</LayoutContainer>
|
</LayoutContainer>
|
||||||
);
|
);
|
||||||
} else if (error) {
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<LayoutContainer>
|
<LayoutContainer>
|
||||||
<ErrorMessage message="Oops, and error occured while loading your services." />
|
<ErrorMessage message="Oops, and error occured while loading your services." />
|
||||||
@ -63,6 +63,17 @@ class ServiceList extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
deploymentGroup.status === 'PROVISIONING' &&
|
||||||
|
!forceArray(services).length
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<LayoutContainer>
|
||||||
|
<Loader msg="Just a moment, we’re on it" />
|
||||||
|
</LayoutContainer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const handleQuickActionsClick = (evt, service) => {
|
const handleQuickActionsClick = (evt, service) => {
|
||||||
const list = this._refs.container;
|
const list = this._refs.container;
|
||||||
const listRect = list.getBoundingClientRect();
|
const listRect = list.getBoundingClientRect();
|
||||||
@ -109,7 +120,7 @@ class ServiceList extends Component {
|
|||||||
toggleServicesQuickActions({ show: false });
|
toggleServicesQuickActions({ show: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
const serviceList = services.map(service => {
|
const serviceList = sortBy(services, ['slug']).map(service => {
|
||||||
return (
|
return (
|
||||||
<ServiceListItem
|
<ServiceListItem
|
||||||
key={service.id}
|
key={service.id}
|
||||||
|
Loading…
Reference in New Issue
Block a user