update AlertTabs to only show tabs for services supported by current kapacitor

pull/3290/head
Iris Scholten 2018-03-27 18:05:06 -07:00
parent 27a4357db2
commit 929a253627
2 changed files with 27 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import {
getKapacitorConfig,
updateKapacitorConfigSection,
testAlertOutput,
getAllServices,
} from 'shared/apis'
import {
@ -38,11 +39,15 @@ class AlertTabs extends Component {
this.state = {
configSections: null,
services: [],
}
}
componentDidMount() {
async componentDidMount() {
this.refreshKapacitorConfig(this.props.kapacitor)
const services = await getAllServices(this.props.kapacitor)
this.setState({services})
}
componentWillReceiveProps(nextProps) {
@ -132,7 +137,7 @@ class AlertTabs extends Component {
}
render() {
const {configSections} = this.state
const {configSections, services} = this.state
const {hash} = this.props
if (!configSections) {
@ -285,8 +290,11 @@ class AlertTabs extends Component {
<TabList customClass="config-endpoint--tabs">
{_.reduce(
configSections,
(acc, _cur, k) =>
supportedConfigs[k]
(acc, _cur, k) => {
return supportedConfigs[k] &&
services.find(service => {
return service.name === _.toLower(supportedConfigs[k].type)
})
? acc.concat(
<Tab
key={supportedConfigs[k].type}
@ -295,7 +303,8 @@ class AlertTabs extends Component {
{supportedConfigs[k].type}
</Tab>
)
: acc,
: acc
},
[]
)}
</TabList>

View File

@ -185,6 +185,19 @@ export const testAlertOutput = async (kapacitor, outputName) => {
}
}
export const getAllServices = async kapacitor => {
try {
const {data: {services}} = await kapacitorProxy(
kapacitor,
'GET',
'/kapacitor/v1/service-tests'
)
return services
} catch (error) {
console.error(error)
}
}
export function createKapacitorTask(kapacitor, id, type, dbrps, script) {
return kapacitorProxy(kapacitor, 'POST', '/kapacitor/v1/tasks', {
id,