mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
This commit is contained in:
parent
593423bd46
commit
823c75f3bd
3 changed files with 82 additions and 22 deletions
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
EuiSelect,
|
||||
EuiFormRow,
|
||||
} from '@elastic/eui';
|
||||
|
||||
const NO_REGIONMAP_LAYERS_MSG =
|
||||
'No vector layers are available.' +
|
||||
' Contact your system administrator to enable vector layers by setting "map.regionmap" in kibana.yml.';
|
||||
|
||||
export function CreateSourceEditor({ onSelect, regionmapLayers }) {
|
||||
|
||||
const regionmapOptions = regionmapLayers.map(({ name, url }) => {
|
||||
return {
|
||||
value: url,
|
||||
text: name
|
||||
};
|
||||
});
|
||||
|
||||
const onChange = ({ target }) => {
|
||||
const selectedName = target.options[target.selectedIndex].text;
|
||||
onSelect({ name: selectedName });
|
||||
};
|
||||
|
||||
return (
|
||||
<EuiFormRow
|
||||
label="Vector layer"
|
||||
helpText={regionmapLayers.length === 0 ? NO_REGIONMAP_LAYERS_MSG : null}
|
||||
>
|
||||
<EuiSelect
|
||||
hasNoInitialSelection
|
||||
options={regionmapOptions}
|
||||
onChange={onChange}
|
||||
disabled={regionmapLayers.length === 0}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
);
|
||||
}
|
||||
|
||||
CreateSourceEditor.propTypes = {
|
||||
onSelect: PropTypes.func.isRequired,
|
||||
regionmapLayers: PropTypes.arrayOf(PropTypes.shape({
|
||||
url: PropTypes.string.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
})),
|
||||
};
|
||||
|
||||
CreateSourceEditor.defaultProps = {
|
||||
regionmapLayers: [],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export { KibanaRegionmapSource } from './kibana_regionmap_source';
|
|
@ -4,14 +4,14 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { VectorSource } from './vector_source';
|
||||
import _ from 'lodash';
|
||||
import { VectorSource } from '../vector_source';
|
||||
import React, { Fragment } from 'react';
|
||||
import {
|
||||
EuiText,
|
||||
EuiSelect,
|
||||
EuiFormRow,
|
||||
EuiSpacer
|
||||
} from '@elastic/eui';
|
||||
import { CreateSourceEditor } from './create_source_editor';
|
||||
|
||||
export class KibanaRegionmapSource extends VectorSource {
|
||||
|
||||
|
@ -23,35 +23,27 @@ export class KibanaRegionmapSource extends VectorSource {
|
|||
this._regionList = ymlFileLayers;
|
||||
}
|
||||
|
||||
static createDescriptor(name) {
|
||||
static createDescriptor(options) {
|
||||
return {
|
||||
type: KibanaRegionmapSource.type,
|
||||
name: name
|
||||
name: options.name
|
||||
};
|
||||
}
|
||||
|
||||
static renderEditor = ({ dataSourcesMeta, onPreviewSource }) => {
|
||||
const regionmapOptionsRaw = (dataSourcesMeta) ? dataSourcesMeta.kibana.regionmap : [];
|
||||
const regionmapOptions = regionmapOptionsRaw ? regionmapOptionsRaw.map((file) => ({
|
||||
value: file.url,
|
||||
text: file.name
|
||||
})) : [];
|
||||
const regionmapLayers = _.get(dataSourcesMeta, 'kibana.regionmap', []);
|
||||
|
||||
const onChange = ({ target }) => {
|
||||
const selectedName = target.options[target.selectedIndex].text;
|
||||
const kibanaRegionmapSourceDescriptor = KibanaRegionmapSource.createDescriptor(selectedName);
|
||||
const kibanaRegionmapSource = new KibanaRegionmapSource(kibanaRegionmapSourceDescriptor, regionmapOptionsRaw);
|
||||
onPreviewSource(kibanaRegionmapSource);
|
||||
const onSelect = (layerConfig) => {
|
||||
const sourceDescriptor = KibanaRegionmapSource.createDescriptor(layerConfig);
|
||||
const source = new KibanaRegionmapSource(sourceDescriptor, { ymlFileLayers: regionmapLayers });
|
||||
onPreviewSource(source);
|
||||
};
|
||||
|
||||
return (
|
||||
<EuiFormRow label="File">
|
||||
<EuiSelect
|
||||
hasNoInitialSelection
|
||||
options={regionmapOptions}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<CreateSourceEditor
|
||||
onSelect={onSelect}
|
||||
regionmapLayers={regionmapLayers}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -105,4 +97,8 @@ export class KibanaRegionmapSource extends VectorSource {
|
|||
async isTimeAware() {
|
||||
return false;
|
||||
}
|
||||
|
||||
canFormatFeatureProperties() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue