Merge pull request #601 from influxdata/measurement-present

Fix layout being displayed when measurement not present
pull/10616/head
Nathan Haugo 2016-11-29 11:30:51 -08:00 committed by GitHub
commit 6e8c55e4b4
2 changed files with 39 additions and 11 deletions

View File

@ -81,3 +81,28 @@ export function getAppsForHosts(proxyLink, hosts, appMappings, telegrafDB) {
return newHosts; return newHosts;
}); });
} }
export function getMeasurementsForHost(source, host) {
return proxy({
source: source.links.proxy,
query: `SHOW MEASUREMENTS WHERE "host" = '${host}'`,
db: source.telegraf,
}).then(({data}) => {
if (_isEmpty(data) || _hasError(data)) {
return [];
}
const series = data.results[0].series[0];
return series.values.map((measurement) => {
return measurement[0];
});
});
}
function _isEmpty(resp) {
return !resp.results[0].series;
}
function _hasError(resp) {
return !!resp.results[0].error;
}

View File

@ -2,7 +2,7 @@ import React, {PropTypes} from 'react';
import LayoutRenderer from 'shared/components/LayoutRenderer'; import LayoutRenderer from 'shared/components/LayoutRenderer';
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown'; import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
import timeRanges from 'hson!../../shared/data/timeRanges.hson'; import timeRanges from 'hson!../../shared/data/timeRanges.hson';
import {getMappings, getAppsForHosts} from '../apis'; import {getMappings, getAppsForHosts, getMeasurementsForHost} from 'src/hosts/apis';
import {fetchLayouts} from 'shared/apis'; import {fetchLayouts} from 'shared/apis';
export const HostPage = React.createClass({ export const HostPage = React.createClass({
@ -33,22 +33,25 @@ export const HostPage = React.createClass({
}, },
componentDidMount() { componentDidMount() {
const hosts = {[this.props.params.hostID]: {name: this.props.params.hostID}}; const {source, params} = this.props;
const {source} = this.props; const hosts = {[params.hostID]: {name: params.hostID}};
// fetching layouts and mappings can be done at the same time // fetching layouts and mappings can be done at the same time
fetchLayouts().then(({data: {layouts}}) => { fetchLayouts().then(({data: {layouts}}) => {
getMappings().then(({data: {mappings}}) => { getMappings().then(({data: {mappings}}) => {
getAppsForHosts(source.links.proxy, hosts, mappings, source.telegraf).then((newHosts) => { getAppsForHosts(source.links.proxy, hosts, mappings, source.telegraf).then((newHosts) => {
const host = newHosts[this.props.params.hostID]; getMeasurementsForHost(source, params.hostID).then((measurements) => {
const filteredLayouts = layouts.filter((layout) => { const host = newHosts[this.props.params.hostID];
const focusedApp = this.props.location.query.app; const filteredLayouts = layouts.filter((layout) => {
if (focusedApp) { const focusedApp = this.props.location.query.app;
return layout.app === focusedApp; if (focusedApp) {
} return layout.app === focusedApp;
return host.apps && host.apps.includes(layout.app); }
return host.apps && host.apps.includes(layout.app) && measurements.includes(layout.measurement);
});
this.setState({layouts: filteredLayouts});
}); });
this.setState({layouts: filteredLayouts});
}); });
}); });
}); });