import { css } from '@emotion/css'; import React, { useState, FormEvent } from 'react'; import { GrafanaTheme2, SelectableValue } from '@grafana/data'; import { HorizontalGroup, Icon, InlineField, InlineFieldRow, InlineSwitch, Input, Select, useStyles2, } from '@grafana/ui'; import * as c from '../../constants'; import { ZabbixQueryOptions } from '../../types'; const ackOptions: Array> = [ { label: 'all triggers', value: 2 }, { label: 'unacknowledged', value: 0 }, { label: 'acknowledged', value: 1 }, ]; const sortOptions: Array> = [ { label: 'Default', value: 'default' }, { label: 'Last change', value: 'lastchange' }, { label: 'Severity', value: 'severity' }, ]; const trendsOptions: Array> = [ { label: 'Default', value: 'default' }, { label: 'True', value: 'true' }, { label: 'False', value: 'false' }, ]; interface Props { queryType: string; queryOptions: ZabbixQueryOptions; onChange: (options: ZabbixQueryOptions) => void; } export const QueryOptionsEditor = ({ queryType, queryOptions, onChange }: Props) => { const [isOpen, setIsOpen] = useState(false); const styles = useStyles2(getStyles); const onLimitChange = (v: FormEvent) => { const newValue = Number(v?.currentTarget?.value); if (newValue !== null) { onChange({ ...queryOptions, limit: newValue }); } }; const onPropChange = (prop: string) => { return (option: SelectableValue) => { if (option.value !== null) { onChange({ ...queryOptions, [prop]: option.value }); } }; }; const renderClosed = () => { return ( <> {!isOpen && } {isOpen && } Options
{renderOptions()}
); }; const renderOptions = () => { const elements: JSX.Element[] = []; for (const key in queryOptions) { if (queryOptions.hasOwnProperty(key)) { const value = queryOptions[key]; if (value === true && value !== '' && value !== null && value !== undefined) { elements.push({`${key} = ${value}`}); } } } return elements; }; const renderEditor = () => { return (
{queryType === c.MODE_METRICS && renderMetricOptions()} {queryType === c.MODE_ITEMID && renderMetricOptions()} {queryType === c.MODE_ITSERVICE && renderMetricOptions()} {queryType === c.MODE_TEXT && renderTextMetricsOptions()} {queryType === c.MODE_PROBLEMS && renderProblemsOptions()} {queryType === c.MODE_TRIGGERS && renderTriggersOptions()}
); }; const renderMetricOptions = () => { return ( <> ); }; const renderTriggersOptions = () => { return ( <>