import { css } from '@emotion/css'; import React, { PureComponent } from 'react'; import { LiveChannelScope, LiveChannelAddress, SelectableValue, StandardEditorProps, GrafanaTheme, } from '@grafana/data'; import { Select, Alert, Label, stylesFactory } from '@grafana/ui'; import { config } from 'app/core/config'; import { LivePanelOptions } from './types'; type Props = StandardEditorProps; 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' }, ]; interface State { namespaces: Array>; paths: Array>; } export class LiveChannelEditor extends PureComponent { state: State = { namespaces: [], paths: [], }; async componentDidMount() { this.updateSelectOptions(); } async componentDidUpdate(oldProps: Props) { if (this.props.value !== oldProps.value) { this.updateSelectOptions(); } } async updateSelectOptions() { this.setState({ namespaces: [], paths: [], }); } onScopeChanged = (v: SelectableValue) => { if (v.value) { this.props.onChange({ scope: v.value, namespace: undefined as unknown as string, path: undefined as unknown as string, } as LiveChannelAddress); } }; onNamespaceChanged = (v: SelectableValue) => { const update = { scope: this.props.value?.scope, path: undefined as unknown as string, } as LiveChannelAddress; if (v.value) { update.namespace = v.value; } this.props.onChange(update); }; onPathChanged = (v: SelectableValue) => { const { value, onChange } = this.props; const update = { scope: value.scope, namespace: value.namespace, } as LiveChannelAddress; if (v.value) { update.path = v.value; } onChange(update); }; render() { const { namespaces, paths } = this.state; const { scope, namespace, path } = this.props.value; const style = getStyles(config.theme); 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={this.onNamespaceChanged} allowCustomValue={true} backspaceRemovesValue={true} />
)} {scope && namespace && (