import { css } from '@emotion/css'; import React, { useEffect, useState } from 'react'; import { GrafanaTheme } from '@grafana/data'; import { getBackendSrv } from '@grafana/runtime'; import { Tag, useStyles, IconButton } from '@grafana/ui'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { RuleModal } from './RuleModal'; import { Rule, Output, RuleType } from './types'; function renderOutputTags(key: string, output?: Output): React.ReactNode { if (!output?.type) { return null; } return ; } interface Props { rules: Rule[]; onRuleChanged: () => void; selectRule?: Rule; } export const PipelineTable: React.FC = (props) => { const { rules } = props; const [isOpen, setOpen] = useState(false); const [selectedRule, setSelectedRule] = useState(); const [clickColumn, setClickColumn] = useState('converter'); const styles = useStyles(getStyles); const onRowClick = (rule: Rule, event?: any) => { if (!rule) { return; } let column = event?.target?.getAttribute('data-column'); if (!column || column === 'pattern') { column = 'converter'; } setClickColumn(column); setSelectedRule(rule); setOpen(true); }; // Supports selecting a rule from external config (after add rule) useEffect(() => { if (props.selectRule) { onRowClick(props.selectRule); } }, [props.selectRule]); const onRemoveRule = (pattern: string) => { getBackendSrv() .delete(`api/live/channel-rules`, JSON.stringify({ pattern: pattern })) .catch((e) => console.error(e)) .finally(() => { props.onRuleChanged(); }); }; const renderPattern = (pattern: string) => { if (pattern.startsWith('ds/')) { const idx = pattern.indexOf('/', 4); if (idx > 3) { const uid = pattern.substring(3, idx); const ds = getDatasourceSrv().getInstanceSettings(uid); if (ds) { return (
  {pattern.substring(idx + 1)}
); } } } return pattern; }; return (
{rules.map((rule) => ( onRowClick(rule, e)} className={styles.row}> ))}
Channel Converter Processor Output  
{renderPattern(rule.pattern)} {rule.settings?.converter?.type} {rule.settings?.frameProcessors?.map((processor) => ( {processor.type} ))} {rule.settings?.frameOutputs?.map((output) => ( {renderOutputTags('out', output)} ))} { e.stopPropagation(); onRemoveRule(rule.pattern); }} >
{isOpen && selectedRule && ( { setOpen(false); }} clickColumn={clickColumn} /> )}
); }; const getStyles = (theme: GrafanaTheme) => { return { row: css` cursor: pointer; `, }; };