import React, { useEffect, useState, ChangeEvent } from 'react'; import { getBackendSrv } from '@grafana/runtime'; import { Input } from '@grafana/ui'; import Page from 'app/core/components/Page/Page'; import { useNavModel } from 'app/core/hooks/useNavModel'; import { AddNewRule } from './AddNewRule'; import { PipelineTable } from './PipelineTable'; import { Rule } from './types'; export default function PipelineAdminPage() { const [rules, setRules] = useState([]); const [defaultRules, setDefaultRules] = useState([]); const [newRule, setNewRule] = useState(); const navModel = useNavModel('live-pipeline'); const [error, setError] = useState(); const loadRules = () => { getBackendSrv() .get(`api/live/channel-rules`) .then((data) => { setRules(data.rules ?? []); setDefaultRules(data.rules ?? []); }) .catch((e) => { if (e.data) { setError(JSON.stringify(e.data, null, 2)); } }); }; useEffect(() => { loadRules(); }, []); const onSearchQueryChange = (e: ChangeEvent) => { if (e.target.value) { setRules(rules.filter((rule) => rule.pattern.toLowerCase().includes(e.target.value.toLowerCase()))); } else { setRules(defaultRules); } }; return ( {error &&
{error}
}
{ console.log('GOT', r, 'vs', rules[0]); setNewRule(r); loadRules(); }} />
); }