Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vis: Default editor] EUIficate region map options tab #42944

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0053254
EUIficate region_map_options
sulemanof Aug 7, 2019
1ad6842
Merge branch 'master' into EUIfication/options/region_map_options
sulemanof Aug 7, 2019
b86a25f
Euificate region_map_options
sulemanof Aug 8, 2019
38a3726
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 8, 2019
52f9c51
Reuse types
sulemanof Aug 8, 2019
7792e57
Fix typo
sulemanof Aug 8, 2019
763e69c
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 9, 2019
34519cc
Remove wms_options directive
sulemanof Aug 9, 2019
77a903c
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 9, 2019
77de0cb
Remove style import
sulemanof Aug 9, 2019
1ca3b39
Fix failing tests
sulemanof Aug 9, 2019
cc3a5a5
Fix issue with join field default value
sulemanof Aug 9, 2019
4871b4e
Add fullWidth to the number_input
sulemanof Aug 9, 2019
da1844b
Fix comments
sulemanof Aug 12, 2019
01607f0
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 12, 2019
502d6af
Fix comments
sulemanof Aug 12, 2019
1323b9c
Fix comments
sulemanof Aug 14, 2019
0d600ca
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 14, 2019
ffe7904
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 15, 2019
edb4e57
Watch setValue in useCallback
sulemanof Aug 15, 2019
bac218a
Change functional tests
sulemanof Aug 15, 2019
97b5dee
Merge remote-tracking branch 'upstream/master' into EUIfication/optio…
sulemanof Aug 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import { EuiFormRow, EuiFieldNumber } from '@elastic/eui';

interface NumberInputOptionProps<ParamName extends string> {
label?: React.ReactNode;
max?: number;
min?: number;
paramName: ParamName;
value?: number | '';
setValue: (paramName: ParamName, value: number | '') => void;
}

function NumberInputOption<ParamName extends string>({
label,
max,
min,
paramName,
value = '',
setValue,
}: NumberInputOptionProps<ParamName>) {
return (
<EuiFormRow label={label} fullWidth compressed>
<EuiFieldNumber
fullWidth
max={max}
min={min}
value={value}
onChange={ev =>
setValue(paramName, isNaN(ev.target.valueAsNumber) ? '' : ev.target.valueAsNumber)
}
/>
</EuiFormRow>
);
}

export { NumberInputOption };
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ import React from 'react';
import { EuiFormRow, EuiSelect } from '@elastic/eui';

interface SelectOptionProps<ParamName extends string, ValidParamValues extends string> {
id?: string;
label: string;
labelAppend?: React.ReactNode;
options: Array<{ value: ValidParamValues; text: string }>;
paramName: ParamName;
value?: ValidParamValues;
setValue: (paramName: ParamName, value: ValidParamValues) => void;
}

const emptyValue = { text: '', value: 'EMPTY_VALUE', disabled: true, hidden: true };

