Skip to content

Commit

Permalink
Removes editorConfig.collections (#89854)
Browse files Browse the repository at this point in the history
* Removed editorConfig.collections

* Fix CI

* Update snapshots

* Fix comments

* Fix eslint

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
VladLasitsa and kibanamachine authored Feb 5, 2021
1 parent 81e4595 commit 1f0da4f
Show file tree
Hide file tree
Showing 48 changed files with 329 additions and 582 deletions.
6 changes: 2 additions & 4 deletions src/plugins/maps_legacy/public/components/wms_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ import { EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { TmsLayer } from '../index';
import { Vis } from '../../../visualizations/public';
import { SelectOption, SwitchOption } from '../../../vis_default_editor/public';
import { WmsInternalOptions } from './wms_internal_options';
import { WMSOptions } from '../common/types';

interface Props<K> {
stateParams: K;
setValue: (title: 'wms', options: WMSOptions) => void;
vis: Vis;
tmsLayers: TmsLayer[];
}

const mapLayerForOption = ({ id }: TmsLayer) => ({ text: id, value: id });

function WmsOptions<K extends { wms: WMSOptions }>({ stateParams, setValue, vis }: Props<K>) {
function WmsOptions<K extends { wms: WMSOptions }>({ stateParams, setValue, tmsLayers }: Props<K>) {
const { wms } = stateParams;
const { tmsLayers } = vis.type.editorConfig.collections;
const tmsLayerOptions = useMemo(() => tmsLayers.map(mapLayerForOption), [tmsLayers]);

const setWmsOption = <T extends keyof WMSOptions>(paramName: T, value: WMSOptions[T]) =>
Expand Down
16 changes: 10 additions & 6 deletions src/plugins/region_map/public/components/region_map_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { EuiIcon, EuiLink, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elast
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { VisEditorOptionsProps } from 'src/plugins/visualizations/public';
import { truncatedColorSchemas } from '../../../charts/public';
import { FileLayerField, VectorLayer, IServiceSettings } from '../../../maps_legacy/public';
import { SelectOption, SwitchOption, NumberInputOption } from '../../../vis_default_editor/public';
import { WmsOptions } from '../../../maps_legacy/public';
import { RegionMapVisParams } from '../region_map_types';
import { getTmsLayers, getVectorLayers } from '../kibana_services';

const mapLayerForOption = ({ layerId, name }: VectorLayer) => ({
text: name,
Expand All @@ -26,14 +28,16 @@ const mapFieldForOption = ({ description, name }: FileLayerField) => ({
value: name,
});

const tmsLayers = getTmsLayers();
const vectorLayers = getVectorLayers();
const vectorLayerOptions = vectorLayers.map(mapLayerForOption);

export type RegionMapOptionsProps = {
getServiceSettings: () => Promise<IServiceSettings>;
} & VisEditorOptionsProps<RegionMapVisParams>;

function RegionMapOptions(props: RegionMapOptionsProps) {
const { getServiceSettings, stateParams, vis, setValue } = props;
const { vectorLayers } = vis.type.editorConfig.collections;
const vectorLayerOptions = useMemo(() => vectorLayers.map(mapLayerForOption), [vectorLayers]);
const { getServiceSettings, stateParams, setValue } = props;
const fieldOptions = useMemo(
() =>
((stateParams.selectedLayer && stateParams.selectedLayer.fields) || []).map(
Expand Down Expand Up @@ -61,7 +65,7 @@ function RegionMapOptions(props: RegionMapOptionsProps) {
setEmsHotLink(newLayer);
}
},
[vectorLayers, setEmsHotLink, setValue]
[setEmsHotLink, setValue]
);

const setField = useCallback(
Expand Down Expand Up @@ -178,7 +182,7 @@ function RegionMapOptions(props: RegionMapOptionsProps) {
label={i18n.translate('regionMap.visParams.colorSchemaLabel', {
defaultMessage: 'Color schema',
})}
options={vis.type.editorConfig.collections.colorSchemas}
options={truncatedColorSchemas}
paramName="colorSchema"
value={stateParams.colorSchema}
setValue={setValue}
Expand All @@ -197,7 +201,7 @@ function RegionMapOptions(props: RegionMapOptionsProps) {

<EuiSpacer size="s" />

<WmsOptions {...props} />
<WmsOptions setValue={setValue} stateParams={stateParams} tmsLayers={tmsLayers} />
</>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/region_map/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createGetterSetter } from '../../kibana_utils/public';
import { DataPublicPluginStart } from '../../data/public';
import { KibanaLegacyStart } from '../../kibana_legacy/public';
import { SharePluginStart } from '../../share/public';
import { VectorLayer, TmsLayer } from '../../maps_legacy/public';

export const [getCoreService, setCoreService] = createGetterSetter<CoreStart>('Core');

Expand All @@ -32,3 +33,7 @@ export const [getShareService, setShareService] = createGetterSetter<SharePlugin
export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter<KibanaLegacyStart>(
'KibanaLegacy'
);

export const [getTmsLayers, setTmsLayers] = createGetterSetter<TmsLayer[]>('TmsLayers');

export const [getVectorLayers, setVectorLayers] = createGetterSetter<VectorLayer[]>('VectorLayers');
16 changes: 7 additions & 9 deletions src/plugins/region_map/public/region_map_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { i18n } from '@kbn/i18n';

import { VisTypeDefinition } from '../../visualizations/public';
import { truncatedColorSchemas } from '../../charts/public';
import { ORIGIN } from '../../maps_legacy/public';

import { getDeprecationMessage } from './get_deprecation_message';
Expand All @@ -18,6 +17,7 @@ import { createRegionMapOptions } from './components';
import { toExpressionAst } from './to_ast';
import { RegionMapVisParams } from './region_map_types';
import { mapToLayerWithId } from './util';
import { setTmsLayers, setVectorLayers } from './kibana_services';

export function createRegionMapTypeDefinition({
uiSettings,
Expand Down Expand Up @@ -50,11 +50,6 @@ provided base maps, or add your own. Darker colors represent higher values.',
},
editorConfig: {
optionsTemplate: createRegionMapOptions(getServiceSettings),
collections: {
colorSchemas: truncatedColorSchemas,
vectorLayers: [],
tmsLayers: [],
},
schemas: [
{
group: 'metrics',
Expand Down Expand Up @@ -95,7 +90,9 @@ provided base maps, or add your own. Darker colors represent higher values.',
setup: async (vis) => {
const serviceSettings = await getServiceSettings();
const tmsLayers = await serviceSettings.getTMSServices();
vis.type.editorConfig.collections.tmsLayers = tmsLayers;
setTmsLayers(tmsLayers);
setVectorLayers([]);

if (!vis.params.wms.selectedTmsLayer && tmsLayers.length) {
vis.params.wms.selectedTmsLayer = tmsLayers[0];
}
Expand All @@ -122,9 +119,10 @@ provided base maps, or add your own. Darker colors represent higher values.',
}
});

vis.type.editorConfig.collections.vectorLayers = [...vectorLayers, ...newLayers];
const allVectorLayers = [...vectorLayers, ...newLayers];
setVectorLayers(allVectorLayers);

[selectedLayer] = vis.type.editorConfig.collections.vectorLayers;
[selectedLayer] = allVectorLayers;
selectedJoinField = selectedLayer ? selectedLayer.fields[0] : undefined;

if (selectedLayer && !vis.params.selectedLayer && selectedLayer.isEMS) {
Expand Down
65 changes: 65 additions & 0 deletions src/plugins/tile_map/public/components/collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { MapTypes } from '../utils/map_types';

export const collections = {
mapTypes: [
{
value: MapTypes.ScaledCircleMarkers,
text: i18n.translate('tileMap.mapTypes.scaledCircleMarkersText', {
defaultMessage: 'Scaled circle markers',
}),
},
{
value: MapTypes.ShadedCircleMarkers,
text: i18n.translate('tileMap.mapTypes.shadedCircleMarkersText', {
defaultMessage: 'Shaded circle markers',
}),
},
{
value: MapTypes.ShadedGeohashGrid,
text: i18n.translate('tileMap.mapTypes.shadedGeohashGridText', {
defaultMessage: 'Shaded geohash grid',
}),
},
{
value: MapTypes.Heatmap,
text: i18n.translate('tileMap.mapTypes.heatmapText', {
defaultMessage: 'Heatmap',
}),
},
],
legendPositions: [
{
value: 'bottomleft',
text: i18n.translate('tileMap.legendPositions.bottomLeftText', {
defaultMessage: 'Bottom left',
}),
},
{
value: 'bottomright',
text: i18n.translate('tileMap.legendPositions.bottomRightText', {
defaultMessage: 'Bottom right',
}),
},
{
value: 'topleft',
text: i18n.translate('tileMap.legendPositions.topLeftText', {
defaultMessage: 'Top left',
}),
},
{
value: 'topright',
text: i18n.translate('tileMap.legendPositions.topRightText', {
defaultMessage: 'Top right',
}),
},
],
};
17 changes: 11 additions & 6 deletions src/plugins/tile_map/public/components/tile_map_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@ import {
SwitchOption,
RangeOption,
} from '../../../vis_default_editor/public';
import { truncatedColorSchemas } from '../../../charts/public';
import { WmsOptions } from '../../../maps_legacy/public';
import { TileMapVisParams } from '../types';
import { MapTypes } from '../utils/map_types';
import { getTmsLayers } from '../services';
import { collections } from './collections';

export type TileMapOptionsProps = VisEditorOptionsProps<TileMapVisParams>;

const tmsLayers = getTmsLayers();

function TileMapOptions(props: TileMapOptionsProps) {
const { stateParams, setValue, vis } = props;

useEffect(() => {
if (!stateParams.mapType) {
setValue('mapType', vis.type.editorConfig.collections.mapTypes[0]);
setValue('mapType', collections.mapTypes[0].value);
}
}, [setValue, stateParams.mapType, vis.type.editorConfig.collections.mapTypes]);
}, [setValue, stateParams.mapType]);

return (
<>
Expand All @@ -39,7 +44,7 @@ function TileMapOptions(props: TileMapOptionsProps) {
label={i18n.translate('tileMap.visParams.mapTypeLabel', {
defaultMessage: 'Map type',
})}
options={vis.type.editorConfig.collections.mapTypes}
options={collections.mapTypes}
paramName="mapType"
value={stateParams.mapType}
setValue={setValue}
Expand All @@ -62,14 +67,14 @@ function TileMapOptions(props: TileMapOptionsProps) {
label={i18n.translate('tileMap.visParams.colorSchemaLabel', {
defaultMessage: 'Color schema',
})}
options={vis.type.editorConfig.collections.colorSchemas}
options={truncatedColorSchemas}
paramName="colorSchema"
value={stateParams.colorSchema}
setValue={setValue}
/>
)}

<BasicOptions {...props} />
<BasicOptions {...props} legendPositions={collections.legendPositions} />

<SwitchOption
disabled={!vis.type.visConfig?.canDesaturate}
Expand All @@ -88,7 +93,7 @@ function TileMapOptions(props: TileMapOptionsProps) {

<EuiSpacer size="s" />

<WmsOptions {...props} />
<WmsOptions setValue={setValue} stateParams={stateParams} tmsLayers={tmsLayers} />
</>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/tile_map/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createGetterSetter } from '../../kibana_utils/public';
import { DataPublicPluginStart } from '../../data/public';
import { KibanaLegacyStart } from '../../kibana_legacy/public';
import { SharePluginStart } from '../../share/public';
import { TmsLayer } from '../../maps_legacy/public';

export const [getCoreService, setCoreService] = createGetterSetter<CoreStart>('Core');

Expand All @@ -27,3 +28,5 @@ export const [getShareService, setShareService] = createGetterSetter<SharePlugin
export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter<KibanaLegacyStart>(
'KibanaLegacy'
);

export const [getTmsLayers, setTmsLayers] = createGetterSetter<TmsLayer[]>('TmsLayers');
61 changes: 2 additions & 59 deletions src/plugins/tile_map/public/tile_map_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { i18n } from '@kbn/i18n';
import { VisTypeDefinition } from 'src/plugins/visualizations/public';
import { truncatedColorSchemas } from '../../charts/public';

// @ts-expect-error
import { supportsCssFilters } from './css_filters';
Expand All @@ -17,7 +16,7 @@ import { getDeprecationMessage } from './get_deprecation_message';
import { TileMapVisualizationDependencies } from './plugin';
import { toExpressionAst } from './to_ast';
import { TileMapVisParams } from './types';
import { MapTypes } from './utils/map_types';
import { setTmsLayers } from './services';

export function createTileMapTypeDefinition(
dependencies: TileMapVisualizationDependencies
Expand Down Expand Up @@ -50,62 +49,6 @@ export function createTileMapTypeDefinition(
},
toExpressionAst,
editorConfig: {
collections: {
colorSchemas: truncatedColorSchemas,
legendPositions: [
{
value: 'bottomleft',
text: i18n.translate('tileMap.vis.editorConfig.legendPositions.bottomLeftText', {
defaultMessage: 'Bottom left',
}),
},
{
value: 'bottomright',
text: i18n.translate('tileMap.vis.editorConfig.legendPositions.bottomRightText', {
defaultMessage: 'Bottom right',
}),
},
{
value: 'topleft',
text: i18n.translate('tileMap.vis.editorConfig.legendPositions.topLeftText', {
defaultMessage: 'Top left',
}),
},
{
value: 'topright',
text: i18n.translate('tileMap.vis.editorConfig.legendPositions.topRightText', {
defaultMessage: 'Top right',
}),
},
],
mapTypes: [
{
value: MapTypes.ScaledCircleMarkers,
text: i18n.translate('tileMap.vis.editorConfig.mapTypes.scaledCircleMarkersText', {
defaultMessage: 'Scaled circle markers',
}),
},
{
value: MapTypes.ShadedCircleMarkers,
text: i18n.translate('tileMap.vis.editorConfig.mapTypes.shadedCircleMarkersText', {
defaultMessage: 'Shaded circle markers',
}),
},
{
value: MapTypes.ShadedGeohashGrid,
text: i18n.translate('tileMap.vis.editorConfig.mapTypes.shadedGeohashGridText', {
defaultMessage: 'Shaded geohash grid',
}),
},
{
value: MapTypes.Heatmap,
text: i18n.translate('tileMap.vis.editorConfig.mapTypes.heatmapText', {
defaultMessage: 'Heatmap',
}),
},
],
tmsLayers: [],
},
optionsTemplate: TileMapOptionsLazy,
schemas: [
{
Expand Down Expand Up @@ -141,7 +84,7 @@ export function createTileMapTypeDefinition(
return vis;
}

vis.type.editorConfig.collections.tmsLayers = tmsLayers;
setTmsLayers(tmsLayers);
if (!vis.params.wms.selectedTmsLayer && tmsLayers.length) {
vis.params.wms.selectedTmsLayer = tmsLayers[0];
}
Expand Down
Loading

0 comments on commit 1f0da4f

Please sign in to comment.