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

[Maps] fix Cannot open Lens editor in airgapped environment #132429

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -121,10 +121,15 @@ export class LayerTemplate extends Component<RenderWizardArguments, State> {
};

_loadEmsFileFields = async () => {
const emsFileLayers = await getEmsFileLayers();
const emsFileLayer = emsFileLayers.find((fileLayer: FileLayer) => {
return fileLayer.getId() === this.state.leftEmsFileId;
});
let emsFileLayer: FileLayer | undefined;
try {
const emsFileLayers = await getEmsFileLayers();
emsFileLayer = emsFileLayers.find((fileLayer: FileLayer) => {
return fileLayer.getId() === this.state.leftEmsFileId;
});
} catch (error) {
// ignore error, lack of EMS file layers will be surfaced in EMS file select
}

if (!this._isMounted || !emsFileLayer) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,31 @@ export class TileServiceSelect extends Component<Props, State> {
}

_loadTmsOptions = async () => {
const emsTMSServices = await getEmsTmsServices();

if (!this._isMounted) {
return;
try {
const emsTMSServices = await getEmsTmsServices();

if (!this._isMounted) {
return;
}

const emsTmsOptions = emsTMSServices.map((tmsService) => {
return {
value: tmsService.getId(),
text: tmsService.getDisplayName() ? tmsService.getDisplayName() : tmsService.getId(),
};
});
emsTmsOptions.unshift({
value: AUTO_SELECT,
text: i18n.translate('xpack.maps.source.emsTile.autoLabel', {
defaultMessage: 'Autoselect based on Kibana theme',
}),
});
this.setState({ emsTmsOptions, hasLoaded: true });
} catch (error) {
if (this._isMounted) {
this.setState({ emsTmsOptions: [], hasLoaded: true });
}
}

const emsTmsOptions = emsTMSServices.map((tmsService) => {
return {
value: tmsService.getId(),
text: tmsService.getDisplayName() ? tmsService.getDisplayName() : tmsService.getId(),
};
});
emsTmsOptions.unshift({
value: AUTO_SELECT,
text: i18n.translate('xpack.maps.source.emsTile.autoLabel', {
defaultMessage: 'Autoselect based on Kibana theme',
}),
});
this.setState({ emsTmsOptions, hasLoaded: true });
};

_onChange = (e: ChangeEvent<HTMLSelectElement>) => {
Expand Down
13 changes: 12 additions & 1 deletion x-pack/plugins/maps/public/components/ems_file_select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ export class EMSFileSelect extends Component<Props, State> {
};

_loadFileOptions = async () => {
const fileLayers: FileLayer[] = await getEmsFileLayers();
let fileLayers: FileLayer[] = [];
try {
fileLayers = await getEmsFileLayers();
} catch (error) {
if (this._isMounted) {
this.setState({
hasLoadedOptions: true,
emsFileOptions: [],
});
}
}

const options = fileLayers.map((fileLayer) => {
return {
value: fileLayer.getId(),
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/maps/public/ems_autosuggest/ems_autosuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ interface FileLayerFieldShim {
export async function suggestEMSTermJoinConfig(
sampleValuesConfig: SampleValuesConfig
): Promise<EMSTermJoinConfig | null> {
const fileLayers = await getEmsFileLayers();
return emsAutoSuggest(sampleValuesConfig, fileLayers);
try {
const fileLayers = await getEmsFileLayers();
return emsAutoSuggest(sampleValuesConfig, fileLayers);
} catch (error) {
// can not return suggestions since EMS is not available.
return null;
}
}

export function emsAutoSuggest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ReactDOM from 'react-dom';
import type { IInterpreterRenderHandlers } from '@kbn/expressions-plugin/public';
import type { EmbeddableFactory } from '@kbn/embeddable-plugin/public';
import type { CoreSetup, CoreStart } from '@kbn/core/public';
import type { FileLayer } from '@elastic/ems-client';
import type { MapsPluginStartDependencies } from '../../plugin';
import type { ChoroplethChartProps } from './types';
import type { MapEmbeddableInput, MapEmbeddableOutput } from '../../embeddable';
Expand Down Expand Up @@ -40,12 +41,19 @@ export function getExpressionRenderer(coreSetup: CoreSetup<MapsPluginStartDepend
return;
}

let emsFileLayers: FileLayer[] = [];
try {
emsFileLayers = await getEmsFileLayers();
} catch (error) {
// ignore error, lack of EMS file layers will be surfaced in dimension editor
}

ReactDOM.render(
<ChoroplethChart
{...config}
formatFactory={plugins.fieldFormats.deserialize}
uiSettings={coreStart.uiSettings}
emsFileLayers={await getEmsFileLayers()}
emsFileLayers={emsFileLayers}
mapEmbeddableFactory={mapEmbeddableFactory}
/>,
domNode,
Expand Down
11 changes: 10 additions & 1 deletion x-pack/plugins/maps/public/lens/choropleth_chart/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type { ExpressionsSetup } from '@kbn/expressions-plugin/public';
import type { CoreSetup, CoreStart } from '@kbn/core/public';
import type { LensPublicSetup } from '@kbn/lens-plugin/public';
import type { FileLayer } from '@elastic/ems-client';
import type { MapsPluginStartDependencies } from '../../plugin';
import { getExpressionFunction } from './expression_function';
import { getExpressionRenderer } from './expression_renderer';
Expand All @@ -28,9 +29,17 @@ export function setupLensChoroplethChart(
await coreSetup.getStartServices();
const { getEmsFileLayers } = await import('../../util');
const { getVisualization } = await import('./visualization');

let emsFileLayers: FileLayer[] = [];
try {
emsFileLayers = await getEmsFileLayers();
} catch (error) {
// ignore error, lack of EMS file layers will be surfaced in dimension editor
}

return getVisualization({
theme: coreStart.theme,
emsFileLayers: await getEmsFileLayers(),
emsFileLayers,
paletteService: await plugins.charts.palettes.getPalettes(),
});
});
Expand Down