grafana/public/app/features/geo/editor/locationEditor.ts
Drew Slobodnjak ee8f292c6a
Geomap: Improve location editor (#58017)
* add custom component for location editor

* FC cleanup

* Apply filter to add location fields call

* Create custom editor for location mode

* Apply validation logic and render warning

* Improve alert styling

* Add help url button to location alert

* Add success alert for auto

* Remove completed TODOs

* Only use alert on error, not success

* Change location mode to dropdown

* Change alert severity to less severe, info

* Prevent auto field selection during manual

* Update location testing to be for auto mode

* Run geo transformer editor init once

* Fix breaking test

* Clean up some anys

* Update styling for alert

* Remove auto success styling

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
2022-11-22 11:24:56 -08:00

79 lines
2.1 KiB
TypeScript

import {
Field,
FieldType,
FrameGeometrySource,
FrameGeometrySourceMode,
PanelOptionsEditorBuilder,
DataFrame,
} from '@grafana/data';
import { GazetteerPathEditor } from 'app/features/geo/editor/GazetteerPathEditor';
import { LocationModeEditor } from './locationModeEditor';
export function addLocationFields<TOptions>(
title: string,
prefix: string,
builder: PanelOptionsEditorBuilder<TOptions>, // ??? Perhaps pass in the filtered data?
source?: FrameGeometrySource,
data?: DataFrame[]
) {
builder.addCustomEditor({
id: 'modeEditor',
path: `${prefix}mode`,
name: 'Location Mode',
editor: LocationModeEditor,
settings: { data, source },
});
// TODO apply data filter to field pickers
switch (source?.mode) {
case FrameGeometrySourceMode.Coords:
builder
.addFieldNamePicker({
path: `${prefix}latitude`,
name: 'Latitude field',
settings: {
filter: (f: Field) => f.type === FieldType.number,
noFieldsMessage: 'No numeric fields found',
},
})
.addFieldNamePicker({
path: `${prefix}longitude`,
name: 'Longitude field',
settings: {
filter: (f: Field) => f.type === FieldType.number,
noFieldsMessage: 'No numeric fields found',
},
});
break;
case FrameGeometrySourceMode.Geohash:
builder.addFieldNamePicker({
path: `${prefix}geohash`,
name: 'Geohash field',
settings: {
filter: (f: Field) => f.type === FieldType.string,
noFieldsMessage: 'No strings fields found',
},
});
break;
case FrameGeometrySourceMode.Lookup:
builder
.addFieldNamePicker({
path: `${prefix}lookup`,
name: 'Lookup field',
settings: {
filter: (f: Field) => f.type === FieldType.string,
noFieldsMessage: 'No strings fields found',
},
})
.addCustomEditor({
id: 'gazetteer',
path: `${prefix}gazetteer`,
name: 'Gazetteer',
editor: GazetteerPathEditor,
});
}
}