2023-01-23 17:12:56 -06:00
|
|
|
import { Field, FieldType, PanelOptionsEditorBuilder, DataFrame } from '@grafana/data';
|
|
|
|
import { FrameGeometrySource, FrameGeometrySourceMode } from '@grafana/schema';
|
2022-01-13 19:15:31 -06:00
|
|
|
import { GazetteerPathEditor } from 'app/features/geo/editor/GazetteerPathEditor';
|
|
|
|
|
2022-11-22 13:24:56 -06:00
|
|
|
import { LocationModeEditor } from './locationModeEditor';
|
|
|
|
|
2022-01-13 19:15:31 -06:00
|
|
|
export function addLocationFields<TOptions>(
|
2022-01-21 16:27:26 -06:00
|
|
|
title: string,
|
2022-01-13 19:15:31 -06:00
|
|
|
prefix: string,
|
2022-11-22 13:24:56 -06:00
|
|
|
builder: PanelOptionsEditorBuilder<TOptions>, // ??? Perhaps pass in the filtered data?
|
|
|
|
source?: FrameGeometrySource,
|
|
|
|
data?: DataFrame[]
|
2022-01-13 19:15:31 -06:00
|
|
|
) {
|
2022-11-22 13:24:56 -06:00
|
|
|
builder.addCustomEditor({
|
|
|
|
id: 'modeEditor',
|
2022-01-21 16:27:26 -06:00
|
|
|
path: `${prefix}mode`,
|
2022-11-22 13:24:56 -06:00
|
|
|
name: 'Location Mode',
|
|
|
|
editor: LocationModeEditor,
|
|
|
|
settings: { data, source },
|
2022-01-13 19:15:31 -06:00
|
|
|
});
|
|
|
|
|
2022-11-22 13:24:56 -06:00
|
|
|
// TODO apply data filter to field pickers
|
2022-01-13 19:15:31 -06:00
|
|
|
switch (source?.mode) {
|
|
|
|
case FrameGeometrySourceMode.Coords:
|
|
|
|
builder
|
|
|
|
.addFieldNamePicker({
|
2022-01-21 16:27:26 -06:00
|
|
|
path: `${prefix}latitude`,
|
2022-01-13 19:15:31 -06:00
|
|
|
name: 'Latitude field',
|
|
|
|
settings: {
|
|
|
|
filter: (f: Field) => f.type === FieldType.number,
|
|
|
|
noFieldsMessage: 'No numeric fields found',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addFieldNamePicker({
|
2022-01-21 16:27:26 -06:00
|
|
|
path: `${prefix}longitude`,
|
2022-01-13 19:15:31 -06:00
|
|
|
name: 'Longitude field',
|
|
|
|
settings: {
|
|
|
|
filter: (f: Field) => f.type === FieldType.number,
|
|
|
|
noFieldsMessage: 'No numeric fields found',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FrameGeometrySourceMode.Geohash:
|
|
|
|
builder.addFieldNamePicker({
|
2022-08-22 16:12:21 -05:00
|
|
|
path: `${prefix}geohash`,
|
2022-01-13 19:15:31 -06:00
|
|
|
name: 'Geohash field',
|
|
|
|
settings: {
|
|
|
|
filter: (f: Field) => f.type === FieldType.string,
|
|
|
|
noFieldsMessage: 'No strings fields found',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FrameGeometrySourceMode.Lookup:
|
|
|
|
builder
|
|
|
|
.addFieldNamePicker({
|
2022-01-21 16:27:26 -06:00
|
|
|
path: `${prefix}lookup`,
|
2022-01-13 19:15:31 -06:00
|
|
|
name: 'Lookup field',
|
|
|
|
settings: {
|
|
|
|
filter: (f: Field) => f.type === FieldType.string,
|
|
|
|
noFieldsMessage: 'No strings fields found',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.addCustomEditor({
|
|
|
|
id: 'gazetteer',
|
2022-01-21 16:27:26 -06:00
|
|
|
path: `${prefix}gazetteer`,
|
2022-01-13 19:15:31 -06:00
|
|
|
name: 'Gazetteer',
|
|
|
|
editor: GazetteerPathEditor,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|