import { css } from '@emotion/css'; import { useEffect, useMemo, useState } from 'react'; import { LiveChannelScope, LiveChannelAddress, SelectableValue, StandardEditorProps, GrafanaTheme2, parseLiveChannelAddress, } from '@grafana/data'; import { Select, Alert, Label, stylesFactory } from '@grafana/ui'; import { config } from 'app/core/config'; import { getManagedChannelInfo } from 'app/features/live/info'; import { LivePanelOptions } from './types'; type Props = StandardEditorProps, {}, LivePanelOptions>; const scopes: Array> = [ { label: 'Grafana', value: LiveChannelScope.Grafana, description: 'Core grafana live features' }, { label: 'Data Sources', value: LiveChannelScope.DataSource, description: 'Data sources with live support' }, { label: 'Plugins', value: LiveChannelScope.Plugin, description: 'Plugins with live support' }, { label: 'Stream', value: LiveChannelScope.Stream, description: 'data streams (eg, influx style)' }, ]; export function LiveChannelEditor(props: Props) { const [channels, setChannels] = useState>>([]); const [namespaces, paths] = useMemo(() => { const namespaces: Array> = []; const paths: Array> = []; const scope = props.value.scope; const namespace = props.value.namespace; if (!scope?.length) { return [namespaces, paths]; } const used: Record = {}; for (let channel of channels) { const addr = parseLiveChannelAddress(channel.value); if (!addr || addr.scope !== scope) { continue; } if (!used[addr.namespace]) { namespaces.push({ value: addr.namespace, label: addr.namespace, }); used[addr.namespace] = true; } if (namespace?.length && namespace === addr.namespace) { paths.push({ ...channel, value: addr.path, }); } } return [namespaces, paths]; }, [channels, props.value.scope, props.value.namespace]); useEffect(() => { getManagedChannelInfo().then((v) => { setChannels(v.channels); }); }, [props.value.scope]); const onScopeChanged = (v: SelectableValue) => { if (v.value) { props.onChange({ scope: v.value, namespace: undefined, path: undefined, }); } }; const onNamespaceChanged = (v: SelectableValue) => { props.onChange({ scope: props.value?.scope, namespace: v?.value, path: undefined, }); }; const onPathChanged = (v: SelectableValue) => { const { value, onChange } = props; onChange({ scope: value.scope, namespace: value.namespace, path: v?.value, }); }; const { scope, namespace, path } = props.value; const style = getStyles(config.theme2); return ( <> This supports real-time event streams in grafana core. This feature is under heavy development. Expect the intefaces and structures to change as this becomes more production ready.
s.value === namespace) ?? (namespace ? { label: namespace, value: namespace } : undefined) } onChange={onNamespaceChanged} allowCustomValue={true} backspaceRemovesValue={true} isClearable={true} />
)} {scope && namespace && (