Merge pull request #601 from influxdata/measurement-present
Fix layout being displayed when measurement not presentpull/10616/head
commit
6e8c55e4b4
|
@ -81,3 +81,28 @@ export function getAppsForHosts(proxyLink, hosts, appMappings, telegrafDB) {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, {PropTypes} from 'react';
|
|||
import LayoutRenderer from 'shared/components/LayoutRenderer';
|
||||
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
|
||||
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';
|
||||
|
||||
export const HostPage = React.createClass({
|
||||
|
@ -33,25 +33,28 @@ export const HostPage = React.createClass({
|
|||
},
|
||||
|
||||
componentDidMount() {
|
||||
const hosts = {[this.props.params.hostID]: {name: this.props.params.hostID}};
|
||||
const {source} = this.props;
|
||||
const {source, params} = this.props;
|
||||
const hosts = {[params.hostID]: {name: params.hostID}};
|
||||
|
||||
// fetching layouts and mappings can be done at the same time
|
||||
fetchLayouts().then(({data: {layouts}}) => {
|
||||
getMappings().then(({data: {mappings}}) => {
|
||||
getAppsForHosts(source.links.proxy, hosts, mappings, source.telegraf).then((newHosts) => {
|
||||
getMeasurementsForHost(source, params.hostID).then((measurements) => {
|
||||
const host = newHosts[this.props.params.hostID];
|
||||
const filteredLayouts = layouts.filter((layout) => {
|
||||
const focusedApp = this.props.location.query.app;
|
||||
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});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
handleChooseTimeRange({lower}) {
|
||||
|
|
Loading…
Reference in New Issue