function SelectOption<ParamName extends string, ValidParamValues extends string>({
id,
label,
labelAppend,
options,
paramName,
value,
setValue,
}: SelectOptionProps<ParamName, ValidParamValues>) {
return (
<EuiFormRow label={label} fullWidth={true} compressed>
<EuiFormRow id={id} label={label} fullWidth={true} compressed labelAppend={labelAppend}>
<EuiSelect
options={options}
value={value}
options={[emptyValue, ...options]}
value={value || emptyValue.value}
onChange={ev => setValue(paramName, ev.target.value as ValidParamValues)}
fullWidth={true}
/>
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/region_map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const regionMapPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyP
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars(server) {
const { regionmap } = server.config().get('map');
Expand Down
4 changes: 0 additions & 4 deletions src/legacy/core_plugins/region_map/public/_region_map.scss

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { useEffect, useState, useCallback } from 'react';
import { EuiIcon, EuiLink, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { toastNotifications } from 'ui/notify';
import { FileLayerField, VectorLayer, ServiceSettings } from 'ui/vis/map/service_settings';
import { VisOptionsProps } from 'ui/vis/editors/default';
import { SelectOption } from '../../../kbn_vislib_vis_types/public/controls/select';
import { SwitchOption } from '../../../kbn_vislib_vis_types/public/controls/switch';
import { NumberInputOption } from '../../../kbn_vislib_vis_types/public/controls/number_input';
import { ORIGIN } from '../../../tile_map/common/origin';
import { WmsOptions } from '../../../tile_map/public/components/wms_options';
import { mapToLayerWithId } from '../util';
import { RegionMapVisParams } from '../types';
import { RegionMapsConfig } from '../plugin';

const mapLayerForOption = ({ layerId, name }: VectorLayer) => ({
text: name,
value: layerId,
});

const mapFieldForOption = ({ description, name }: FileLayerField) => ({
text: description,
value: name,
});

export type RegionMapOptionsProps = {
serviceSettings: ServiceSettings;
regionmapsConfig: RegionMapsConfig;
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
} & VisOptionsProps<RegionMapVisParams>;

function RegionMapOptions(props: RegionMapOptionsProps) {
const { regionmapsConfig, serviceSettings, stateParams, vis, setValue } = props;
const [vectorLayers, setVectorLayers] = useState<VectorLayer[]>(
vis.type.editorConfig.collections.vectorLayers
);
const [vectorLayerOptions, setVectorLayerOptions] = useState(vectorLayers.map(mapLayerForOption));
const [fieldOptions, setFieldOptions] = useState(
((stateParams.selectedLayer && stateParams.selectedLayer.fields) || []).map(mapFieldForOption)
);

const onLayerChange = useCallback(async (selectedLayer: VectorLayer) => {
setFieldOptions(selectedLayer.fields.map(mapFieldForOption));
setValue('selectedJoinField', selectedLayer.fields[0]);
setValue('emsHotLink', null);

if (selectedLayer.isEMS) {
const emsHotLink = await serviceSettings.getEMSHotLink(selectedLayer);
setValue('emsHotLink', emsHotLink);
}
}, []);

useEffect(() => {
if (regionmapsConfig.includeElasticMapsService) {
serviceSettings
.getFileLayers()
.then(layers => {
const newLayers = layers
.map(mapToLayerWithId.bind(null, ORIGIN.EMS))
.filter(
layer => !vectorLayers.some(vectorLayer => vectorLayer.layerId === layer.layerId)
);

newLayers.forEach(layer => {
if (layer.format === 'geojson') {
layer.format = {
type: 'geojson',
};
}
});

const newVectorLayers = [...vectorLayers, ...newLayers];

setVectorLayers(newVectorLayers);
setVectorLayerOptions(newVectorLayers.map(mapLayerForOption));

if (newVectorLayers[0] && !stateParams.selectedLayer) {
setValue('selectedLayer', newVectorLayers[0]);
onLayerChange(newVectorLayers[0]);
}
})
.catch((error: Error) => toastNotifications.addWarning(error.message));
}
}, []);

const setLayer = useCallback(
(paramName: 'selectedLayer', value: VectorLayer['layerId']) => {
const newLayer = vectorLayers.find(({ layerId }: VectorLayer) => layerId === value);

if (newLayer) {
setValue(paramName, newLayer);
onLayerChange(newLayer);
}
},
[vectorLayers]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should also include setValue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we build the logic with static setValue prop, but it could be changed in the future.. so it would make sense to watch it also. Thnx!

);

const setField = useCallback(
(paramName: 'selectedJoinField', value: FileLayerField['name']) => {
if (stateParams.selectedLayer) {
setValue(paramName, stateParams.selectedLayer.fields.find(f => f.name === value));
}
},
[stateParams.selectedLayer]
);

return (
<>
<EuiPanel paddingSize="s">
<EuiTitle size="xs">
<h2>
<FormattedMessage
id="regionMap.visParams.layerSettingsTitle"
defaultMessage="Layer settings"
/>
</h2>
</EuiTitle>
<EuiSpacer size="s" />

<SelectOption
id="regionMapOptionsSelectLayer"
label={i18n.translate('regionMap.visParams.vectorMapLabel', {
defaultMessage: 'Vector map',
})}
labelAppend={
stateParams.emsHotLink && (
<EuiText size="xs">
<EuiLink
href={stateParams.emsHotLink}
target="_blank"
rel="noopener"
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
title={i18n.translate('regionMap.visParams.previewOnEMSLinkTitle', {
defaultMessage: 'Preview {selectedLayerName} on the Elastic Maps Service',
values: {
selectedLayerName:
stateParams.selectedLayer && stateParams.selectedLayer.name,
},
})}
>
<FormattedMessage
id="regionMap.visParams.previewOnEMSLinkText"
defaultMessage="Preview on EMS"
/>{' '}
<EuiIcon type="popout" size="s" />
</EuiLink>
</EuiText>
)
}
options={vectorLayerOptions}
paramName="selectedLayer"
value={stateParams.selectedLayer && stateParams.selectedLayer.layerId}
setValue={setLayer}
/>

<SelectOption
id="regionMapOptionsSelectJoinField"
label={i18n.translate('regionMap.visParams.joinFieldLabel', {
defaultMessage: 'Join field',
})}
options={fieldOptions}
paramName="selectedJoinField"
value={stateParams.selectedJoinField && stateParams.selectedJoinField.name}
setValue={setField}
/>

<SwitchOption
label={i18n.translate('regionMap.visParams.displayWarningsLabel', {
defaultMessage: 'Display warnings',
})}
tooltip={i18n.translate('regionMap.visParams.switchWarningsTipText', {
defaultMessage:
'Turns on/off warnings. When turned on, warning will be shown for each term that cannot be matched to a shape in the vector layer based on the join field. When turned off, these warnings will be turned off.',
})}
paramName="isDisplayWarning"
value={stateParams.isDisplayWarning}
setValue={setValue}
/>

<SwitchOption
label={i18n.translate('regionMap.visParams.showAllShapesLabel', {
defaultMessage: 'Show all shapes',
})}
tooltip={i18n.translate('regionMap.visParams.turnOffShowingAllShapesTipText', {
defaultMessage:
'Turning this off only shows the shapes that were matched with a corresponding term',
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
})}
paramName="showAllShapes"
value={stateParams.showAllShapes}
setValue={setValue}
/>
</EuiPanel>

<EuiSpacer size="s" />

<EuiPanel paddingSize="s">
<EuiTitle size="xs">
<h2>
<FormattedMessage
id="regionMap.visParams.styleSettingsLabel"
defaultMessage="Style settings"
/>
</h2>
</EuiTitle>
<EuiSpacer size="s" />

<SelectOption
label={i18n.translate('regionMap.visParams.colorSchemaLabel', {
defaultMessage: 'Color schema',
})}
options={vis.type.editorConfig.collections.colorSchemas}
paramName="colorSchema"
value={stateParams.colorSchema}
setValue={setValue}
/>

<NumberInputOption
label={i18n.translate('regionMap.visParams.outlineWeightLabel', {
defaultMessage: 'Outline weight',
sulemanof marked this conversation as resolved.
Show resolved Hide resolved
})}
paramName="outlineWeight"
value={stateParams.outlineWeight}
setValue={setValue}
/>
</EuiPanel>

<EuiSpacer size="s" />

<WmsOptions {...props} />
</>
);
}

export { RegionMapOptions };
10 changes: 0 additions & 10 deletions src/legacy/core_plugins/region_map/public/index.scss

This file was deleted.

Loading