[Maps] add empty state for 'Custom vector shapes' source (#28598) (#28627)

This commit is contained in:
Nathan Reese 2019-01-12 07:51:02 -07:00 committed by GitHub
parent 593423bd46
commit 823c75f3bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 22 deletions

View file

@ -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: [],
};

View file

@ -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';

View file

@ -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;
}
}