USAQueryEditor.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import React from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { InlineFieldRow, InlineField, Select, MultiSelect, Input } from '@grafana/ui';
  4. import { USAQuery } from '../types';
  5. export interface Props {
  6. onChange: (value: USAQuery) => void;
  7. query: USAQuery;
  8. }
  9. export function USAQueryEditor({ query, onChange }: Props) {
  10. return (
  11. <>
  12. <InlineFieldRow>
  13. <InlineField labelWidth={14} label="Mode">
  14. <Select
  15. options={usaQueryModes}
  16. onChange={(v) => {
  17. onChange({ ...query, mode: v.value });
  18. }}
  19. width={32}
  20. value={usaQueryModes.find((ep) => ep.value === query.mode)}
  21. />
  22. </InlineField>
  23. <InlineField label="Period">
  24. <Input
  25. value={query.period}
  26. placeholder={'30m'}
  27. onChange={(v) => {
  28. onChange({ ...query, period: v.currentTarget.value });
  29. }}
  30. />
  31. </InlineField>
  32. </InlineFieldRow>
  33. <InlineFieldRow>
  34. <InlineField labelWidth={14} label="Fields">
  35. <MultiSelect
  36. options={fieldNames}
  37. onChange={(vals: SelectableValue[]) => {
  38. onChange({ ...query, fields: vals.map((v) => v.value) });
  39. }}
  40. width={32}
  41. placeholder="all"
  42. value={query.fields}
  43. />
  44. </InlineField>
  45. <InlineField label="States" grow>
  46. <MultiSelect
  47. options={stateNames}
  48. onChange={(vals: SelectableValue[]) => {
  49. onChange({ ...query, states: vals.map((v) => v.value) });
  50. }}
  51. placeholder="all"
  52. value={query.states}
  53. />
  54. </InlineField>
  55. </InlineFieldRow>
  56. </>
  57. );
  58. }
  59. export const usaQueryModes = [
  60. 'values-as-rows',
  61. 'values-as-fields',
  62. 'values-as-labeled-fields',
  63. 'timeseries',
  64. 'timeseries-wide',
  65. ].map((f) => ({ label: f, value: f }));
  66. export const fieldNames = [
  67. 'foo',
  68. 'bar',
  69. 'baz', // all short
  70. ].map((f) => ({ label: f, value: f }));
  71. export const stateNames = [
  72. 'AL',
  73. 'AK',
  74. 'AZ',
  75. 'AR',
  76. 'CA',
  77. 'CO',
  78. 'CT',
  79. 'DE',
  80. 'DC',
  81. 'FL',
  82. 'GA',
  83. 'HI',
  84. 'ID',
  85. 'IL',
  86. 'IN',
  87. 'IA',
  88. 'KS',
  89. 'KY',
  90. 'LA',
  91. 'ME',
  92. 'MT',
  93. 'NE',
  94. 'NV',
  95. 'NH',
  96. 'NJ',
  97. 'NM',
  98. 'NY',
  99. 'NC',
  100. 'ND',
  101. 'OH',
  102. 'OK',
  103. 'OR',
  104. 'MD',
  105. 'MA',
  106. 'MI',
  107. 'MN',
  108. 'MS',
  109. 'MO',
  110. 'PA',
  111. 'RI',
  112. 'SC',
  113. 'SD',
  114. 'TN',
  115. 'TX',
  116. 'UT',
  117. 'VT',
  118. 'VA',
  119. 'WA',
  120. 'WV',
  121. 'WI',
  122. 'WY',
  123. ].map((f) => ({ label: f, value: f }));