123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import React from 'react';
- import { SelectableValue } from '@grafana/data';
- import { InlineFieldRow, InlineField, Select, MultiSelect, Input } from '@grafana/ui';
- import { USAQuery } from '../types';
- export interface Props {
- onChange: (value: USAQuery) => void;
- query: USAQuery;
- }
- export function USAQueryEditor({ query, onChange }: Props) {
- return (
- <>
- <InlineFieldRow>
- <InlineField labelWidth={14} label="Mode">
- <Select
- options={usaQueryModes}
- onChange={(v) => {
- onChange({ ...query, mode: v.value });
- }}
- width={32}
- value={usaQueryModes.find((ep) => ep.value === query.mode)}
- />
- </InlineField>
- <InlineField label="Period">
- <Input
- value={query.period}
- placeholder={'30m'}
- onChange={(v) => {
- onChange({ ...query, period: v.currentTarget.value });
- }}
- />
- </InlineField>
- </InlineFieldRow>
- <InlineFieldRow>
- <InlineField labelWidth={14} label="Fields">
- <MultiSelect
- options={fieldNames}
- onChange={(vals: SelectableValue[]) => {
- onChange({ ...query, fields: vals.map((v) => v.value) });
- }}
- width={32}
- placeholder="all"
- value={query.fields}
- />
- </InlineField>
- <InlineField label="States" grow>
- <MultiSelect
- options={stateNames}
- onChange={(vals: SelectableValue[]) => {
- onChange({ ...query, states: vals.map((v) => v.value) });
- }}
- placeholder="all"
- value={query.states}
- />
- </InlineField>
- </InlineFieldRow>
- </>
- );
- }
- export const usaQueryModes = [
- 'values-as-rows',
- 'values-as-fields',
- 'values-as-labeled-fields',
- 'timeseries',
- 'timeseries-wide',
- ].map((f) => ({ label: f, value: f }));
- export const fieldNames = [
- 'foo',
- 'bar',
- 'baz', // all short
- ].map((f) => ({ label: f, value: f }));
- export const stateNames = [
- 'AL',
- 'AK',
- 'AZ',
- 'AR',
- 'CA',
- 'CO',
- 'CT',
- 'DE',
- 'DC',
- 'FL',
- 'GA',
- 'HI',
- 'ID',
- 'IL',
- 'IN',
- 'IA',
- 'KS',
- 'KY',
- 'LA',
- 'ME',
- 'MT',
- 'NE',
- 'NV',
- 'NH',
- 'NJ',
- 'NM',
- 'NY',
- 'NC',
- 'ND',
- 'OH',
- 'OK',
- 'OR',
- 'MD',
- 'MA',
- 'MI',
- 'MN',
- 'MS',
- 'MO',
- 'PA',
- 'RI',
- 'SC',
- 'SD',
- 'TN',
- 'TX',
- 'UT',
- 'VT',
- 'VA',
- 'WA',
- 'WV',
- 'WI',
- 'WY',
- ].map((f) => ({ label: f, value: f }));
|