Skip to content

Commit

Permalink
Merge branch 'main' into 454/service-list-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 23, 2022
2 parents 98724ab + 93de448 commit f219fef
Show file tree
Hide file tree
Showing 59 changed files with 1,265 additions and 274 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/kbn-react-field/src/field_icon/field_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface FieldIconProps extends Omit<EuiTokenProps, 'iconType'> {
| 'geo_shape'
| 'ip'
| 'ip_range'
| 'match_only_text'
| 'murmur3'
| 'number'
| 'number_range'
Expand All @@ -45,6 +46,7 @@ export const typeToEuiIconMap: Partial<Record<string, EuiTokenProps>> = {
geo_shape: { iconType: 'tokenGeo' },
ip: { iconType: 'tokenIP' },
ip_range: { iconType: 'tokenIP' },
match_only_text: { iconType: 'tokenString' },
// is a plugin's data type https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-murmur3-usage.html
murmur3: { iconType: 'tokenSearchType' },
number: { iconType: 'tokenNumber' },
Expand Down
2 changes: 2 additions & 0 deletions packages/shared-ux/prompt/no_data_views/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RUNTIME_DEPS = [
"//packages/kbn-i18n-react",
"//packages/kbn-i18n",
"//packages/kbn-shared-ux-utility",
"//packages/kbn-test-jest-helpers",
]

# In this array place dependencies necessary to build the types, which will include the
Expand All @@ -71,6 +72,7 @@ TYPES_DEPS = [
"//packages/kbn-i18n-react:npm_module_types",
"//packages/kbn-i18n:npm_module_types",
"//packages/kbn-shared-ux-utility:npm_module_types",
"//packages/kbn-test-jest-helpers:npm_module_types",
]

jsts_transpiler(
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
*/

import { Observable } from 'rxjs';
import { ErrorLike } from '@kbn/expressions-plugin';
import { Adapters } from '../types';
import { IContainer } from '../containers/i_container';
import { EmbeddableInput } from '../../../common/types';

export interface EmbeddableError {
name: string;
message: string;
}

export type EmbeddableError = ErrorLike;
export type { EmbeddableInput };

export interface EmbeddableOutput {
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/vis_types/timeseries/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,16 @@ export class PivotNotSelectedForTableError extends UIError {
);
}
}

export class DataViewNotFoundError extends UIError {
constructor(dataViewId: string) {
super(
i18n.translate('visTypeTimeseries.errors.dataViewNotFoundError', {
defaultMessage: `Could not find the data view: {dataViewId}`,
values: {
dataViewId,
},
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { uniq } from 'lodash';
import { DataViewsService } from '@kbn/data-views-plugin/common';
import { DataViewNotFoundError } from './errors';
import type { Panel, IndexPatternValue, FetchedIndexPattern } from './types';

export const isStringTypeIndexPattern = (
Expand Down Expand Up @@ -70,7 +71,11 @@ export const fetchIndexPattern = async (

indexPatternString = indexPatternValue;
} else if (indexPatternValue.id) {
indexPattern = await indexPatternsService.get(indexPatternValue.id);
try {
indexPattern = await indexPatternsService.get(indexPatternValue.id);
} catch (e) {
throw new DataViewNotFoundError(indexPatternValue.id);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ export async function fetchFields(
try {
const indexFields = await Promise.all(
patterns.map(async (pattern) => {
if (typeof pattern !== 'string' && pattern?.id) {
return toSanitizedFieldType(
(await getDataViewsStart().get(pattern.id)).getNonScriptedFields()
);
} else {
return coreStart.http.get(ROUTES.FIELDS, {
query: {
index: `${pattern ?? ''}`,
},
signal,
});
try {
if (typeof pattern !== 'string' && pattern?.id) {
return toSanitizedFieldType(
(await getDataViewsStart().get(pattern.id)).getNonScriptedFields()
);
} else {
return coreStart.http.get(ROUTES.FIELDS, {
query: {
index: `${pattern ?? ''}`,
},
signal,
});
}
} catch (e) {
return [];
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,44 @@ export async function getSeriesData(
panel: Panel,
services: VisTypeTimeseriesRequestServices
) {
const {
cachedIndexPatternFetcher,
searchStrategyRegistry,
indexPatternsService,
fieldFormatService,
} = services;

const panelIndex = await cachedIndexPatternFetcher(
panel.index_pattern,
!panel.use_kibana_indexes
);

const strategy = await searchStrategyRegistry.getViableStrategy(requestContext, req, panelIndex);

if (!strategy) {
throw new Error(
i18n.translate('visTypeTimeseries.searchStrategyUndefinedErrorMessage', {
defaultMessage: 'Search strategy was not defined',
})
let meta: DataResponseMeta | undefined;
const handleError = handleErrorResponse(panel);

try {
const {
cachedIndexPatternFetcher,
searchStrategyRegistry,
indexPatternsService,
fieldFormatService,
} = services;

const panelIndex = await cachedIndexPatternFetcher(
panel.index_pattern,
!panel.use_kibana_indexes
);
}

const { searchStrategy, capabilities } = strategy;
const handleError = handleErrorResponse(panel);
const strategy = await searchStrategyRegistry.getViableStrategy(
requestContext,
req,
panelIndex
);

const meta: DataResponseMeta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
trackedEsSearches: {},
};
if (!strategy) {
throw new Error(
i18n.translate('visTypeTimeseries.searchStrategyUndefinedErrorMessage', {
defaultMessage: 'Search strategy was not defined',
})
);
}

const { searchStrategy, capabilities } = strategy;

meta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
trackedEsSearches: {},
};

try {
const bodiesPromises = getActiveSeries(panel).map((series) => {
isAggSupported(series.metrics, capabilities);
return getSeriesRequestParams(req, panel, panelIndex, series, capabilities, services);
Expand Down Expand Up @@ -116,7 +122,7 @@ export async function getSeriesData(
};
} catch (err) {
return {
...meta,
...(meta || {}),
...handleError(err),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,56 @@ export async function getTableData(
panel: Panel,
services: VisTypeTimeseriesRequestServices
) {
const panelIndex = await services.cachedIndexPatternFetcher(
panel.index_pattern,
!panel.use_kibana_indexes
);

const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
panelIndex
);

if (!strategy) {
throw new Error(
i18n.translate('visTypeTimeseries.searchStrategyUndefinedErrorMessage', {
defaultMessage: 'Search strategy was not defined',
})
let meta: DataResponseMeta | undefined;
const handleError = handleErrorResponse(panel);

try {
const panelIndex = await services.cachedIndexPatternFetcher(
panel.index_pattern,
!panel.use_kibana_indexes
);
}

const { searchStrategy, capabilities } = strategy;
const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
panelIndex
);

const extractFields = createFieldsFetcher(req, {
indexPatternsService: services.indexPatternsService,
cachedIndexPatternFetcher: services.cachedIndexPatternFetcher,
searchStrategy,
capabilities,
});
if (!strategy) {
throw new Error(
i18n.translate('visTypeTimeseries.searchStrategyUndefinedErrorMessage', {
defaultMessage: 'Search strategy was not defined',
})
);
}

const calculatePivotLabel = async () => {
const pivotIds = getFieldsForTerms(panel.pivot_id);
const { searchStrategy, capabilities } = strategy;

if (pivotIds.length) {
const fields = panelIndex.indexPattern?.id
? await extractFields({ id: panelIndex.indexPattern.id })
: [];
const extractFields = createFieldsFetcher(req, {
indexPatternsService: services.indexPatternsService,
cachedIndexPatternFetcher: services.cachedIndexPatternFetcher,
searchStrategy,
capabilities,
});

return getMultiFieldLabel(pivotIds, fields);
}
};
const calculatePivotLabel = async () => {
const pivotIds = getFieldsForTerms(panel.pivot_id);

const meta: DataResponseMeta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
trackedEsSearches: {},
};
const handleError = handleErrorResponse(panel);
if (pivotIds.length) {
const fields = panelIndex.indexPattern?.id
? await extractFields({ id: panelIndex.indexPattern.id })
: [];

return getMultiFieldLabel(pivotIds, fields);
}
};

meta = {
type: panel.type,
uiRestrictions: capabilities.uiRestrictions,
trackedEsSearches: {},
};

try {
panel.series.forEach((series) => {
isAggSupported(series.metrics, capabilities);
if (series.filter?.query && !isConfigurationFeatureEnabled('filter', capabilities)) {
Expand Down Expand Up @@ -131,7 +133,7 @@ export async function getTableData(
const series = await Promise.all(buckets.map(processBucket({ panel, extractFields })));

return {
...meta,
...(meta || {}),
pivot_label: panel.pivot_label || (await calculatePivotLabel()),
series,
};
Expand Down
1 change: 1 addition & 0 deletions src/plugins/visualizations/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"requiredPlugins": [
"data",
"expressions",
"fieldFormats",
"uiActions",
"urlForwarding",
"navigation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import { EuiEmptyPrompt, EuiText } from '@elastic/eui';
import React from 'react';

interface VisualizationNoResultsProps {
interface VisualizationErrorProps {
onInit?: () => void;
error: string | Error;
}

export class VisualizationError extends React.Component<VisualizationNoResultsProps> {
export class VisualizationError extends React.Component<VisualizationErrorProps> {
public render() {
return (
<EuiEmptyPrompt
Expand Down
Loading

0 comments on commit f219fef

Please sign in to comment.