Skip to content

Commit

Permalink
Merge pull request #356 from cumulus-nasa/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
dereklieu authored Apr 13, 2017
2 parents 2e32a32 + c7c34e0 commit 4041416
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 25 deletions.
7 changes: 4 additions & 3 deletions app/scripts/components/app/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var Sidebar = React.createClass({

propTypes: {
currentPath: React.PropTypes.string,
params: React.PropTypes.object
params: React.PropTypes.object,
count: React.PropTypes.array
},

resolvePath: function (base, path) {
Expand All @@ -21,11 +22,11 @@ var Sidebar = React.createClass({

renderNavSection: function (section) {
const { base, routes } = section;
const { currentPath, params } = this.props;
const { currentPath, params, count } = this.props;
return (
<div key={base}>
<ul>
{routes(currentPath, params).map((d, i) => {
{routes(currentPath, params, count).map((d, i) => {
let path = this.resolvePath(base, d[1]);
let className = d[2] || '';
if (path === currentPath) {
Expand Down
29 changes: 27 additions & 2 deletions app/scripts/components/granules/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import React from 'react';
import { connect } from 'react-redux';
import { get } from 'object-path';
import Sidebar from '../app/sidebar';
import { interval, getCount } from '../../actions';
import { updateInterval } from '../../config';

var Granules = React.createClass({
displayName: 'Granules',

propTypes: {
children: React.PropTypes.object,
location: React.PropTypes.object,
params: React.PropTypes.object
params: React.PropTypes.object,
dispatch: React.PropTypes.func,
stats: React.PropTypes.object
},

componentWillMount: function () {
this.cancelInterval = interval(() => this.query(), updateInterval, true);
},

componentWillUnmount: function () {
if (this.cancelInterval) { this.cancelInterval(); }
},

query: function () {
this.props.dispatch(getCount({
type: 'granules',
field: 'status'
}));
},

render: function () {
const count = get(this.props.stats, 'count.data.granules.count');
return (
<div className='page__granules'>
<div className='content__header'>
Expand All @@ -21,7 +42,11 @@ var Granules = React.createClass({
</div>
<div className='page__content'>
<div className='row wrapper__sidebar'>
<Sidebar currentPath={this.props.location.pathname} params={this.props.params} />
<Sidebar
currentPath={this.props.location.pathname}
params={this.props.params}
count={count}
/>
<div className='page__content--shortened'>
{this.props.children}
</div>
Expand Down
29 changes: 27 additions & 2 deletions app/scripts/components/pdr/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
'use strict';
import React from 'react';
import { get } from 'object-path';
import { connect } from 'react-redux';
import Sidebar from '../app/sidebar';
import { interval, getCount } from '../../actions';
import { updateInterval } from '../../config';

var Pdrs = React.createClass({
displayName: 'Pdrs',

propTypes: {
children: React.PropTypes.object,
location: React.PropTypes.object,
params: React.PropTypes.object
params: React.PropTypes.object,
dispatch: React.PropTypes.func,
stats: React.PropTypes.object
},

componentWillMount: function () {
this.cancelInterval = interval(() => this.query(), updateInterval, true);
},

componentWillUnmount: function () {
if (this.cancelInterval) { this.cancelInterval(); }
},

query: function () {
this.props.dispatch(getCount({
type: 'pdrs',
field: 'status'
}));
},

render: function () {
const count = get(this.props.stats, 'count.data.pdrs.count');
return (
<div className='page__pdrs'>
<div className='content__header'>
Expand All @@ -22,7 +43,11 @@ var Pdrs = React.createClass({
</div>
<div className='page__content'>
<div className='row wrapper__sidebar'>
<Sidebar currentPath={this.props.location.pathname} params={this.props.params} />
<Sidebar
currentPath={this.props.location.pathname}
params={this.props.params}
count={count}
/>
<div className='page__content--shortened'>
{this.props.children}
</div>
Expand Down
29 changes: 27 additions & 2 deletions app/scripts/components/providers/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
'use strict';
import React from 'react';
import { get } from 'object-path';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import Sidebar from '../app/sidebar';
import { interval, getCount } from '../../actions';
import { updateInterval } from '../../config';

var Providers = React.createClass({
displayName: 'Providers',

propTypes: {
children: React.PropTypes.object,
location: React.PropTypes.object,
params: React.PropTypes.object
params: React.PropTypes.object,
dispatch: React.PropTypes.func,
stats: React.PropTypes.object
},

componentWillMount: function () {
this.cancelInterval = interval(() => this.query(), updateInterval, true);
},

componentWillUnmount: function () {
if (this.cancelInterval) { this.cancelInterval(); }
},

query: function () {
this.props.dispatch(getCount({
type: 'providers',
field: 'status'
}));
},

render: function () {
const { pathname } = this.props.location;
const alreadyInAddProvider = pathname === '/providers/add';
const count = get(this.props.stats, 'count.data.providers.count');
return (
<div className='page__providers'>
<div className='content__header'>
Expand All @@ -26,7 +47,11 @@ var Providers = React.createClass({
</div>
<div className='page__content'>
<div className='row wrapper__sidebar'>
{alreadyInAddProvider ? null : <Sidebar currentPath={this.props.location.pathname} params={this.props.params} />}
{alreadyInAddProvider ? null : <Sidebar
currentPath={this.props.location.pathname}
params={this.props.params}
count={count}
/>}
<div className='page__content--shortened'>
{this.props.children}
</div>
Expand Down
16 changes: 10 additions & 6 deletions app/scripts/paths/granules.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';
import { encode } from '../utils/browser';
import tally from './tally';
import { queryStatus } from '../utils/status';
const processing = queryStatus.filter(d => d !== 'failed' && d !== 'completed');

const granuleRoutes = [
['All Granules', null],
['Completed', 'completed'],
['Processing', 'processing'],
['Failed', 'failed']
['Completed', 'completed', (d) => d.key === 'completed'],
['Processing', 'processing', (d) => processing.indexOf(d.key) >= 0],
['Failed', 'failed', (d) => d.key === 'failed']
];

const singleGranuleRoutes = [
Expand All @@ -19,16 +22,17 @@ const empty = [['', '']];
const granules = {
base: 'granules',
heading: 'Granules',
routes: (currentRoute, params) => {
routes: (currentRoute, params, count) => {
if (currentRoute.indexOf('granules/granule') >= 0) {
return singleGranuleRoutes.map(d => {
if (!d[1] || d[1].indexOf(':granuleId') === -1) { return d; }
if (!d[1] || d[1].indexOf(':granuleId') === -1) return d;
let copy = d.slice();
copy[1] = encode(copy[1].replace(':granuleId', params.granuleId));
return copy;
});
} else if (currentRoute.slice(0, 9) === '/granules') {
return granuleRoutes;
count = count || [];
return granuleRoutes.map(d => tally(d, count));
} else {
return empty;
}
Expand Down
14 changes: 9 additions & 5 deletions app/scripts/paths/pdrs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';
import tally from './tally';
import { pdrQueryStatus } from '../utils/status';
const processing = pdrQueryStatus.filter(d => d !== 'failed' && d !== 'completed');

const pdrRoutes = [
['Overview', null],
['All PDRs', 'all'],
['Completed', 'completed'],
['Active', 'active'],
['Failed', 'failed']
['Completed', 'completed', (d) => d.key === 'completed'],
['Active', 'active', (d) => processing.indexOf(d.key) >= 0],
['Failed', 'failed', (d) => d.key === 'failed']
];

const singlePdrRoutes = [
Expand All @@ -17,13 +20,14 @@ const empty = [['', '']];
const pdrs = {
base: 'pdrs',
heading: 'PDRs',
routes: (currentRoute) => {
routes: (currentRoute, params, count) => {
if (currentRoute.indexOf('pdrs/pdr') >= 0) {
return singlePdrRoutes;
} else if (currentRoute.slice(0, 5) !== '/pdrs') {
return empty;
} else {
return pdrRoutes;
count = count || [];
return pdrRoutes.map(d => tally(d, count));
}
}
};
Expand Down
12 changes: 7 additions & 5 deletions app/scripts/paths/providers.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict';
import tally from './tally';

const providerRoutes = [
['Overview', null],
['All Providers', 'all'],
['Active', 'active'],
['Inactive', 'inactive'],
['Failed', 'failed']
['Active', 'active', (d) => d.key === 'ingesting'],
['Inactive', 'inactive', (d) => d.key === 'stopped'],
['Failed', 'failed', (d) => d.key === 'failed']
];

const EMPTY = [['', '']];

const providers = {
base: 'providers',
heading: 'Providers',
routes: (currentRoute) => {
routes: (currentRoute, params, count) => {
if (currentRoute.startsWith('/providers')) {
return providerRoutes;
count = count || [];
return providerRoutes.map(d => tally(d, count));
} else {
return EMPTY;
}
Expand Down
21 changes: 21 additions & 0 deletions app/scripts/paths/tally.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
import { get } from 'object-path';
import { tally } from '../utils/format';
function tallyFn (route, count) {
// check for a filter function
const filter = route[2];
if (typeof filter !== 'function') return route;

// filter
const matches = count.filter(filter);
if (!matches.length) return route;

// reduce
const value = matches.reduce((a, b) => a + get(b, 'count', 0), 0);

// clone and set the tally
const copy = route.slice();
copy[0] += ` (${tally(value)})`;
return copy;
}
export default tallyFn;
7 changes: 7 additions & 0 deletions app/scripts/utils/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ export const pdrStatus = {
Completed: 'completed',
Failed: 'failed'
};

export const pdrQueryStatus = [
'discovered',
'parsed',
'completed',
'failed'
];

0 comments on commit 4041416

Please sign in to comment.