locationEditor.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. Field,
  3. FieldType,
  4. FrameGeometrySource,
  5. FrameGeometrySourceMode,
  6. PanelOptionsEditorBuilder,
  7. } from '@grafana/data';
  8. import { GazetteerPathEditor } from 'app/features/geo/editor/GazetteerPathEditor';
  9. export function addLocationFields<TOptions>(
  10. title: string,
  11. prefix: string,
  12. builder: PanelOptionsEditorBuilder<TOptions>,
  13. source?: FrameGeometrySource
  14. ) {
  15. builder.addRadio({
  16. path: `${prefix}mode`,
  17. name: title,
  18. description: '',
  19. defaultValue: FrameGeometrySourceMode.Auto,
  20. settings: {
  21. options: [
  22. { value: FrameGeometrySourceMode.Auto, label: 'Auto' },
  23. { value: FrameGeometrySourceMode.Coords, label: 'Coords' },
  24. { value: FrameGeometrySourceMode.Geohash, label: 'Geohash' },
  25. { value: FrameGeometrySourceMode.Lookup, label: 'Lookup' },
  26. ],
  27. },
  28. });
  29. switch (source?.mode) {
  30. case FrameGeometrySourceMode.Coords:
  31. builder
  32. .addFieldNamePicker({
  33. path: `${prefix}latitude`,
  34. name: 'Latitude field',
  35. settings: {
  36. filter: (f: Field) => f.type === FieldType.number,
  37. noFieldsMessage: 'No numeric fields found',
  38. },
  39. })
  40. .addFieldNamePicker({
  41. path: `${prefix}longitude`,
  42. name: 'Longitude field',
  43. settings: {
  44. filter: (f: Field) => f.type === FieldType.number,
  45. noFieldsMessage: 'No numeric fields found',
  46. },
  47. });
  48. break;
  49. case FrameGeometrySourceMode.Geohash:
  50. builder.addFieldNamePicker({
  51. path: `${prefix}.geohash`,
  52. name: 'Geohash field',
  53. settings: {
  54. filter: (f: Field) => f.type === FieldType.string,
  55. noFieldsMessage: 'No strings fields found',
  56. },
  57. });
  58. break;
  59. case FrameGeometrySourceMode.Lookup:
  60. builder
  61. .addFieldNamePicker({
  62. path: `${prefix}lookup`,
  63. name: 'Lookup field',
  64. settings: {
  65. filter: (f: Field) => f.type === FieldType.string,
  66. noFieldsMessage: 'No strings fields found',
  67. },
  68. })
  69. .addCustomEditor({
  70. id: 'gazetteer',
  71. path: `${prefix}gazetteer`,
  72. name: 'Gazetteer',
  73. editor: GazetteerPathEditor,
  74. });
  75. }
  76. }