update AlertTabs to only show tabs for services supported by current kapacitor
parent
27a4357db2
commit
929a253627
|
@ -8,6 +8,7 @@ import {
|
||||||
getKapacitorConfig,
|
getKapacitorConfig,
|
||||||
updateKapacitorConfigSection,
|
updateKapacitorConfigSection,
|
||||||
testAlertOutput,
|
testAlertOutput,
|
||||||
|
getAllServices,
|
||||||
} from 'shared/apis'
|
} from 'shared/apis'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -38,11 +39,15 @@ class AlertTabs extends Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
configSections: null,
|
configSections: null,
|
||||||
|
services: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
async componentDidMount() {
|
||||||
this.refreshKapacitorConfig(this.props.kapacitor)
|
this.refreshKapacitorConfig(this.props.kapacitor)
|
||||||
|
const services = await getAllServices(this.props.kapacitor)
|
||||||
|
|
||||||
|
this.setState({services})
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
|
@ -132,7 +137,7 @@ class AlertTabs extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {configSections} = this.state
|
const {configSections, services} = this.state
|
||||||
const {hash} = this.props
|
const {hash} = this.props
|
||||||
|
|
||||||
if (!configSections) {
|
if (!configSections) {
|
||||||
|
@ -285,8 +290,11 @@ class AlertTabs extends Component {
|
||||||
<TabList customClass="config-endpoint--tabs">
|
<TabList customClass="config-endpoint--tabs">
|
||||||
{_.reduce(
|
{_.reduce(
|
||||||
configSections,
|
configSections,
|
||||||
(acc, _cur, k) =>
|
(acc, _cur, k) => {
|
||||||
supportedConfigs[k]
|
return supportedConfigs[k] &&
|
||||||
|
services.find(service => {
|
||||||
|
return service.name === _.toLower(supportedConfigs[k].type)
|
||||||
|
})
|
||||||
? acc.concat(
|
? acc.concat(
|
||||||
<Tab
|
<Tab
|
||||||
key={supportedConfigs[k].type}
|
key={supportedConfigs[k].type}
|
||||||
|
@ -295,7 +303,8 @@ class AlertTabs extends Component {
|
||||||
{supportedConfigs[k].type}
|
{supportedConfigs[k].type}
|
||||||
</Tab>
|
</Tab>
|
||||||
)
|
)
|
||||||
: acc,
|
: acc
|
||||||
|
},
|
||||||
[]
|
[]
|
||||||
)}
|
)}
|
||||||
</TabList>
|
</TabList>
|
||||||
|
|
|
@ -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) {
|
export function createKapacitorTask(kapacitor, id, type, dbrps, script) {
|
||||||
return kapacitorProxy(kapacitor, 'POST', '/kapacitor/v1/tasks', {
|
return kapacitorProxy(kapacitor, 'POST', '/kapacitor/v1/tasks', {
|
||||||
id,
|
id,
|
||||||
|
|
Loading…
Reference in New Issue