@@ -51,10 +51,7 @@ const getReadyToSwitchCallOut = (value: PopoverProps['value'], onModeChange: ()
>
);
-const getNoMatchedIndicesCallOut = (
- value: PopoverProps['value'],
- onCreateIndexClick: () => void
-) => (
+const getNoMatchedIndicesCallOut = (value: string, onCreateIndexClick: () => void) => (
<>
@@ -77,7 +74,7 @@ const getNoMatchedIndicesCallOut = (
>
);
-export const MigrationPopover = ({ value, onModeChange, matchedIndex }: PopoverProps) => {
+export const MigrationPopover = ({ fetchedIndex, onModeChange }: PopoverProps) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const closePopover = useCallback(() => setIsPopoverOpen(false), []);
const onButtonClick = useCallback(() => setIsPopoverOpen((isOpen) => !isOpen), []);
@@ -88,9 +85,13 @@ export const MigrationPopover = ({ value, onModeChange, matchedIndex }: PopoverP
const navigateToCreateIndexPatterns = useCallback(() => {
getCoreStart().application.navigateToApp('management', {
- path: `/kibana/indexPatterns/create?name=${value}`,
+ path: `/kibana/indexPatterns/create?name=${fetchedIndex?.indexPatternString ?? ''}`,
});
- }, [value]);
+ }, [fetchedIndex]);
+
+ if (!fetchedIndex) {
+ return null;
+ }
return (
{switchModeLabel}
- {matchedIndex && getReadyToSwitchCallOut(value, switchMode)}
- {!matchedIndex && getNoMatchedIndicesCallOut(value, navigateToCreateIndexPatterns)}
+ {fetchedIndex.indexPattern &&
+ getReadyToSwitchCallOut(fetchedIndex.indexPatternString, switchMode)}
+
+ {!fetchedIndex.indexPattern &&
+ getNoMatchedIndicesCallOut(fetchedIndex.indexPatternString, navigateToCreateIndexPatterns)}
);
};
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
index 43574ce84ab85..58a9e6dadb60d 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
@@ -6,11 +6,11 @@
* Side Public License, v 1.
*/
import { Assign } from '@kbn/utility-types';
-import type { IndexPatternObject } from '../../../../../common/types';
+import type { FetchedIndexPattern, IndexPatternObject } from '../../../../../common/types';
/** @internal **/
export interface SelectIndexComponentProps {
- value: IndexPatternObject;
+ fetchedIndex: FetchedIndexPattern | undefined;
onIndexChange: (value: IndexPatternObject) => void;
onModeChange: (useKibanaIndexes: boolean) => void;
'data-test-subj': string;
@@ -21,9 +21,8 @@ export interface SelectIndexComponentProps {
/** @internal **/
export type PopoverProps = Assign<
- Pick,
+ Pick,
{
useKibanaIndices: boolean;
- matchedIndex?: IndexPatternObject;
}
>;
diff --git a/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx b/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
index c74f37ce58c84..ddee08b6a12b7 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
@@ -6,26 +6,51 @@
* Side Public License, v 1.
*/
-import React, { useContext } from 'react';
+import React, { useContext, useEffect, useState } from 'react';
import { CoreStartContext } from '../contexts/query_input_bar_context';
import { IndexPatternObject } from '../../../common/types';
-import { convertIndexPatternObjectToStringRepresentation } from '../../../common/index_patterns_utils';
import { QueryStringInput, QueryStringInputProps } from '../../../../../plugins/data/public';
+import { getDataStart } from '../../services';
+import { fetchIndexPattern, isStringTypeIndexPattern } from '../../../common/index_patterns_utils';
type QueryBarWrapperProps = Pick & {
indexPatterns: IndexPatternObject[];
};
export function QueryBarWrapper({ query, onChange, indexPatterns }: QueryBarWrapperProps) {
+ const { indexPatterns: indexPatternsService } = getDataStart();
+ const [indexes, setIndexes] = useState([]);
+
const coreStartContext = useContext(CoreStartContext);
+ useEffect(() => {
+ async function fetchIndexes() {
+ const i: QueryStringInputProps['indexPatterns'] = [];
+
+ for (const index of indexPatterns) {
+ if (isStringTypeIndexPattern(index)) {
+ i.push(index);
+ } else if (index?.id) {
+ const fetchedIndex = await fetchIndexPattern(index, indexPatternsService);
+
+ if (fetchedIndex.indexPattern) {
+ i.push(fetchedIndex.indexPattern);
+ }
+ }
+ }
+ setIndexes(i);
+ }
+
+ fetchIndexes();
+ }, [indexPatterns, indexPatternsService]);
+
return (
);
diff --git a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts
index ccece62586e24..b0e85f8e44fbe 100644
--- a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts
@@ -27,19 +27,20 @@ export async function getFields(
indexPatternString = defaultIndexPattern?.title ?? '';
}
+ const fetchedIndex = await cachedIndexPatternFetcher(indexPatternString);
+
const {
searchStrategy,
capabilities,
} = (await framework.searchStrategyRegistry.getViableStrategy(
requestContext,
request,
- indexPatternString
+ fetchedIndex
))!;
const fields = await searchStrategy.getFieldsForWildcard(
- indexPatternString,
+ fetchedIndex,
indexPatternsService,
- cachedIndexPatternFetcher,
capabilities
);
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
index e94b871fb2c79..016960691dd83 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
@@ -98,7 +98,7 @@ describe('CachedIndexPatternFetcher', () => {
});
test('should return default index if Kibana index not found', async () => {
- const value = await cachedIndexPatternFetcher({ id: 'indexId', title: 'title' });
+ const value = await cachedIndexPatternFetcher({ id: 'indexId' });
expect(value).toMatchInlineSnapshot(`
Object {
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/fields_fetcher.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/fields_fetcher.ts
similarity index 74%
rename from src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/fields_fetcher.ts
rename to src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/fields_fetcher.ts
index 0444c33055cee..9003eb7fc2ced 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/helpers/fields_fetcher.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/fields_fetcher.ts
@@ -6,10 +6,10 @@
* Side Public License, v 1.
*/
-import { VisTypeTimeseriesVisDataRequest } from '../../../types';
-import { AbstractSearchStrategy, DefaultSearchCapabilities } from '../../search_strategies';
-import { IndexPatternsService } from '../../../../../data/common';
-import { CachedIndexPatternFetcher } from '../../search_strategies/lib/cached_index_pattern_fetcher';
+import type { VisTypeTimeseriesVisDataRequest } from '../../../types';
+import type { AbstractSearchStrategy, DefaultSearchCapabilities } from '../index';
+import type { IndexPatternsService } from '../../../../../data/common';
+import type { CachedIndexPatternFetcher } from './cached_index_pattern_fetcher';
export interface FieldsFetcherServices {
indexPatternsService: IndexPatternsService;
@@ -33,11 +33,11 @@ export const createFieldsFetcher = (
if (fieldsCacheMap.has(index)) {
return fieldsCacheMap.get(index);
}
+ const fetchedIndex = await cachedIndexPatternFetcher(index);
const fields = await searchStrategy.getFieldsForWildcard(
- index,
+ fetchedIndex,
indexPatternsService,
- cachedIndexPatternFetcher,
capabilities
);
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategy_registry.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategy_registry.ts
index 6445b3099a8cb..4a013fd89735d 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategy_registry.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategy_registry.ts
@@ -8,7 +8,7 @@
import { VisTypeTimeseriesRequest, VisTypeTimeseriesRequestHandlerContext } from '../../types';
import { AbstractSearchStrategy } from './strategies';
-import { IndexPatternObject } from '../../../common/types';
+import { FetchedIndexPattern } from '../../../common/types';
export class SearchStrategyRegistry {
private strategies: AbstractSearchStrategy[] = [];
@@ -23,13 +23,13 @@ export class SearchStrategyRegistry {
async getViableStrategy(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesRequest,
- indexPatternObject: IndexPatternObject
+ fetchedIndexPattern: FetchedIndexPattern
) {
for (const searchStrategy of this.strategies) {
const { isViable, capabilities } = await searchStrategy.checkForViability(
requestContext,
req,
- indexPatternObject
+ fetchedIndexPattern
);
if (isViable) {
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
index 757b2919c8a25..b6d7dc2aff31b 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.test.ts
@@ -23,7 +23,6 @@ class FooSearchStrategy extends AbstractSearchStrategy {}
describe('AbstractSearchStrategy', () => {
let abstractSearchStrategy: AbstractSearchStrategy;
let mockedFields: IFieldType[];
- let indexPattern: string;
let requestContext: VisTypeTimeseriesRequestHandlerContext;
beforeEach(() => {
@@ -51,7 +50,7 @@ describe('AbstractSearchStrategy', () => {
test('should return fields for wildcard', async () => {
const fields = await abstractSearchStrategy.getFieldsForWildcard(
- indexPattern,
+ { indexPatternString: '', indexPattern: undefined },
({
getDefault: jest.fn(),
getFieldsForWildcard: jest.fn(() => Promise.resolve(mockedFields)),
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
index f27a4ceeaa68d..f27533f1f3ebb 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
@@ -9,13 +9,12 @@
import { indexPatterns, IndexPatternsService } from '../../../../../data/server';
import type { FieldSpec } from '../../../../../data/common';
-import type { IndexPatternObject, SanitizedFieldType } from '../../../../common/types';
+import type { SanitizedFieldType, FetchedIndexPattern } from '../../../../common/types';
import type {
VisTypeTimeseriesRequest,
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
-import { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
export const toSanitizedFieldType = (fields: FieldSpec[]) => {
return fields
@@ -64,30 +63,25 @@ export abstract class AbstractSearchStrategy {
checkForViability(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesRequest,
- indexPatternObject: IndexPatternObject
+ fetchedIndexPattern: FetchedIndexPattern
): Promise<{ isViable: boolean; capabilities: any }> {
throw new TypeError('Must override method');
}
async getFieldsForWildcard(
- indexPatternObject: IndexPatternObject,
+ fetchedIndexPattern: FetchedIndexPattern,
indexPatternsService: IndexPatternsService,
- cachedIndexPatternFetcher: CachedIndexPatternFetcher,
capabilities?: unknown,
options?: Partial<{
type: string;
rollupIndex: string;
}>
) {
- const { indexPattern, indexPatternString } = await cachedIndexPatternFetcher(
- indexPatternObject
- );
-
return toSanitizedFieldType(
- indexPattern
- ? indexPattern.getNonScriptedFields()
+ fetchedIndexPattern.indexPattern
+ ? fetchedIndexPattern.indexPattern.getNonScriptedFields()
: await indexPatternsService.getFieldsForWildcard({
- pattern: indexPatternString,
+ pattern: fetchedIndexPattern.indexPatternString,
metaFields: [],
...options,
})
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
index de18809f6ded2..90915fca5401e 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
@@ -8,32 +8,30 @@
import { AbstractSearchStrategy } from './abstract_search_strategy';
import { DefaultSearchCapabilities } from '../capabilities/default_search_capabilities';
-import { VisTypeTimeseriesRequestHandlerContext, VisTypeTimeseriesRequest } from '../../../types';
import { IndexPatternsService } from '../../../../../data/server';
-import { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
+
+import type { FetchedIndexPattern } from '../../../../common/types';
+import type {
+ VisTypeTimeseriesRequestHandlerContext,
+ VisTypeTimeseriesRequest,
+} from '../../../types';
export class DefaultSearchStrategy extends AbstractSearchStrategy {
- checkForViability(
+ async checkForViability(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesRequest
) {
- return Promise.resolve({
+ return {
isViable: true,
capabilities: new DefaultSearchCapabilities(req),
- });
+ };
}
async getFieldsForWildcard(
- indexPattern: string,
+ fetchedIndexPattern: FetchedIndexPattern,
indexPatternsService: IndexPatternsService,
- getCachedIndexPatternFetcher: CachedIndexPatternFetcher,
capabilities?: unknown
) {
- return super.getFieldsForWildcard(
- indexPattern,
- indexPatternsService,
- getCachedIndexPatternFetcher,
- capabilities
- );
+ return super.getFieldsForWildcard(fetchedIndexPattern, indexPatternsService, capabilities);
}
}
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
index bed4ecef5a7a6..4b2b9aebb21dc 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
@@ -99,7 +99,7 @@ describe('Rollup Search Strategy', () => {
const result = await rollupSearchStrategy.checkForViability(
requestContext,
{} as VisTypeTimeseriesVisDataRequest,
- (null as unknown) as string
+ { indexPatternString: (null as unknown) as string, indexPattern: undefined }
);
expect(result).toEqual({
@@ -154,7 +154,7 @@ describe('Rollup Search Strategy', () => {
test('should return fields for wildcard', async () => {
const fields = await rollupSearchStrategy.getFieldsForWildcard(
- indexPattern,
+ { indexPatternString: 'indexPattern', indexPattern: undefined },
{} as IndexPatternsService,
(() => Promise.resolve({}) as unknown) as CachedIndexPatternFetcher,
{
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
index e7a2fc722731a..e6333ca420e0d 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.ts
@@ -7,21 +7,19 @@
*/
import { getCapabilitiesForRollupIndices, IndexPatternsService } from '../../../../../data/server';
-import {
+import { AbstractSearchStrategy } from './abstract_search_strategy';
+import { RollupSearchCapabilities } from '../capabilities/rollup_search_capabilities';
+
+import type { FetchedIndexPattern } from '../../../../common/types';
+import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
+import type {
VisTypeTimeseriesRequest,
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
-import { AbstractSearchStrategy } from './abstract_search_strategy';
-import { RollupSearchCapabilities } from '../capabilities/rollup_search_capabilities';
-import { IndexPatternObject } from '../../../../common/types';
-import { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
-import { convertIndexPatternObjectToStringRepresentation } from '../../../../common/index_patterns_utils';
const getRollupIndices = (rollupData: { [key: string]: any }) => Object.keys(rollupData);
const isIndexPatternContainsWildcard = (indexPattern: string) => indexPattern.includes('*');
-const isIndexPatternValid = (indexPattern: string) =>
- indexPattern && typeof indexPattern === 'string' && !isIndexPatternContainsWildcard(indexPattern);
export class RollupSearchStrategy extends AbstractSearchStrategy {
async search(
@@ -52,15 +50,17 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
async checkForViability(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesRequest,
- indexPatternObject: IndexPatternObject
+ { indexPatternString, indexPattern }: FetchedIndexPattern
) {
let isViable = false;
let capabilities = null;
- const index = convertIndexPatternObjectToStringRepresentation(indexPatternObject);
-
- if (isIndexPatternValid(index)) {
- const rollupData = await this.getRollupData(requestContext, index);
+ if (
+ indexPatternString &&
+ !isIndexPatternContainsWildcard(indexPatternString) &&
+ (!indexPattern || indexPattern.type === 'rollup')
+ ) {
+ const rollupData = await this.getRollupData(requestContext, indexPatternString);
const rollupIndices = getRollupIndices(rollupData);
isViable = rollupIndices.length === 1;
@@ -80,20 +80,14 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
}
async getFieldsForWildcard(
- indexPatternObject: IndexPatternObject,
+ fetchedIndexPattern: FetchedIndexPattern,
indexPatternsService: IndexPatternsService,
getCachedIndexPatternFetcher: CachedIndexPatternFetcher,
capabilities?: unknown
) {
- return super.getFieldsForWildcard(
- indexPatternObject,
- indexPatternsService,
- getCachedIndexPatternFetcher,
- capabilities,
- {
- type: 'rollup',
- rollupIndex: convertIndexPatternObjectToStringRepresentation(indexPatternObject),
- }
- );
+ return super.getFieldsForWildcard(fetchedIndexPattern, indexPatternsService, capabilities, {
+ type: 'rollup',
+ rollupIndex: fetchedIndexPattern.indexPatternString,
+ });
}
}
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
index e1bc9c29ecf61..d6c6a24f98709 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
@@ -23,25 +23,18 @@ import type {
import type { PanelSchema } from '../../../common/types';
import { PANEL_TYPES } from '../../../common/panel_types';
-import {
- convertIndexPatternObjectToStringRepresentation,
- extractIndexPatternObjects,
-} from '../../../common/index_patterns_utils';
-
export async function getSeriesData(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesVisDataRequest,
panel: PanelSchema,
services: VisTypeTimeseriesRequestServices
) {
- const indexPattern = extractIndexPatternObjects(panel, panel.default_index_pattern)
- .map(convertIndexPatternObjectToStringRepresentation)
- .join(',');
+ const fetchedIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
- indexPattern
+ fetchedIndex
);
if (!strategy) {
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
index b882d8b529d76..8f9916bab5e92 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
@@ -17,7 +17,7 @@ import { handleErrorResponse } from './handle_error_response';
// @ts-expect-error
import { processBucket } from './table/process_bucket';
-import { createFieldsFetcher } from './helpers/fields_fetcher';
+import { createFieldsFetcher } from '../search_strategies/lib/fields_fetcher';
import { extractFieldLabel } from '../../../common/calculate_label';
import type {
VisTypeTimeseriesRequestHandlerContext,
@@ -32,14 +32,12 @@ export async function getTableData(
panel: PanelSchema,
services: VisTypeTimeseriesRequestServices
) {
- const { indexPattern, indexPatternString } = await services.cachedIndexPatternFetcher(
- panel.index_pattern
- );
+ const fetchedIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
- indexPatternString
+ fetchedIndex
);
if (!strategy) {
@@ -60,8 +58,8 @@ export async function getTableData(
});
const calculatePivotLabel = async () => {
- if (panel.pivot_id && indexPattern?.title) {
- const fields = await extractFields(indexPattern.title);
+ if (panel.pivot_id && fetchedIndex.indexPattern?.title) {
+ const fields = await extractFields(fetchedIndex.indexPattern.title);
return extractFieldLabel(fields, panel.pivot_id);
}
@@ -79,7 +77,7 @@ export async function getTableData(
req,
panel,
services.esQueryConfig,
- indexPattern,
+ fetchedIndex.indexPattern,
capabilities,
services.uiSettings
);
@@ -87,7 +85,7 @@ export async function getTableData(
const [resp] = await searchStrategy.search(requestContext, req, [
{
body,
- index: indexPatternString,
+ index: fetchedIndex.indexPatternString,
},
]);
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/handle_response_body.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/handle_response_body.ts
index 22e0372c23526..49f1ec0f93de5 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/handle_response_body.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/handle_response_body.ts
@@ -12,7 +12,10 @@ import { PanelSchema } from '../../../../common/types';
import { buildProcessorFunction } from '../build_processor_function';
// @ts-expect-error
import { processors } from '../response_processors/series';
-import { createFieldsFetcher, FieldsFetcherServices } from './../helpers/fields_fetcher';
+import {
+ createFieldsFetcher,
+ FieldsFetcherServices,
+} from '../../search_strategies/lib/fields_fetcher';
import { VisTypeTimeseriesVisDataRequest } from '../../../types';
export function handleResponseBody(
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts
new file mode 100644
index 0000000000000..9419efad41b83
--- /dev/null
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts
@@ -0,0 +1,48 @@
+/*
+ * 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 { SavedObjectReference } from '../../../../../core/types';
+
+export const extractControlsReferences = (
+ visState: Record,
+ references: SavedObjectReference[] = []
+) => {
+ const controls = visState.params?.controls ?? [];
+
+ controls.forEach((control: Record, i: number) => {
+ if (!control.indexPattern) {
+ return;
+ }
+ control.indexPatternRefName = `control_${i}_index_pattern`;
+ references.push({
+ name: control.indexPatternRefName,
+ type: 'index-pattern',
+ id: control.indexPattern,
+ });
+ delete control.indexPattern;
+ });
+};
+
+export const injectControlsReferences = (
+ visState: Record,
+ references: SavedObjectReference[]
+) => {
+ const controls = visState.params?.controls ?? [];
+
+ controls.forEach((control: Record) => {
+ if (!control.indexPatternRefName) {
+ return;
+ }
+ const reference = references.find((ref) => ref.name === control.indexPatternRefName);
+ if (!reference) {
+ throw new Error(`Could not find index pattern reference "${control.indexPatternRefName}"`);
+ }
+ control.indexPattern = reference.id;
+ delete control.indexPatternRefName;
+ });
+};
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/index.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/index.ts
new file mode 100644
index 0000000000000..727005b7f1836
--- /dev/null
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/index.ts
@@ -0,0 +1,9 @@
+/*
+ * 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.
+ */
+
+export { extractReferences, injectReferences } from './saved_visualization_references';
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.test.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.test.ts
similarity index 97%
rename from src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.test.ts
rename to src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.test.ts
index f81054febcc44..3961d303382f0 100644
--- a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.test.ts
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.test.ts
@@ -7,8 +7,8 @@
*/
import { extractReferences, injectReferences } from './saved_visualization_references';
-import { VisSavedObject } from '../types';
-import { SavedVisState } from '../../common';
+import { VisSavedObject } from '../../types';
+import { SavedVisState } from '../../../common';
describe('extractReferences', () => {
test('extracts nothing if savedSearchId is empty', () => {
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.ts
similarity index 68%
rename from src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.ts
rename to src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.ts
index 27b5a4542036b..4afd1bf5980a9 100644
--- a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references.ts
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/saved_visualization_references.ts
@@ -10,13 +10,16 @@ import {
SavedObjectAttribute,
SavedObjectAttributes,
SavedObjectReference,
-} from '../../../../core/public';
-import { VisSavedObject } from '../types';
+} from '../../../../../core/public';
+import { VisSavedObject } from '../../types';
import {
extractSearchSourceReferences,
injectSearchSourceReferences,
SearchSourceFields,
-} from '../../../data/public';
+} from '../../../../data/public';
+
+import { extractTimeSeriesReferences, injectTimeSeriesReferences } from './timeseries_references';
+import { extractControlsReferences, injectControlsReferences } from './controls_references';
export function extractReferences({
attributes,
@@ -50,19 +53,10 @@ export function extractReferences({
// Extract index patterns from controls
if (updatedAttributes.visState) {
const visState = JSON.parse(String(updatedAttributes.visState));
- const controls = (visState.params && visState.params.controls) || [];
- controls.forEach((control: Record, i: number) => {
- if (!control.indexPattern) {
- return;
- }
- control.indexPatternRefName = `control_${i}_index_pattern`;
- updatedReferences.push({
- name: control.indexPatternRefName,
- type: 'index-pattern',
- id: control.indexPattern,
- });
- delete control.indexPattern;
- });
+
+ extractControlsReferences(visState, updatedReferences);
+ extractTimeSeriesReferences(visState, updatedReferences);
+
updatedAttributes.visState = JSON.stringify(visState);
}
@@ -89,18 +83,9 @@ export function injectReferences(savedObject: VisSavedObject, references: SavedO
savedObject.savedSearchId = savedSearchReference.id;
delete savedObject.savedSearchRefName;
}
- if (savedObject.visState) {
- const controls = (savedObject.visState.params && savedObject.visState.params.controls) || [];
- controls.forEach((control: Record) => {
- if (!control.indexPatternRefName) {
- return;
- }
- const reference = references.find((ref) => ref.name === control.indexPatternRefName);
- if (!reference) {
- throw new Error(`Could not find index pattern reference "${control.indexPatternRefName}"`);
- }
- control.indexPattern = reference.id;
- delete control.indexPatternRefName;
- });
+
+ if (savedObject.visState?.params) {
+ injectControlsReferences(savedObject.visState, references);
+ injectTimeSeriesReferences(savedObject.visState, references);
}
}
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts
new file mode 100644
index 0000000000000..c825972bcc096
--- /dev/null
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts
@@ -0,0 +1,82 @@
+/*
+ * 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 { SavedObjectReference } from '../../../../../core/types';
+
+/** @internal **/
+const REF_NAME_POSTFIX = '_ref_name';
+
+/** @internal **/
+enum INDEX_TYPE {
+ KIBANA_INDEX_PATTERN = 'index-pattern',
+ STRING_INDEX_PATTERN = 'string-index-pattern',
+}
+
+/** @internal **/
+type Action = (object: Record, key: string) => void;
+
+const doForExtractedIndices = (action: Action, visState: Record) => {
+ if (visState.type !== 'metrics') {
+ return;
+ }
+
+ action(visState.params, 'index_pattern');
+
+ visState.params.series.forEach((series: any) => {
+ if (series.override_index_pattern) {
+ action(series, 'series_index_pattern');
+ }
+ });
+
+ if (visState.params.annotations) {
+ visState.params.annotations.forEach((annotation: any) => {
+ action(annotation, 'index_pattern');
+ });
+ }
+};
+
+export const extractTimeSeriesReferences = (
+ visState: Record,
+ references: SavedObjectReference[] = []
+) => {
+ let i = 0;
+
+ doForExtractedIndices((object, key) => {
+ if (object[key]) {
+ const name = `ref_${++i}_index_pattern`;
+
+ object[key + REF_NAME_POSTFIX] = name;
+ references.push({
+ name,
+ type: object[key].id ? INDEX_TYPE.KIBANA_INDEX_PATTERN : INDEX_TYPE.STRING_INDEX_PATTERN,
+ id: object[key].id || object[key],
+ });
+ delete object[key];
+ }
+ }, visState);
+};
+
+export const injectTimeSeriesReferences = (
+ visState: Record,
+ references: SavedObjectReference[]
+) => {
+ doForExtractedIndices((object, key) => {
+ const refKey = key + REF_NAME_POSTFIX;
+
+ if (object[refKey]) {
+ const refValue = references.find((ref) => ref.name === object[refKey]);
+
+ if (refValue) {
+ object[key] =
+ refValue.type === INDEX_TYPE.KIBANA_INDEX_PATTERN ? { id: refValue.id } : refValue.id;
+ }
+
+ delete object[refKey];
+ }
+ }, visState);
+};
From 4df3d13580a497cdf702b7ed03fdfb663474dab8 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Thu, 18 Mar 2021 16:13:20 +0300
Subject: [PATCH 26/39] remove wrong logic
---
.../common/index_patterns_utils.test.ts | 14 --------------
.../common/index_patterns_utils.ts | 4 +---
2 files changed, 1 insertion(+), 17 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts b/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
index a541288e07d36..929391662468e 100644
--- a/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
+++ b/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
@@ -135,19 +135,5 @@ describe('fetchIndexPattern', () => {
}
`);
});
-
- test('should return default index if Kibana index not found', async () => {
- const value = await fetchIndexPattern({ id: 'indexId' }, indexPatternsService);
-
- expect(value).toMatchInlineSnapshot(`
- Object {
- "indexPattern": Object {
- "id": "default",
- "title": "index",
- },
- "indexPatternString": "index",
- }
- `);
- });
});
});
diff --git a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
index 4905b0cfc287d..d07dc977cac1a 100644
--- a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
+++ b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
@@ -69,9 +69,7 @@ export const fetchIndexPattern = async (
indexPatternString = indexPatternObject;
}
} else if (indexPatternObject.id) {
- indexPattern =
- (await indexPatternsService.get(indexPatternObject.id)) ??
- (await indexPatternsService.getDefault());
+ indexPattern = await indexPatternsService.get(indexPatternObject.id);
}
}
From ecdb580e19393a843cb722d3d380ea8687429c37 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Fri, 19 Mar 2021 12:57:46 +0300
Subject: [PATCH 27/39] fix JEST
---
.../lib/cached_index_pattern_fetcher.test.ts | 7 ++-----
.../search_strategies/search_strategies_registry.test.ts | 6 ++----
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
index 016960691dd83..aeaf3ca2cd327 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.test.ts
@@ -102,11 +102,8 @@ describe('CachedIndexPatternFetcher', () => {
expect(value).toMatchInlineSnapshot(`
Object {
- "indexPattern": Object {
- "id": "default",
- "title": "index",
- },
- "indexPatternString": "index",
+ "indexPattern": undefined,
+ "indexPatternString": "",
}
`);
});
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategies_registry.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategies_registry.test.ts
index 7b3e6a2888431..a6e7c5b11ee64 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategies_registry.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/search_strategies_registry.test.ts
@@ -45,12 +45,11 @@ describe('SearchStrategyRegister', () => {
test('should return a DefaultSearchStrategy instance', async () => {
const req = {} as VisTypeTimeseriesRequest;
- const indexPattern = '*';
const { searchStrategy, capabilities } = (await registry.getViableStrategy(
requestContext,
req,
- indexPattern
+ { indexPatternString: '*', indexPattern: undefined }
))!;
expect(searchStrategy instanceof DefaultSearchStrategy).toBe(true);
@@ -67,14 +66,13 @@ describe('SearchStrategyRegister', () => {
test('should return a MockSearchStrategy instance', async () => {
const req = {} as VisTypeTimeseriesRequest;
- const indexPattern = '*';
const anotherSearchStrategy = new MockSearchStrategy();
registry.addStrategy(anotherSearchStrategy);
const { searchStrategy, capabilities } = (await registry.getViableStrategy(
requestContext,
req,
- indexPattern
+ { indexPatternString: '*', indexPattern: undefined }
))!;
expect(searchStrategy instanceof MockSearchStrategy).toBe(true);
From 83d958de93b41c074cfd9fd21f019a22b80559f8 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Fri, 19 Mar 2021 17:13:17 +0300
Subject: [PATCH 28/39] fix some ui issues
---
.../vis_type_timeseries/common/types.ts | 2 +-
.../index_pattern_select/combo_box_select.tsx | 25 +++----
.../field_text_select.tsx | 14 ++--
.../index_pattern_select.tsx | 71 +++++++++++--------
.../index_pattern_select/migrate_popover.tsx | 20 +++---
.../switch_mode_popover.tsx | 8 ++-
.../lib/index_pattern_select/types.ts | 6 +-
.../timeseries_references.ts | 14 ++--
8 files changed, 90 insertions(+), 70 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/common/types.ts b/src/plugins/vis_type_timeseries/common/types.ts
index 82563d8748553..0aa1d0e22cdbe 100644
--- a/src/plugins/vis_type_timeseries/common/types.ts
+++ b/src/plugins/vis_type_timeseries/common/types.ts
@@ -30,7 +30,7 @@ export type IndexPatternObject = TypeOf;
export interface FetchedIndexPattern {
indexPattern: IndexPattern | undefined | null;
- indexPatternString: string;
+ indexPatternString: string | undefined;
}
interface PanelData {
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
index 8a7314134a77a..0e1713d6c05f7 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
@@ -38,17 +38,25 @@ export const ComboBoxSelect = ({
const [availableIndexes, setAvailableIndexes] = useState([]);
const [selectedOptions, setSelectedOptions] = useState([]);
+ const onComboBoxChange: EuiComboBoxProps['onChange'] = useCallback(
+ ([selected]) => {
+ onIndexChange(selected ? { id: selected.id } : '');
+ },
+ [onIndexChange]
+ );
+
useEffect(() => {
let options: SelectedOptions = [];
+ const { indexPattern, indexPatternString } = fetchedIndex;
- if (fetchedIndex) {
- if (!fetchedIndex.indexPattern) {
- options = [{ label: fetchedIndex.indexPatternString ?? '' }];
+ if (indexPattern || indexPatternString) {
+ if (!indexPattern) {
+ options = [{ label: indexPatternString ?? '' }];
} else {
options = [
{
- id: fetchedIndex.indexPattern.id,
- label: fetchedIndex.indexPattern.title,
+ id: indexPattern.id,
+ label: indexPattern.title,
},
];
}
@@ -56,13 +64,6 @@ export const ComboBoxSelect = ({
setSelectedOptions(options);
}, [fetchedIndex]);
- const onComboBoxChange: EuiComboBoxProps['onChange'] = useCallback(
- ([selected]) => {
- onIndexChange(selected ? { id: selected.id } : '');
- },
- [onIndexChange]
- );
-
useEffect(() => {
async function fetchIndexes() {
setAvailableIndexes(await getDataStart().indexPatterns.getIdsWithTitle());
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
index 5e176eeeaec74..fff5e86395273 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
@@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
-import React, { useCallback, useState } from 'react';
+import React, { useCallback, useState, useEffect } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { EuiFieldText, EuiFieldTextProps } from '@elastic/eui';
@@ -22,16 +22,20 @@ export const FieldTextSelect = ({
allowSwitchMode,
'data-test-subj': dataTestSubj,
}: SelectIndexComponentProps) => {
- const textualValue = fetchedIndex?.indexPatternString ?? '';
- const [inputValue, setInputValue] = useState(textualValue);
+ const [inputValue, setInputValue] = useState();
+ const { indexPatternString } = fetchedIndex;
const onFieldTextChange: EuiFieldTextProps['onChange'] = useCallback((e) => {
setInputValue(e.target.value);
}, []);
+ useEffect(() => {
+ setInputValue(indexPatternString ?? '');
+ }, [indexPatternString]);
+
useDebounce(
() => {
- if (inputValue !== textualValue) {
+ if (inputValue !== indexPatternString) {
onIndexChange(inputValue);
}
},
@@ -43,7 +47,7 @@ export const FieldTextSelect = ({
{
const htmlId = htmlIdGenerator();
const panelModel = useContext(PanelModelContext);
- const [fetchedIndex, setFetchedIndex] = useState();
-
+ const [fetchedIndex, setFetchedIndex] = useState();
const useKibanaIndices = Boolean(panelModel?.[USE_KIBANA_INDEXES_KEY]);
const Component = useKibanaIndices ? ComboBoxSelect : FieldTextSelect;
- useEffect(() => {
- async function fetchIndex() {
- const { indexPatterns } = getDataStart();
-
- setFetchedIndex(value ? await fetchIndexPattern(value, indexPatterns) : undefined);
- }
-
- fetchIndex();
- }, [value]);
+ const onIndexChange = useCallback(
+ (index: IndexPatternObject) => {
+ onChange({
+ [indexPatternName]: index,
+ });
+ },
+ [indexPatternName, onChange]
+ );
const onModeChange = useCallback(
- (useKibanaIndexes: boolean) => {
+ (useKibanaIndexes: boolean, index?: FetchedIndexPattern) => {
onChange({
[USE_KIBANA_INDEXES_KEY]: useKibanaIndexes,
- [indexPatternName]: fetchedIndex?.indexPattern
+ [indexPatternName]: index?.indexPattern?.id
? {
- id: fetchedIndex.indexPattern.id!,
+ id: index.indexPattern.id,
}
: '',
});
},
- [onChange, fetchedIndex, indexPatternName]
+ [onChange, indexPatternName]
);
- const onIndexChange = useCallback(
- (index: IndexPatternObject) => {
- onChange({
- [indexPatternName]: index,
- });
- },
- [indexPatternName, onChange]
- );
+ useEffect(() => {
+ async function fetchIndex() {
+ const { indexPatterns } = getDataStart();
+
+ setFetchedIndex(
+ value
+ ? await fetchIndexPattern(value, indexPatterns)
+ : {
+ indexPattern: undefined,
+ indexPatternString: undefined,
+ }
+ );
+ }
+
+ fetchIndex();
+ }, [value]);
+
+ if (!fetchedIndex) {
+ return null;
+ }
return (
setIsPopoverOpen((isOpen) => !isOpen), []);
const switchMode = useCallback(() => {
- onModeChange(true);
- }, [onModeChange]);
+ onModeChange(true, fetchedIndex);
+ }, [onModeChange, fetchedIndex]);
const navigateToCreateIndexPatterns = useCallback(() => {
- getCoreStart().application.navigateToApp('management', {
- path: `/kibana/indexPatterns/create?name=${fetchedIndex?.indexPatternString ?? ''}`,
+ const coreStart = getCoreStart();
+
+ coreStart.application.navigateToApp('management', {
+ path: `/kibana/indexPatterns/create?name=${fetchedIndex.indexPatternString ?? ''}`,
});
}, [fetchedIndex]);
- if (!fetchedIndex) {
+ if (!fetchedIndex.indexPatternString) {
return null;
}
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/switch_mode_popover.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/switch_mode_popover.tsx
index 3b186af65336b..5f5506ce4a332 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/switch_mode_popover.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/switch_mode_popover.tsx
@@ -7,6 +7,9 @@
*/
import React, { useState, useCallback } from 'react';
+import { i18n } from '@kbn/i18n';
+import { FormattedMessage } from '@kbn/i18n/react';
+
import {
EuiButtonIcon,
EuiPopover,
@@ -15,9 +18,8 @@ import {
EuiSwitch,
EuiText,
} from '@elastic/eui';
-import { i18n } from '@kbn/i18n';
-import { FormattedMessage } from '@kbn/i18n/react';
-import { PopoverProps } from './types';
+
+import type { PopoverProps } from './types';
export const SwitchModePopover = ({ onModeChange, useKibanaIndices }: PopoverProps) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
index 58a9e6dadb60d..0e7eed0d16654 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
@@ -5,14 +5,14 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
-import { Assign } from '@kbn/utility-types';
+import type { Assign } from '@kbn/utility-types';
import type { FetchedIndexPattern, IndexPatternObject } from '../../../../../common/types';
/** @internal **/
export interface SelectIndexComponentProps {
- fetchedIndex: FetchedIndexPattern | undefined;
+ fetchedIndex: FetchedIndexPattern;
onIndexChange: (value: IndexPatternObject) => void;
- onModeChange: (useKibanaIndexes: boolean) => void;
+ onModeChange: (useKibanaIndexes: boolean, index?: FetchedIndexPattern) => void;
'data-test-subj': string;
placeholder?: string;
disabled?: boolean;
diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts
index c825972bcc096..2a3fccb797799 100644
--- a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts
+++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts
@@ -12,10 +12,7 @@ import { SavedObjectReference } from '../../../../../core/types';
const REF_NAME_POSTFIX = '_ref_name';
/** @internal **/
-enum INDEX_TYPE {
- KIBANA_INDEX_PATTERN = 'index-pattern',
- STRING_INDEX_PATTERN = 'string-index-pattern',
-}
+const INDEX_PATTERN_REF_TYPE = 'index_pattern';
/** @internal **/
type Action = (object: Record, key: string) => void;
@@ -47,14 +44,14 @@ export const extractTimeSeriesReferences = (
let i = 0;
doForExtractedIndices((object, key) => {
- if (object[key]) {
+ if (object[key] && object[key].id) {
const name = `ref_${++i}_index_pattern`;
object[key + REF_NAME_POSTFIX] = name;
references.push({
name,
- type: object[key].id ? INDEX_TYPE.KIBANA_INDEX_PATTERN : INDEX_TYPE.STRING_INDEX_PATTERN,
- id: object[key].id || object[key],
+ type: INDEX_PATTERN_REF_TYPE,
+ id: object[key].id,
});
delete object[key];
}
@@ -72,8 +69,7 @@ export const injectTimeSeriesReferences = (
const refValue = references.find((ref) => ref.name === object[refKey]);
if (refValue) {
- object[key] =
- refValue.type === INDEX_TYPE.KIBANA_INDEX_PATTERN ? { id: refValue.id } : refValue.id;
+ object[key] = { id: refValue.id };
}
delete object[refKey];
From 9fd52a932d989d6e764a530735e71e4187fbcbdb Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Fri, 19 Mar 2021 17:56:25 +0300
Subject: [PATCH 29/39] update sample data
---
.../data_sets/ecommerce/saved_objects.ts | 25 ++++++++++++++++---
.../data_sets/flights/saved_objects.ts | 15 +++++++++--
.../data_sets/logs/saved_objects.ts | 25 ++++++++++++++++---
.../lib/cached_index_pattern_fetcher.ts | 5 ++--
.../strategies/abstract_search_strategy.ts | 2 +-
.../strategies/default_search_strategy.ts | 2 +-
.../strategies/rollup_search_strategy.test.ts | 7 +++---
.../server/lib/vis_data/get_series_data.ts | 6 ++---
.../server/lib/vis_data/get_table_data.ts | 12 ++++-----
.../lib/vis_data/series/get_request_params.ts | 23 +++++++++++------
10 files changed, 88 insertions(+), 34 deletions(-)
diff --git a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts
index 9b69dacd8fdb5..cfac42b97c686 100644
--- a/src/plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts
+++ b/src/plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts
@@ -109,7 +109,7 @@ export const getSavedObjects = (): SavedObject[] => [
defaultMessage: '[eCommerce] Promotion Tracking',
}),
visState:
- '{"title":"[eCommerce] Promotion Tracking","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"ea20ae70-b88d-11e8-a451-f37365e9f268","color":"rgba(240,138,217,1)","split_mode":"everything","metrics":[{"id":"ea20ae71-b88d-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*trouser*","label":"Revenue Trousers","value_template":"${{value}}"},{"id":"062d77b0-b88e-11e8-a451-f37365e9f268","color":"rgba(191,240,129,1)","split_mode":"everything","metrics":[{"id":"062d77b1-b88e-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*watch*","label":"Revenue Watches","value_template":"${{value}}"},{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(23,233,230,1)","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*bag*","label":"Revenue Bags","value_template":"${{value}}"},{"id":"faa2c170-b88d-11e8-a451-f37365e9f268","color":"rgba(235,186,180,1)","split_mode":"everything","metrics":[{"id":"faa2c171-b88d-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*cocktail dress*","label":"Revenue Cocktail Dresses","value_template":"${{value}}"}],"time_field":"order_date","index_pattern":"kibana_sample_data_ecommerce","interval":">=12h","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"legend_position":"bottom","annotations":[{"fields":"taxful_total_price","template":"Ring the bell! ${{taxful_total_price}}","index_pattern":"kibana_sample_data_ecommerce","query_string":"taxful_total_price:>250","id":"c8c30be0-b88f-11e8-a451-f37365e9f268","color":"rgba(25,77,51,1)","time_field":"order_date","icon":"fa-bell","ignore_global_filters":1,"ignore_panel_filters":1}]},"aggs":[]}',
+ '{"title":"[eCommerce] Promotion Tracking","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"ea20ae70-b88d-11e8-a451-f37365e9f268","color":"rgba(240,138,217,1)","split_mode":"everything","metrics":[{"id":"ea20ae71-b88d-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*trouser*","label":"Revenue Trousers","value_template":"${{value}}"},{"id":"062d77b0-b88e-11e8-a451-f37365e9f268","color":"rgba(191,240,129,1)","split_mode":"everything","metrics":[{"id":"062d77b1-b88e-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*watch*","label":"Revenue Watches","value_template":"${{value}}"},{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(23,233,230,1)","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*bag*","label":"Revenue Bags","value_template":"${{value}}"},{"id":"faa2c170-b88d-11e8-a451-f37365e9f268","color":"rgba(235,186,180,1)","split_mode":"everything","metrics":[{"id":"faa2c171-b88d-11e8-a451-f37365e9f268","type":"sum","field":"taxful_total_price"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":"0.7","stacked":"none","filter":"products.product_name:*cocktail dress*","label":"Revenue Cocktail Dresses","value_template":"${{value}}"}],"time_field":"order_date","index_pattern_ref_name":"ref_1_index_pattern","interval":">=12h","use_kibana_indexes":true,"axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"legend_position":"bottom","annotations":[{"fields":"taxful_total_price","template":"Ring the bell! ${{taxful_total_price}}","index_pattern_ref_name":"ref_2_index_pattern","query_string":"taxful_total_price:>250","id":"c8c30be0-b88f-11e8-a451-f37365e9f268","color":"rgba(25,77,51,1)","time_field":"order_date","icon":"fa-bell","ignore_global_filters":1,"ignore_panel_filters":1}]},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@@ -117,7 +117,18 @@ export const getSavedObjects = (): SavedObject[] => [
searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}',
},
},
- references: [],
+ references: [
+ {
+ name: 'ref_1_index_pattern',
+ type: 'index_pattern',
+ id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f',
+ },
+ {
+ name: 'ref_2_index_pattern',
+ type: 'index_pattern',
+ id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f',
+ },
+ ],
},
{
id: '10f1a240-b891-11e8-a6d9-e546fe2bba5f',
@@ -152,7 +163,7 @@ export const getSavedObjects = (): SavedObject[] => [
defaultMessage: '[eCommerce] Sold Products per Day',
}),
visState:
- '{"title":"[eCommerce] Sold Products per Day","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"gauge","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"#68BC00","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Trxns / day"}],"time_field":"order_date","index_pattern":"kibana_sample_data_ecommerce","interval":"1d","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"gauge_color_rules":[{"value":150,"id":"6da070c0-b891-11e8-b645-195edeb9de84","gauge":"rgba(104,188,0,1)","operator":"gte"},{"value":150,"id":"9b0cdbc0-b891-11e8-b645-195edeb9de84","gauge":"rgba(244,78,59,1)","operator":"lt"}],"gauge_width":"15","gauge_inner_width":10,"gauge_style":"half","filter":"","gauge_max":"300"},"aggs":[]}',
+ '{"title":"[eCommerce] Sold Products per Day","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"gauge","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"#68BC00","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"count"}],"separate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Trxns / day"}],"time_field":"order_date","index_pattern_ref_name":"ref_1_index_pattern","interval":"1d","axis_position":"left","axis_formatter":"number","axis_scale":"normal","show_legend":1,"show_grid":1,"gauge_color_rules":[{"value":150,"id":"6da070c0-b891-11e8-b645-195edeb9de84","gauge":"rgba(104,188,0,1)","operator":"gte"},{"value":150,"id":"9b0cdbc0-b891-11e8-b645-195edeb9de84","gauge":"rgba(244,78,59,1)","operator":"lt"}],"gauge_width":"15","gauge_inner_width":10,"gauge_style":"half","filter":"","gauge_max":"300","use_kibana_indexes":true},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@@ -160,7 +171,13 @@ export const getSavedObjects = (): SavedObject[] => [
searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}',
},
},
- references: [],
+ references: [
+ {
+ name: 'ref_1_index_pattern',
+ type: 'index_pattern',
+ id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f',
+ },
+ ],
},
{
id: '4b3ec120-b892-11e8-a6d9-e546fe2bba5f',
diff --git a/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts b/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts
index b316835029d7c..f16c1c7104417 100644
--- a/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts
+++ b/src/plugins/home/server/services/sample_data/data_sets/flights/saved_objects.ts
@@ -144,7 +144,7 @@ export const getSavedObjects = (): SavedObject[] => [
defaultMessage: '[Flights] Delays & Cancellations',
}),
visState:
- '{"title":"[Flights] Delays & Cancellations","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(0,156,224,1)","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"filter_ratio","numerator":"FlightDelay:true"}],"separate_axis":0,"axis_position":"right","formatter":"percent","chart_type":"line","line_width":"2","point_size":"0","fill":0.5,"stacked":"none","label":"Percent Delays"}],"time_field":"timestamp","index_pattern":"kibana_sample_data_flights","interval":">=1h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"annotations":[{"fields":"FlightDelay,Cancelled,Carrier","template":"{{Carrier}}: Flight Delayed and Cancelled!","index_pattern":"kibana_sample_data_flights","query_string":"FlightDelay:true AND Cancelled:true","id":"53b7dff0-4c89-11e8-a66a-6989ad5a0a39","color":"rgba(0,98,177,1)","time_field":"timestamp","icon":"fa-exclamation-triangle","ignore_global_filters":1,"ignore_panel_filters":1}],"legend_position":"bottom"},"aggs":[]}',
+ '{"title":"[Flights] Delays & Cancellations","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(0,156,224,1)","split_mode":"everything","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"filter_ratio","numerator":"FlightDelay:true"}],"separate_axis":0,"axis_position":"right","formatter":"percent","chart_type":"line","line_width":"2","point_size":"0","fill":0.5,"stacked":"none","label":"Percent Delays"}],"time_field":"timestamp","index_pattern_ref_name":"ref_1_index_pattern","interval":">=1h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"annotations":[{"fields":"FlightDelay,Cancelled,Carrier","template":"{{Carrier}}: Flight Delayed and Cancelled!","index_pattern_ref_name":"ref_2_index_pattern","query_string":"FlightDelay:true AND Cancelled:true","id":"53b7dff0-4c89-11e8-a66a-6989ad5a0a39","color":"rgba(0,98,177,1)","time_field":"timestamp","icon":"fa-exclamation-triangle","ignore_global_filters":1,"ignore_panel_filters":1}],"legend_position":"bottom","use_kibana_indexes":true},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@@ -152,7 +152,18 @@ export const getSavedObjects = (): SavedObject[] => [
searchSourceJSON: '{}',
},
},
- references: [],
+ references: [
+ {
+ name: 'ref_1_index_pattern',
+ type: 'index_pattern',
+ id: 'd3d7af60-4c81-11e8-b3d7-01146121b73d'
+ },
+ {
+ name: 'ref_2_index_pattern',
+ type: 'index_pattern',
+ id: 'd3d7af60-4c81-11e8-b3d7-01146121b73d'
+ }
+ ]
},
{
id: '9886b410-4c8b-11e8-b3d7-01146121b73d',
diff --git a/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts b/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts
index 0396cb58d3692..8a3469fe4f3c0 100644
--- a/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts
+++ b/src/plugins/home/server/services/sample_data/data_sets/logs/saved_objects.ts
@@ -89,7 +89,7 @@ export const getSavedObjects = (): SavedObject[] => [
defaultMessage: '[Logs] Host, Visits and Bytes Table',
}),
visState:
- '{"title":"[Logs] Host, Visits and Bytes Table","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"table","series":[{"id":"bd09d600-e5b1-11e7-bfc2-a1f7e71965a1","color":"#68BC00","split_mode":"everything","metrics":[{"id":"bd09d601-e5b1-11e7-bfc2-a1f7e71965a1","type":"sum","field":"bytes"},{"sigma":"","id":"c9514c90-e5b1-11e7-bfc2-a1f7e71965a1","type":"sum_bucket","field":"bd09d601-e5b1-11e7-bfc2-a1f7e71965a1"}],"seperate_axis":0,"axis_position":"right","formatter":"bytes","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","color_rules":[{"id":"c0c668d0-e5b1-11e7-bfc2-a1f7e71965a1"}],"label":"Bytes (Total)"},{"id":"b7672c30-a6df-11e8-8b18-1da1dfc50975","color":"#68BC00","split_mode":"everything","metrics":[{"id":"b7672c31-a6df-11e8-8b18-1da1dfc50975","type":"sum","field":"bytes"}],"seperate_axis":0,"axis_position":"right","formatter":"bytes","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","color_rules":[{"id":"c0c668d0-e5b1-11e7-bfc2-a1f7e71965a1"}],"label":"Bytes (Last Hour)"},{"id":"f2c20700-a6df-11e8-8b18-1da1dfc50975","color":"#68BC00","split_mode":"everything","metrics":[{"id":"f2c20701-a6df-11e8-8b18-1da1dfc50975","type":"cardinality","field":"ip"},{"sigma":"","id":"f46333e0-a6df-11e8-8b18-1da1dfc50975","type":"sum_bucket","field":"f2c20701-a6df-11e8-8b18-1da1dfc50975"}],"seperate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Unique Visits (Total)","color_rules":[{"value":1000,"id":"2e963080-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(211,49,21,1)","operator":"lt"},{"value":1000,"id":"3d4fb880-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(252,196,0,1)","operator":"gte"},{"value":1500,"id":"435f8a20-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(104,188,0,1)","operator":"gte"}],"offset_time":"","value_template":"","trend_arrows":1},{"id":"46fd7fc0-e5b1-11e7-bfc2-a1f7e71965a1","color":"#68BC00","split_mode":"everything","metrics":[{"id":"46fd7fc1-e5b1-11e7-bfc2-a1f7e71965a1","type":"cardinality","field":"ip"}],"seperate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Unique Visits (Last Hour)","color_rules":[{"value":10,"id":"4e90aeb0-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(211,49,21,1)","operator":"lt"},{"value":10,"id":"6d59b1c0-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(252,196,0,1)","operator":"gte"},{"value":25,"id":"77578670-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(104,188,0,1)","operator":"gte"}],"offset_time":"","value_template":"","trend_arrows":1}],"time_field":"timestamp","index_pattern":"kibana_sample_data_logs","interval":"1h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"bar_color_rules":[{"id":"e9b4e490-e1c6-11e7-b4f6-0f68c45f7387"}],"pivot_id":"extension.keyword","pivot_label":"Type","drilldown_url":"","axis_scale":"normal"},"aggs":[]}',
+ '{"title":"[Logs] Host, Visits and Bytes Table","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"table","series":[{"id":"bd09d600-e5b1-11e7-bfc2-a1f7e71965a1","color":"#68BC00","split_mode":"everything","metrics":[{"id":"bd09d601-e5b1-11e7-bfc2-a1f7e71965a1","type":"sum","field":"bytes"},{"sigma":"","id":"c9514c90-e5b1-11e7-bfc2-a1f7e71965a1","type":"sum_bucket","field":"bd09d601-e5b1-11e7-bfc2-a1f7e71965a1"}],"seperate_axis":0,"axis_position":"right","formatter":"bytes","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","color_rules":[{"id":"c0c668d0-e5b1-11e7-bfc2-a1f7e71965a1"}],"label":"Bytes (Total)"},{"id":"b7672c30-a6df-11e8-8b18-1da1dfc50975","color":"#68BC00","split_mode":"everything","metrics":[{"id":"b7672c31-a6df-11e8-8b18-1da1dfc50975","type":"sum","field":"bytes"}],"seperate_axis":0,"axis_position":"right","formatter":"bytes","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","color_rules":[{"id":"c0c668d0-e5b1-11e7-bfc2-a1f7e71965a1"}],"label":"Bytes (Last Hour)"},{"id":"f2c20700-a6df-11e8-8b18-1da1dfc50975","color":"#68BC00","split_mode":"everything","metrics":[{"id":"f2c20701-a6df-11e8-8b18-1da1dfc50975","type":"cardinality","field":"ip"},{"sigma":"","id":"f46333e0-a6df-11e8-8b18-1da1dfc50975","type":"sum_bucket","field":"f2c20701-a6df-11e8-8b18-1da1dfc50975"}],"seperate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Unique Visits (Total)","color_rules":[{"value":1000,"id":"2e963080-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(211,49,21,1)","operator":"lt"},{"value":1000,"id":"3d4fb880-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(252,196,0,1)","operator":"gte"},{"value":1500,"id":"435f8a20-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(104,188,0,1)","operator":"gte"}],"offset_time":"","value_template":"","trend_arrows":1},{"id":"46fd7fc0-e5b1-11e7-bfc2-a1f7e71965a1","color":"#68BC00","split_mode":"everything","metrics":[{"id":"46fd7fc1-e5b1-11e7-bfc2-a1f7e71965a1","type":"cardinality","field":"ip"}],"seperate_axis":0,"axis_position":"right","formatter":"number","chart_type":"line","line_width":1,"point_size":1,"fill":0.5,"stacked":"none","label":"Unique Visits (Last Hour)","color_rules":[{"value":10,"id":"4e90aeb0-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(211,49,21,1)","operator":"lt"},{"value":10,"id":"6d59b1c0-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(252,196,0,1)","operator":"gte"},{"value":25,"id":"77578670-a6e0-11e8-8b18-1da1dfc50975","text":"rgba(104,188,0,1)","operator":"gte"}],"offset_time":"","value_template":"","trend_arrows":1}],"time_field":"timestamp","index_pattern_ref_name":"ref_1_index_pattern","use_kibana_indexes": true,"interval":"1h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"bar_color_rules":[{"id":"e9b4e490-e1c6-11e7-b4f6-0f68c45f7387"}],"pivot_id":"extension.keyword","pivot_label":"Type","drilldown_url":"","axis_scale":"normal"},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@@ -97,7 +97,13 @@ export const getSavedObjects = (): SavedObject[] => [
searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}',
},
},
- references: [],
+ references: [
+ {
+ name: 'ref_1_index_pattern',
+ type: 'index_pattern',
+ id: '90943e30-9a47-11e8-b64d-95841ca0b247',
+ },
+ ],
},
{
id: '69a34b00-9ee8-11e7-8711-e7a007dcef99',
@@ -175,7 +181,7 @@ export const getSavedObjects = (): SavedObject[] => [
defaultMessage: '[Logs] Response Codes Over Time + Annotations',
}),
visState:
- '{"title":"[Logs] Response Codes Over Time + Annotations","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(115,216,255,1)","split_mode":"terms","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"cardinality","field":"ip"}],"seperate_axis":0,"axis_position":"right","formatter":"percent","chart_type":"line","line_width":"2","point_size":"0","fill":"0.5","stacked":"percent","terms_field":"response.keyword","terms_order_by":"61ca57f2-469d-11e7-af02-69e470af7417","label":"Response Code Count","split_color_mode":"gradient"}],"time_field":"timestamp","index_pattern":"kibana_sample_data_logs","interval":">=4h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"annotations":[{"fields":"geo.src, host","template":"Security Error from {{geo.src}} on {{host}}","index_pattern":"kibana_sample_data_logs","query_string":"tags:error AND tags:security","id":"bd7548a0-2223-11e8-832f-d5027f3c8a47","color":"rgba(211,49,21,1)","time_field":"timestamp","icon":"fa-asterisk","ignore_global_filters":1,"ignore_panel_filters":1}],"legend_position":"bottom","axis_scale":"normal","drop_last_bucket":0},"aggs":[]}',
+ '{"title":"[Logs] Response Codes Over Time + Annotations","type":"metrics","params":{"id":"61ca57f0-469d-11e7-af02-69e470af7417","type":"timeseries","series":[{"id":"61ca57f1-469d-11e7-af02-69e470af7417","color":"rgba(115,216,255,1)","split_mode":"terms","metrics":[{"id":"61ca57f2-469d-11e7-af02-69e470af7417","type":"cardinality","field":"ip"}],"seperate_axis":0,"axis_position":"right","formatter":"percent","chart_type":"line","line_width":"2","point_size":"0","fill":"0.5","stacked":"percent","terms_field":"response.keyword","terms_order_by":"61ca57f2-469d-11e7-af02-69e470af7417","label":"Response Code Count","split_color_mode":"gradient"}],"time_field":"timestamp","index_pattern_ref_name":"ref_1_index_pattern","use_kibana_indexes":true,"interval":">=4h","axis_position":"left","axis_formatter":"number","show_legend":1,"show_grid":1,"annotations":[{"fields":"geo.src, host","template":"Security Error from {{geo.src}} on {{host}}","index_pattern_ref_name":"ref_2_index_pattern","query_string":"tags:error AND tags:security","id":"bd7548a0-2223-11e8-832f-d5027f3c8a47","color":"rgba(211,49,21,1)","time_field":"timestamp","icon":"fa-asterisk","ignore_global_filters":1,"ignore_panel_filters":1}],"legend_position":"bottom","axis_scale":"normal","drop_last_bucket":0},"aggs":[]}',
uiStateJSON: '{}',
description: '',
version: 1,
@@ -183,7 +189,18 @@ export const getSavedObjects = (): SavedObject[] => [
searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}',
},
},
- references: [],
+ references: [
+ {
+ name: 'ref_1_index_pattern',
+ type: 'index_pattern',
+ id: '90943e30-9a47-11e8-b64d-95841ca0b247',
+ },
+ {
+ name: 'ref_2_index_pattern',
+ type: 'index_pattern',
+ id: '90943e30-9a47-11e8-b64d-95841ca0b247',
+ },
+ ],
},
{
id: '24a3e970-4257-11e8-b3aa-73fdaf54bfc9',
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
index 0277d5d70a3f7..78b859e1049bb 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
@@ -6,13 +6,14 @@
* Side Public License, v 1.
*/
-import { IndexPatternsService } from '../../../../../data/server';
-import { IndexPatternObject, FetchedIndexPattern } from '../../../../common/types';
import {
getIndexPatternObjectKey,
fetchIndexPattern,
} from '../../../../common/index_patterns_utils';
+import type { IndexPatternsService } from '../../../../../data/server';
+import type { IndexPatternObject, FetchedIndexPattern } from '../../../../common/types';
+
export const getCachedIndexPatternFetcher = (indexPatternsService: IndexPatternsService) => {
const cache = new Map();
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
index f27533f1f3ebb..a1fe120b75707 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/abstract_search_strategy.ts
@@ -81,7 +81,7 @@ export abstract class AbstractSearchStrategy {
fetchedIndexPattern.indexPattern
? fetchedIndexPattern.indexPattern.getNonScriptedFields()
: await indexPatternsService.getFieldsForWildcard({
- pattern: fetchedIndexPattern.indexPatternString,
+ pattern: fetchedIndexPattern.indexPatternString ?? '',
metaFields: [],
...options,
})
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
index 90915fca5401e..f95bf81b5c1d3 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/default_search_strategy.ts
@@ -8,8 +8,8 @@
import { AbstractSearchStrategy } from './abstract_search_strategy';
import { DefaultSearchCapabilities } from '../capabilities/default_search_capabilities';
-import { IndexPatternsService } from '../../../../../data/server';
+import type { IndexPatternsService } from '../../../../../data/server';
import type { FetchedIndexPattern } from '../../../../common/types';
import type {
VisTypeTimeseriesRequestHandlerContext,
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
index 4b2b9aebb21dc..c798f58b0b67b 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/strategies/rollup_search_strategy.test.ts
@@ -7,12 +7,13 @@
*/
import { RollupSearchStrategy } from './rollup_search_strategy';
-import {
+
+import type { IndexPatternsService } from '../../../../../data/common';
+import type { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
+import type {
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesVisDataRequest,
} from '../../../types';
-import { IndexPatternsService } from '../../../../../data/common';
-import { CachedIndexPatternFetcher } from '../lib/cached_index_pattern_fetcher';
jest.mock('./abstract_search_strategy', () => {
class AbstractSearchStrategyMock {
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
index d6c6a24f98709..13dc1207f51de 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_series_data.ts
@@ -29,12 +29,12 @@ export async function getSeriesData(
panel: PanelSchema,
services: VisTypeTimeseriesRequestServices
) {
- const fetchedIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
+ const panelIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
- fetchedIndex
+ panelIndex
);
if (!strategy) {
@@ -53,7 +53,7 @@ export async function getSeriesData(
try {
const bodiesPromises = getActiveSeries(panel).map((series) =>
- getSeriesRequestParams(req, panel, series, capabilities, services)
+ getSeriesRequestParams(req, panel, panelIndex, series, capabilities, services)
);
const searches = await Promise.all(bodiesPromises);
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
index 8f9916bab5e92..0cc1188086b7b 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/get_table_data.ts
@@ -32,12 +32,12 @@ export async function getTableData(
panel: PanelSchema,
services: VisTypeTimeseriesRequestServices
) {
- const fetchedIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
+ const panelIndex = await services.cachedIndexPatternFetcher(panel.index_pattern);
const strategy = await services.searchStrategyRegistry.getViableStrategy(
requestContext,
req,
- fetchedIndex
+ panelIndex
);
if (!strategy) {
@@ -58,8 +58,8 @@ export async function getTableData(
});
const calculatePivotLabel = async () => {
- if (panel.pivot_id && fetchedIndex.indexPattern?.title) {
- const fields = await extractFields(fetchedIndex.indexPattern.title);
+ if (panel.pivot_id && panelIndex.indexPattern?.title) {
+ const fields = await extractFields(panelIndex.indexPattern.title);
return extractFieldLabel(fields, panel.pivot_id);
}
@@ -77,7 +77,7 @@ export async function getTableData(
req,
panel,
services.esQueryConfig,
- fetchedIndex.indexPattern,
+ panelIndex.indexPattern,
capabilities,
services.uiSettings
);
@@ -85,7 +85,7 @@ export async function getTableData(
const [resp] = await searchStrategy.search(requestContext, req, [
{
body,
- index: fetchedIndex.indexPatternString,
+ index: panelIndex.indexPatternString,
},
]);
diff --git a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
index f9443324ac054..1f2735da8fb06 100644
--- a/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/vis_data/series/get_request_params.ts
@@ -6,14 +6,19 @@
* Side Public License, v 1.
*/
-import { PanelSchema, SeriesItemsSchema } from '../../../../common/types';
import { buildRequestBody } from './build_request_body';
-import { VisTypeTimeseriesRequestServices, VisTypeTimeseriesVisDataRequest } from '../../../types';
-import { DefaultSearchCapabilities } from '../../search_strategies';
+
+import type { FetchedIndexPattern, PanelSchema, SeriesItemsSchema } from '../../../../common/types';
+import type {
+ VisTypeTimeseriesRequestServices,
+ VisTypeTimeseriesVisDataRequest,
+} from '../../../types';
+import type { DefaultSearchCapabilities } from '../../search_strategies';
export async function getSeriesRequestParams(
req: VisTypeTimeseriesVisDataRequest,
panel: PanelSchema,
+ panelIndex: FetchedIndexPattern,
series: SeriesItemsSchema,
capabilities: DefaultSearchCapabilities,
{
@@ -23,22 +28,24 @@ export async function getSeriesRequestParams(
cachedIndexPatternFetcher,
}: VisTypeTimeseriesRequestServices
) {
- const { indexPattern, indexPatternString } = await cachedIndexPatternFetcher(
- (series.override_index_pattern && series.series_index_pattern) || panel.index_pattern
- );
+ let seriesIndex = panelIndex;
+
+ if (series.override_index_pattern) {
+ seriesIndex = await cachedIndexPatternFetcher(series.series_index_pattern ?? '');
+ }
const request = await buildRequestBody(
req,
panel,
series,
esQueryConfig,
- indexPattern,
+ seriesIndex.indexPattern,
capabilities,
uiSettings
);
return {
- index: indexPatternString,
+ index: seriesIndex.indexPatternString,
body: {
...request,
timeout: esShardTimeout > 0 ? `${esShardTimeout}ms` : undefined,
From 61392d2b975b6d8ecde15df3f47428e86ed81573 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Sat, 20 Mar 2021 17:44:15 +0300
Subject: [PATCH 30/39] indexPatternObject -> indexPatternValue
---
.../common/index_patterns_utils.test.ts | 4 +--
.../common/index_patterns_utils.ts | 32 +++++++++----------
.../vis_type_timeseries/common/types.ts | 2 +-
.../components/aggs/field_select.tsx | 8 ++---
.../index_pattern_select/combo_box_select.tsx | 4 +--
.../index_pattern_select.tsx | 6 ++--
.../lib/index_pattern_select/types.ts | 4 +--
.../components/panel_config/table.js | 4 +--
.../components/query_bar_wrapper.tsx | 4 +--
.../application/components/vis_editor.tsx | 17 ++++------
.../public/application/lib/fetch_fields.ts | 8 ++---
.../lib/cached_index_pattern_fetcher.ts | 15 ++++-----
12 files changed, 51 insertions(+), 57 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts b/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
index 929391662468e..515fadffb6b32 100644
--- a/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
+++ b/src/plugins/vis_type_timeseries/common/index_patterns_utils.test.ts
@@ -7,7 +7,7 @@
*/
import {
- extractIndexPatternObjects,
+ extractIndexPatternValues,
isStringTypeIndexPattern,
fetchIndexPattern,
} from './index_patterns_utils';
@@ -44,7 +44,7 @@ describe('extractIndexPatterns', () => {
});
test('should return index patterns', () => {
- expect(extractIndexPatternObjects(panel, '')).toEqual([
+ expect(extractIndexPatternValues(panel, '')).toEqual([
'*',
'example-1-*',
'example-2-*',
diff --git a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
index d07dc977cac1a..2884440e8f255 100644
--- a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
+++ b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
@@ -7,21 +7,21 @@
*/
import { uniq } from 'lodash';
-import { PanelSchema, IndexPatternObject, FetchedIndexPattern } from '../common/types';
+import { PanelSchema, IndexPatternValue, FetchedIndexPattern } from '../common/types';
import { IndexPatternsService } from '../../data/common';
export const isStringTypeIndexPattern = (
- indexPatternObject: IndexPatternObject
-): indexPatternObject is string => typeof indexPatternObject === 'string';
+ indexPatternValue: IndexPatternValue
+): indexPatternValue is string => typeof indexPatternValue === 'string';
-export const getIndexPatternObjectKey = (indexPatternObject: IndexPatternObject) =>
- isStringTypeIndexPattern(indexPatternObject) ? indexPatternObject : indexPatternObject?.id ?? '';
+export const getIndexPatternKey = (indexPatternValue: IndexPatternValue) =>
+ isStringTypeIndexPattern(indexPatternValue) ? indexPatternValue : indexPatternValue?.id ?? '';
-export const extractIndexPatternObjects = (
+export const extractIndexPatternValues = (
panel: PanelSchema,
defaultIndex?: PanelSchema['default_index_pattern']
) => {
- const patterns: IndexPatternObject[] = [];
+ const patterns: IndexPatternValue[] = [];
if (panel.index_pattern) {
patterns.push(panel.index_pattern);
@@ -47,29 +47,29 @@ export const extractIndexPatternObjects = (
patterns.push(defaultIndex);
}
- return uniq(patterns).sort();
+ return uniq(patterns).sort();
};
export const fetchIndexPattern = async (
- indexPatternObject: IndexPatternObject,
+ indexPatternValue: IndexPatternValue,
indexPatternsService: Pick
): Promise => {
let indexPattern: FetchedIndexPattern['indexPattern'];
let indexPatternString: string = '';
- if (!indexPatternObject) {
+ if (!indexPatternValue) {
indexPattern = await indexPatternsService.getDefault();
} else {
- if (isStringTypeIndexPattern(indexPatternObject)) {
- indexPattern = (await indexPatternsService.find(indexPatternObject)).find(
- (index) => index.title === indexPatternObject
+ if (isStringTypeIndexPattern(indexPatternValue)) {
+ indexPattern = (await indexPatternsService.find(indexPatternValue)).find(
+ (index) => index.title === indexPatternValue
);
if (!indexPattern) {
- indexPatternString = indexPatternObject;
+ indexPatternString = indexPatternValue;
}
- } else if (indexPatternObject.id) {
- indexPattern = await indexPatternsService.get(indexPatternObject.id);
+ } else if (indexPatternValue.id) {
+ indexPattern = await indexPatternsService.get(indexPatternValue.id);
}
}
diff --git a/src/plugins/vis_type_timeseries/common/types.ts b/src/plugins/vis_type_timeseries/common/types.ts
index 0aa1d0e22cdbe..9fe6a162836b4 100644
--- a/src/plugins/vis_type_timeseries/common/types.ts
+++ b/src/plugins/vis_type_timeseries/common/types.ts
@@ -26,7 +26,7 @@ export type MetricsItemsSchema = TypeOf;
export type PanelSchema = TypeOf;
export type VisPayload = TypeOf;
export type FieldObject = TypeOf;
-export type IndexPatternObject = TypeOf;
+export type IndexPatternValue = TypeOf;
export interface FetchedIndexPattern {
indexPattern: IndexPattern | undefined | null;
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/field_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/aggs/field_select.tsx
index dcdb706f1299b..fb5d420e4ab6e 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/field_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/field_select.tsx
@@ -10,8 +10,8 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiComboBox, EuiComboBoxProps, EuiComboBoxOptionOption } from '@elastic/eui';
import { METRIC_TYPES } from '../../../../common/metric_types';
-import { getIndexPatternObjectKey } from '../../../../common/index_patterns_utils';
-import type { SanitizedFieldType, IndexPatternObject } from '../../../../common/types';
+import { getIndexPatternKey } from '../../../../common/index_patterns_utils';
+import type { SanitizedFieldType, IndexPatternValue } from '../../../../common/types';
import type { TimeseriesUIRestrictions } from '../../../../common/ui_restrictions';
// @ts-ignore
@@ -20,7 +20,7 @@ import { isFieldEnabled } from '../../lib/check_ui_restrictions';
interface FieldSelectProps {
type: string;
fields: Record;
- indexPattern: IndexPatternObject;
+ indexPattern: IndexPatternValue;
value: string;
onChange: (options: Array>) => void;
disabled?: boolean;
@@ -62,7 +62,7 @@ export function FieldSelect({
const selectedOptions: Array> = [];
let newPlaceholder = placeholder;
- const fieldsSelector = getIndexPatternObjectKey(indexPattern);
+ const fieldsSelector = getIndexPatternKey(indexPattern);
const groupedOptions: EuiComboBoxProps['options'] = Object.values(
(fields[fieldsSelector] || []).reduce>>(
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
index 0e1713d6c05f7..7111a63244c7f 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/combo_box_select.tsx
@@ -14,7 +14,7 @@ import { getDataStart } from '../../../../services';
import { SwitchModePopover } from './switch_mode_popover';
import type { SelectIndexComponentProps } from './types';
-import type { IndexPatternObject } from '../../../../../common/types';
+import type { IndexPatternValue } from '../../../../../common/types';
import type { IndexPatternsService } from '../../../../../../data/public';
/** @internal **/
@@ -38,7 +38,7 @@ export const ComboBoxSelect = ({
const [availableIndexes, setAvailableIndexes] = useState([]);
const [selectedOptions, setSelectedOptions] = useState([]);
- const onComboBoxChange: EuiComboBoxProps['onChange'] = useCallback(
+ const onComboBoxChange: EuiComboBoxProps['onChange'] = useCallback(
([selected]) => {
onIndexChange(selected ? { id: selected.id } : '');
},
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/index_pattern_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/index_pattern_select.tsx
index 361bd3e3efcb1..a3854bdc41e76 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/index_pattern_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/index_pattern_select.tsx
@@ -22,12 +22,12 @@ import { FieldTextSelect } from './field_text_select';
import { ComboBoxSelect } from './combo_box_select';
import { MigrationPopover } from './migrate_popover';
-import type { IndexPatternObject, FetchedIndexPattern } from '../../../../../common/types';
+import type { IndexPatternValue, FetchedIndexPattern } from '../../../../../common/types';
const USE_KIBANA_INDEXES_KEY = 'use_kibana_indexes';
interface IndexPatternSelectProps {
- value: IndexPatternObject;
+ value: IndexPatternValue;
indexPatternName: string;
onChange: Function;
disabled?: boolean;
@@ -66,7 +66,7 @@ export const IndexPatternSelect = ({
const Component = useKibanaIndices ? ComboBoxSelect : FieldTextSelect;
const onIndexChange = useCallback(
- (index: IndexPatternObject) => {
+ (index: IndexPatternValue) => {
onChange({
[indexPatternName]: index,
});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
index 0e7eed0d16654..93b15402e3c24 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/types.ts
@@ -6,12 +6,12 @@
* Side Public License, v 1.
*/
import type { Assign } from '@kbn/utility-types';
-import type { FetchedIndexPattern, IndexPatternObject } from '../../../../../common/types';
+import type { FetchedIndexPattern, IndexPatternValue } from '../../../../../common/types';
/** @internal **/
export interface SelectIndexComponentProps {
fetchedIndex: FetchedIndexPattern;
- onIndexChange: (value: IndexPatternObject) => void;
+ onIndexChange: (value: IndexPatternValue) => void;
onModeChange: (useKibanaIndexes: boolean, index?: FetchedIndexPattern) => void;
'data-test-subj': string;
placeholder?: string;
diff --git a/src/plugins/vis_type_timeseries/public/application/components/panel_config/table.js b/src/plugins/vis_type_timeseries/public/application/components/panel_config/table.js
index 35830e637b9ee..93971d5a67a6a 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/panel_config/table.js
+++ b/src/plugins/vis_type_timeseries/public/application/components/panel_config/table.js
@@ -36,7 +36,7 @@ import { QueryBarWrapper } from '../query_bar_wrapper';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
import { VisDataContext } from '../../contexts/vis_data_context';
import { BUCKET_TYPES } from '../../../../common/metric_types';
-import { getIndexPatternObjectKey } from '../../../../common/index_patterns_utils';
+import { getIndexPatternKey } from '../../../../common/index_patterns_utils';
export class TablePanelConfig extends Component {
static contextType = VisDataContext;
constructor(props) {
@@ -60,7 +60,7 @@ export class TablePanelConfig extends Component {
handlePivotChange = (selectedOption) => {
const { fields, model } = this.props;
const pivotId = get(selectedOption, '[0].value', null);
- const field = fields[getIndexPatternObjectKey(model.index_pattern)].find(
+ const field = fields[getIndexPatternKey(model.index_pattern)].find(
(field) => field.name === pivotId
);
const pivotType = get(field, 'type', model.pivot_type);
diff --git a/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx b/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
index ddee08b6a12b7..896caa64820a2 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/query_bar_wrapper.tsx
@@ -9,14 +9,14 @@
import React, { useContext, useEffect, useState } from 'react';
import { CoreStartContext } from '../contexts/query_input_bar_context';
-import { IndexPatternObject } from '../../../common/types';
+import { IndexPatternValue } from '../../../common/types';
import { QueryStringInput, QueryStringInputProps } from '../../../../../plugins/data/public';
import { getDataStart } from '../../services';
import { fetchIndexPattern, isStringTypeIndexPattern } from '../../../common/index_patterns_utils';
type QueryBarWrapperProps = Pick & {
- indexPatterns: IndexPatternObject[];
+ indexPatterns: IndexPatternValue[];
};
export function QueryBarWrapper({ query, onChange, indexPatterns }: QueryBarWrapperProps) {
diff --git a/src/plugins/vis_type_timeseries/public/application/components/vis_editor.tsx b/src/plugins/vis_type_timeseries/public/application/components/vis_editor.tsx
index 83e0269843c76..aca91f8c830a8 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/vis_editor.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/vis_editor.tsx
@@ -15,21 +15,18 @@ import { EventEmitter } from 'events';
import { IUiSettingsClient } from 'kibana/public';
import { TimeRange } from 'src/plugins/data/public';
import {
- PersistedState,
Vis,
+ PersistedState,
VisualizeEmbeddableContract,
} from 'src/plugins/visualizations/public';
-import {
- IndexPatternObject,
- TimeseriesVisData,
-} from 'src/plugins/vis_type_timeseries/common/types';
+import { IndexPatternValue, TimeseriesVisData } from 'src/plugins/vis_type_timeseries/common/types';
import { KibanaContextProvider } from '../../../../../plugins/kibana_react/public';
import { Storage } from '../../../../../plugins/kibana_utils/public';
// @ts-expect-error
import { VisEditorVisualization } from './vis_editor_visualization';
import { PanelConfig } from './panel_config';
-import { extractIndexPatternObjects } from '../../../common/index_patterns_utils';
+import { extractIndexPatternValues } from '../../../common/index_patterns_utils';
import { VisPicker } from './vis_picker';
import { fetchFields, VisFields } from '../lib/fetch_fields';
import { getDataStart, getCoreStart } from '../../services';
@@ -50,7 +47,7 @@ export interface TimeseriesEditorProps {
interface TimeseriesEditorState {
autoApply: boolean;
dirty: boolean;
- extractedIndexPatterns: IndexPatternObject[];
+ extractedIndexPatterns: IndexPatternValue[];
model: TimeseriesVisParams;
visFields?: VisFields;
}
@@ -86,7 +83,7 @@ export class VisEditor extends Component {
+ abortableFetchFields = (extractedIndexPatterns: IndexPatternValue[]) => {
this.abortControllerFetchFields?.abort();
this.abortControllerFetchFields = new AbortController();
@@ -205,7 +202,7 @@ export class VisEditor extends Component {
const defaultIndexTitle = index?.title ?? '';
- const indexPatterns = extractIndexPatternObjects(this.props.vis.params, defaultIndexTitle);
+ const indexPatterns = extractIndexPatternValues(this.props.vis.params, defaultIndexTitle);
const visFields = await fetchFields(indexPatterns);
this.setState((state) => ({
diff --git a/src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.ts b/src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.ts
index 1633b846580e7..df6c7401f0881 100644
--- a/src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.ts
+++ b/src/plugins/vis_type_timeseries/public/application/lib/fetch_fields.ts
@@ -9,13 +9,13 @@
import { i18n } from '@kbn/i18n';
import { getCoreStart, getDataStart } from '../../services';
import { ROUTES } from '../../../common/constants';
-import { SanitizedFieldType, IndexPatternObject } from '../../../common/types';
-import { getIndexPatternObjectKey } from '../../../common/index_patterns_utils';
+import { SanitizedFieldType, IndexPatternValue } from '../../../common/types';
+import { getIndexPatternKey } from '../../../common/index_patterns_utils';
export type VisFields = Record;
export async function fetchFields(
- indexes: IndexPatternObject[] = [],
+ indexes: IndexPatternValue[] = [],
signal?: AbortSignal
): Promise {
const patterns = Array.isArray(indexes) ? indexes : [indexes];
@@ -42,7 +42,7 @@ export async function fetchFields(
const fields: VisFields = patterns.reduce(
(cumulatedFields, currentPattern, index) => ({
...cumulatedFields,
- [getIndexPatternObjectKey(currentPattern)]: indexFields[index],
+ [getIndexPatternKey(currentPattern)]: indexFields[index],
}),
{}
);
diff --git a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
index 78b859e1049bb..68cbd93cdc614 100644
--- a/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
+++ b/src/plugins/vis_type_timeseries/server/lib/search_strategies/lib/cached_index_pattern_fetcher.ts
@@ -6,27 +6,24 @@
* Side Public License, v 1.
*/
-import {
- getIndexPatternObjectKey,
- fetchIndexPattern,
-} from '../../../../common/index_patterns_utils';
+import { getIndexPatternKey, fetchIndexPattern } from '../../../../common/index_patterns_utils';
import type { IndexPatternsService } from '../../../../../data/server';
-import type { IndexPatternObject, FetchedIndexPattern } from '../../../../common/types';
+import type { IndexPatternValue, FetchedIndexPattern } from '../../../../common/types';
export const getCachedIndexPatternFetcher = (indexPatternsService: IndexPatternsService) => {
const cache = new Map();
- return async (indexPatternObject: IndexPatternObject): Promise => {
- const key = getIndexPatternObjectKey(indexPatternObject);
+ return async (indexPatternValue: IndexPatternValue): Promise => {
+ const key = getIndexPatternKey(indexPatternValue);
if (cache.has(key)) {
return cache.get(key);
}
- const fetchedIndex = fetchIndexPattern(indexPatternObject, indexPatternsService);
+ const fetchedIndex = fetchIndexPattern(indexPatternValue, indexPatternsService);
- cache.set(indexPatternObject, fetchedIndex);
+ cache.set(indexPatternValue, fetchedIndex);
return fetchedIndex;
};
From 865477aadf5ec7d1cf9da98930f36ae13e06453d Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Tue, 23 Mar 2021 15:54:40 +0300
Subject: [PATCH 31/39] fix comments
---
.../index_pattern_select/migrate_popover.tsx | 32 ++++++++-----------
test/functional/apps/visualize/_tsvb_chart.ts | 4 +--
2 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/migrate_popover.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/migrate_popover.tsx
index 8dac89a113a7b..eb7468154883e 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/migrate_popover.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/migrate_popover.tsx
@@ -33,15 +33,13 @@ const switchModeLabel = i18n.translate(
const getReadyToSwitchCallOut = (value: string, onModeChange: () => void) => (
<>
-
- {value},
- }}
- />
-
+ {value},
+ }}
+ />
@@ -56,15 +54,13 @@ const getReadyToSwitchCallOut = (value: string, onModeChange: () => void) => (
const getNoMatchedIndicesCallOut = (value: string, onCreateIndexClick: () => void) => (
<>
-
- {value},
- }}
- />
-
+ {value},
+ }}
+ />
diff --git a/test/functional/apps/visualize/_tsvb_chart.ts b/test/functional/apps/visualize/_tsvb_chart.ts
index 0908b7b8ff6bb..80ab33170c396 100644
--- a/test/functional/apps/visualize/_tsvb_chart.ts
+++ b/test/functional/apps/visualize/_tsvb_chart.ts
@@ -126,7 +126,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await esArchiver.unload('index_pattern_without_timefield');
});
- const switchIndexTest = async (useKibanaIndicies: boolean) => {
+ const switchIndexTest = async (useKibanaIndexes: boolean) => {
await PageObjects.visualBuilder.clickPanelOptions('metric');
await PageObjects.visualBuilder.setIndexPatternValue('', false);
@@ -135,7 +135,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// Sometimes popovers take some time to appear in Firefox (#71979)
await retry.tryForTime(20000, async () => {
- await PageObjects.visualBuilder.setIndexPatternValue('with-timefield', useKibanaIndicies);
+ await PageObjects.visualBuilder.setIndexPatternValue('with-timefield', useKibanaIndexes);
await PageObjects.visualBuilder.waitForIndexPatternTimeFieldOptionsLoaded();
await PageObjects.visualBuilder.selectIndexPatternTimeField('timestamp');
});
From 7f93d810724040e02b406c88fd59f88321be0032 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Tue, 23 Mar 2021 16:06:59 +0300
Subject: [PATCH 32/39] I have a dashboard with two TSVB viz. One with the
default (haven't applied it to the combobox) and one with the logs. The
filter contains fields only from the logs index pattern
---
.../vis_type_timeseries/common/index_patterns_utils.ts | 2 +-
src/plugins/vis_type_timeseries/public/metrics_type.ts | 9 ++-------
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
index 2884440e8f255..398d1c30ed5a7 100644
--- a/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
+++ b/src/plugins/vis_type_timeseries/common/index_patterns_utils.ts
@@ -51,7 +51,7 @@ export const extractIndexPatternValues = (
};
export const fetchIndexPattern = async (
- indexPatternValue: IndexPatternValue,
+ indexPatternValue: IndexPatternValue | undefined,
indexPatternsService: Pick
): Promise => {
let indexPattern: FetchedIndexPattern['indexPattern'];
diff --git a/src/plugins/vis_type_timeseries/public/metrics_type.ts b/src/plugins/vis_type_timeseries/public/metrics_type.ts
index 3c971dc2a5b1e..a89217409c1ff 100644
--- a/src/plugins/vis_type_timeseries/public/metrics_type.ts
+++ b/src/plugins/vis_type_timeseries/public/metrics_type.ts
@@ -79,13 +79,8 @@ export const metricsVisDefinition = {
inspectorAdapters: {},
getUsedIndexPattern: async (params: VisParams) => {
const { indexPatterns } = getDataStart();
+ const { indexPattern } = await fetchIndexPattern(params.index_pattern, indexPatterns);
- if (params.index_pattern) {
- const { indexPattern } = await fetchIndexPattern(params.index_pattern, indexPatterns);
- if (indexPattern) {
- return [indexPattern];
- }
- }
- return [];
+ return indexPattern ? [indexPattern] : [];
},
};
From 800c0e922f895fe6ff1f331cde890bec895c37f2 Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Tue, 23 Mar 2021 16:31:18 +0300
Subject: [PATCH 33/39] When I am on the string mode and try to write my index,
sometimes some of the chars are not added or they are deleted while typing,
something with the denounce maybe?
---
.../lib/index_pattern_select/field_text_select.tsx | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
index fff5e86395273..86d1758932301 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/index_pattern_select/field_text_select.tsx
@@ -30,8 +30,10 @@ export const FieldTextSelect = ({
}, []);
useEffect(() => {
- setInputValue(indexPatternString ?? '');
- }, [indexPatternString]);
+ if (inputValue === undefined) {
+ setInputValue(indexPatternString ?? '');
+ }
+ }, [indexPatternString, inputValue]);
useDebounce(
() => {
From df49b430044c9dacf7aeb55471e17bc640824dec Mon Sep 17 00:00:00 2001
From: Alexey Antonov
Date: Tue, 23 Mar 2021 17:31:02 +0300
Subject: [PATCH 34/39] fix merge conflicts
---
.../vis_type_timeseries/common/vis_schema.ts | 2 +-
.../components/panel_config/gauge.tsx | 11 ++---
.../components/panel_config/markdown.tsx | 15 +++---
.../components/panel_config/metric.tsx | 16 +++----
.../components/panel_config/table.tsx | 18 ++++---
.../components/panel_config/timeseries.tsx | 17 ++++---
.../components/panel_config/top_n.tsx | 13 +++--
.../components/query_bar_wrapper.tsx | 2 +-
.../components/vis_types/table/config.js | 47 +++++++------------
9 files changed, 60 insertions(+), 81 deletions(-)
diff --git a/src/plugins/vis_type_timeseries/common/vis_schema.ts b/src/plugins/vis_type_timeseries/common/vis_schema.ts
index 94ca9ef9b1a3e..297b021fa9e77 100644
--- a/src/plugins/vis_type_timeseries/common/vis_schema.ts
+++ b/src/plugins/vis_type_timeseries/common/vis_schema.ts
@@ -28,7 +28,7 @@ const numberOptional = schema.maybe(schema.number());
const queryObject = schema.object({
language: schema.string(),
- query: schema.string(),
+ query: schema.oneOf([schema.string(), schema.any()]),
});
const stringOrNumberOptionalNullable = schema.nullable(
schema.oneOf([stringOptionalNullable, numberOptional])
diff --git a/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.tsx b/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.tsx
index 2038905a9ff4a..8a5077fca664c 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/panel_config/gauge.tsx
@@ -29,12 +29,11 @@ import type { Writable } from '@kbn/utility-types';
// @ts-ignore
import { SeriesEditor } from '../series_editor';
-// @ts-ignore should be typed after https://github.com/elastic/kibana/pull/92812 to reduce conflicts
+// @ts-expect-error not typed yet
import { IndexPattern } from '../index_pattern';
import { createSelectHandler } from '../lib/create_select_handler';
import { ColorRules } from '../color_rules';
import { ColorPicker } from '../color_picker';
-// @ts-ignore this is typed in https://github.com/elastic/kibana/pull/92812, remove ignore after merging
import { QueryBarWrapper } from '../query_bar_wrapper';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
import { YesNo } from '../yes_no';
@@ -150,10 +149,10 @@ export class GaugePanelConfig extends Component<
language: model.filter?.language || getDefaultQueryLanguage(),
query: model.filter?.query || '',
}}
- onChange={(filter: PanelConfigProps['model']['filter']) =>
- this.props.onChange({ filter })
- }
- indexPatterns={[model.index_pattern || model.default_index_pattern]}
+ onChange={(filter) => {
+ this.props.onChange({ filter });
+ }}
+ indexPatterns={[model.index_pattern || model.default_index_pattern || '']}
/>