[Unified observability] Migrate deprecated IndexPattern types (#124962)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Gómez 2022-03-09 12:24:08 +01:00 committed by GitHub
parent 6bcce44082
commit 299b21b889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 303 additions and 304 deletions

View file

@ -7,14 +7,14 @@
import React from 'react';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { mockAppIndexPattern, mockIndexPattern, mockUxSeries, render } from '../rtl_helpers';
import { mockAppDataView, mockDataView, mockUxSeries, render } from '../rtl_helpers';
import { FilterLabel } from './filter_label';
import * as useSeriesHook from '../hooks/use_series_filters';
import { buildFilterLabel } from '../../filter_value_label/filter_value_label';
// FLAKY: https://github.com/elastic/kibana/issues/115324
describe.skip('FilterLabel', function () {
mockAppIndexPattern();
mockAppDataView();
const invertFilter = jest.fn();
jest.spyOn(useSeriesHook, 'useSeriesFilters').mockReturnValue({
@ -30,7 +30,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={jest.fn()}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
@ -55,7 +55,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={removeFilter}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
@ -79,7 +79,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={removeFilter}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
@ -106,7 +106,7 @@ describe.skip('FilterLabel', function () {
negate={true}
seriesId={0}
removeFilter={jest.fn()}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
@ -126,7 +126,7 @@ describe.skip('FilterLabel', function () {
buildFilterLabel({
field: 'user_agent.name',
label: 'Browser family',
indexPattern: mockIndexPattern,
dataView: mockDataView,
value: 'Firefox',
negate: false,
})

View file

@ -6,7 +6,7 @@
*/
import React from 'react';
import { IndexPattern } from '../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { useSeriesFilters } from '../hooks/use_series_filters';
import { FilterValueLabel } from '../../filter_value_label/filter_value_label';
import { SeriesUrl } from '../types';
@ -19,7 +19,7 @@ interface Props {
series: SeriesUrl;
negate: boolean;
definitionFilter?: boolean;
indexPattern: IndexPattern;
dataView: DataView;
removeFilter: (field: string, value: string | string[], notVal: boolean) => void;
}
@ -30,15 +30,15 @@ export function FilterLabel({
field,
value,
negate,
indexPattern,
dataView,
removeFilter,
definitionFilter,
}: Props) {
const { invertFilter } = useSeriesFilters({ seriesId, series });
return indexPattern ? (
return dataView ? (
<FilterValueLabel
indexPattern={indexPattern}
dataView={dataView}
removeFilter={removeFilter}
invertFilter={(val) => {
if (!definitionFilter) invertFilter(val);

View file

@ -6,12 +6,12 @@
*/
import { AppDataType, ReportViewType, SeriesConfig } from '../types';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { ReportConfigMap } from '../contexts/exploratory_view_config';
interface Props {
reportType: ReportViewType;
indexPattern: IndexPattern;
dataView: DataView;
dataType: AppDataType;
reportConfigMap: ReportConfigMap;
}
@ -19,13 +19,13 @@ interface Props {
export const getDefaultConfigs = ({
reportType,
dataType,
indexPattern,
dataView,
reportConfigMap,
}: Props): SeriesConfig => {
let configResult: SeriesConfig | undefined;
reportConfigMap[dataType]?.some((fn) => {
const config = fn({ indexPattern });
const config = fn({ dataView });
if (config.reportType === reportType) {
configResult = config;
}

View file

@ -20,7 +20,7 @@ import {
SYSTEM_MEMORY_USAGE,
} from '../constants/labels';
export function getMetricsKPIConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMetricsKPIConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.KPI,
defaultSeriesType: 'area',

View file

@ -6,7 +6,7 @@
*/
import { LayerConfig, LensAttributes } from './lens_attributes';
import { mockAppIndexPattern, mockIndexPattern } from '../rtl_helpers';
import { mockAppDataView, mockDataView } from '../rtl_helpers';
import { getDefaultConfigs } from './default_configs';
import { sampleAttribute } from './test_data/sample_attribute';
@ -21,16 +21,16 @@ import { RECORDS_FIELD, REPORT_METRIC_FIELD, PERCENTILE_RANKS, ReportTypes } fro
import { obsvReportConfigMap } from '../obsv_exploratory_view';
describe('Lens Attribute', () => {
mockAppIndexPattern();
mockAppDataView();
const reportViewConfig = getDefaultConfigs({
reportType: 'data-distribution',
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});
reportViewConfig.baseFilters?.push(...buildExistsFilter('transaction.type', mockIndexPattern));
reportViewConfig.baseFilters?.push(...buildExistsFilter('transaction.type', mockDataView));
let lnsAttr: LensAttributes;
@ -38,7 +38,7 @@ describe('Lens Attribute', () => {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: {},
time: { from: 'now-15m', to: 'now' },
color: 'green',
@ -58,7 +58,7 @@ describe('Lens Attribute', () => {
const seriesConfigKpi = getDefaultConfigs({
reportType: ReportTypes.KPI,
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});
@ -67,7 +67,7 @@ describe('Lens Attribute', () => {
seriesConfig: seriesConfigKpi,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'service.name': ['elastic-co'] },
time: { from: 'now-15m', to: 'now' },
color: 'green',
@ -83,7 +83,7 @@ describe('Lens Attribute', () => {
const seriesConfigKpi = getDefaultConfigs({
reportType: ReportTypes.KPI,
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});
@ -95,7 +95,7 @@ describe('Lens Attribute', () => {
from: 'now-1h',
to: 'now',
},
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
name: 'ux-series-1',
breakdown: 'percentile',
reportDefinitions: {},
@ -200,7 +200,7 @@ describe('Lens Attribute', () => {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
time: { from: 'now-15m', to: 'now' },
color: 'green',
@ -493,7 +493,7 @@ describe('Lens Attribute', () => {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
breakdown: USER_AGENT_NAME,
time: { from: 'now-15m', to: 'now' },
@ -507,7 +507,7 @@ describe('Lens Attribute', () => {
lnsAttr.getBreakdownColumn({
sourceField: USER_AGENT_NAME,
layerId: 'layer0',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
labels: layerConfig.seriesConfig.labels,
});
@ -676,14 +676,14 @@ describe('Lens Attribute', () => {
describe('Layer Filters', function () {
it('should return expected filters', function () {
reportViewConfig.baseFilters?.push(
...buildPhrasesFilter('service.name', ['elastic', 'kibana'], mockIndexPattern)
...buildPhrasesFilter('service.name', ['elastic', 'kibana'], mockDataView)
);
const layerConfig1: LayerConfig = {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
time: { from: 'now-15m', to: 'now' },
color: 'green',

View file

@ -30,7 +30,7 @@ import {
CardinalityIndexPatternColumn,
} from '../../../../../../lens/public';
import { urlFiltersToKueryString } from '../utils/stringify_kueries';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import {
FILTER_RECORDS,
USE_BREAK_DOWN_COLUMN,
@ -91,7 +91,7 @@ export interface LayerConfig {
operationType?: OperationType;
reportDefinitions: URLReportDefinition;
time: { to: string; from: string };
indexPattern: IndexPattern;
indexPattern: DataView; // TODO: Figure out if this can be renamed or if it's a Lens requirement
selectedMetricField: string;
color: string;
name: string;
@ -150,7 +150,7 @@ export class LensAttributes {
sourceField: string;
layerId: string;
labels: Record<string, string>;
indexPattern: IndexPattern;
indexPattern: DataView;
}): TermsIndexPatternColumn {
const fieldMeta = indexPattern.getFieldByName(sourceField);

View file

@ -18,7 +18,7 @@ import { SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { MOBILE_APP, NUMBER_OF_DEVICES } from '../constants/labels';
import { MobileFields } from './mobile_fields';
export function getMobileDeviceDistributionConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileDeviceDistributionConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DEVICE_DISTRIBUTION,
defaultSeriesType: 'bar',
@ -36,8 +36,8 @@ export function getMobileDeviceDistributionConfig({ indexPattern }: ConfigProps)
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhraseFilter('agent.name', 'iOS/swift', indexPattern),
...buildPhraseFilter('processor.event', 'transaction', indexPattern),
...buildPhraseFilter('agent.name', 'iOS/swift', dataView),
...buildPhraseFilter('processor.event', 'transaction', dataView),
],
labels: {
...FieldLabels,

View file

@ -26,7 +26,7 @@ import {
import { CPU_USAGE, SYSTEM_MEMORY_USAGE, MOBILE_APP, RESPONSE_LATENCY } from '../constants/labels';
import { MobileFields } from './mobile_fields';
export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileKPIDistributionConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DISTRIBUTION,
defaultSeriesType: 'bar',
@ -43,7 +43,7 @@ export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): S
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], dataView),
],
labels: {
...FieldLabels,

View file

@ -32,7 +32,7 @@ import {
} from '../constants/labels';
import { MobileFields } from './mobile_fields';
export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileKPIConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.KPI,
defaultSeriesType: 'line',
@ -50,7 +50,7 @@ export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], dataView),
],
labels: {
...FieldLabels,

View file

@ -5,16 +5,16 @@
* 2.0.
*/
import { mockAppIndexPattern, mockIndexPattern } from '../../rtl_helpers';
import { mockAppDataView, mockDataView } from '../../rtl_helpers';
import { LensAttributes } from '../lens_attributes';
import { METRIC_SYSTEM_MEMORY_USAGE, SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
import { testMobileKPIAttr } from '../test_data/mobile_test_attribute';
import { getLayerConfigs } from '../../hooks/use_lens_attributes';
import { IndexPatternState } from '../../hooks/use_app_index_pattern';
import { DataViewState } from '../../hooks/use_app_data_view';
describe('Mobile kpi config test', function () {
mockAppIndexPattern();
mockAppDataView();
let lnsAttr: LensAttributes;
@ -31,7 +31,7 @@ describe('Mobile kpi config test', function () {
],
'kpi-over-time',
{} as any,
{ mobile: mockIndexPattern } as IndexPatternState,
{ mobile: mockDataView } as DataViewState,
obsvReportConfigMap
);

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { mockAppIndexPattern, mockIndexPattern } from '../../rtl_helpers';
import { mockAppDataView, mockDataView } from '../../rtl_helpers';
import { getDefaultConfigs } from '../default_configs';
import { LayerConfig, LensAttributes } from '../lens_attributes';
import { sampleAttributeCoreWebVital } from '../test_data/sample_attribute_cwv';
@ -13,12 +13,12 @@ import { LCP_FIELD, SERVICE_NAME, USER_AGENT_OS } from '../constants/elasticsear
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
describe('Core web vital config test', function () {
mockAppIndexPattern();
mockAppDataView();
const seriesConfig = getDefaultConfigs({
reportType: 'core-web-vitals',
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});
@ -29,7 +29,7 @@ describe('Core web vital config test', function () {
color: 'green',
name: 'test-series',
breakdown: USER_AGENT_OS,
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
time: { from: 'now-15m', to: 'now' },
reportDefinitions: { [SERVICE_NAME]: ['elastic-co'] },
selectedMetricField: LCP_FIELD,

View file

@ -35,7 +35,7 @@ import {
} from '../constants/elasticsearch_fieldnames';
import { CLS_LABEL, FID_LABEL, LCP_LABEL } from '../constants/labels';
export function getCoreWebVitalsConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getCoreWebVitalsConfig({ dataView }: ConfigProps): SeriesConfig {
const statusPallete = euiPaletteForStatus(3);
return {
@ -87,8 +87,8 @@ export function getCoreWebVitalsConfig({ indexPattern }: ConfigProps): SeriesCon
URL_FULL,
],
baseFilters: [
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', indexPattern),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', indexPattern),
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', dataView),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', dataView),
],
labels: { ...FieldLabels, [SERVICE_NAME]: 'Web Application' },
definitionFields: [SERVICE_NAME, SERVICE_ENVIRONMENT],

View file

@ -45,7 +45,7 @@ import {
WEB_APPLICATION_LABEL,
} from '../constants/labels';
export function getRumDistributionConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getRumDistributionConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DISTRIBUTION,
defaultSeriesType: 'line',
@ -90,8 +90,8 @@ export function getRumDistributionConfig({ indexPattern }: ConfigProps): SeriesC
{ label: CLS_LABEL, id: CLS_FIELD, field: CLS_FIELD },
],
baseFilters: [
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', indexPattern),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', indexPattern),
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', dataView),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', dataView),
],
labels: {
...FieldLabels,

View file

@ -48,7 +48,7 @@ import {
WEB_APPLICATION_LABEL,
} from '../constants/labels';
export function getKPITrendsLensConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getKPITrendsLensConfig({ dataView }: ConfigProps): SeriesConfig {
return {
defaultSeriesType: 'bar_stacked',
seriesTypes: [],
@ -83,8 +83,8 @@ export function getKPITrendsLensConfig({ indexPattern }: ConfigProps): SeriesCon
LABEL_FIELDS_BREAKDOWN,
],
baseFilters: [
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', indexPattern),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', indexPattern),
...buildPhraseFilter(TRANSACTION_TYPE, 'page-load', dataView),
...buildPhraseFilter(PROCESSOR_EVENT, 'transaction', dataView),
],
labels: { ...FieldLabels, [SERVICE_NAME]: WEB_APPLICATION_LABEL },
definitionFields: [SERVICE_NAME, SERVICE_ENVIRONMENT],

View file

@ -31,10 +31,7 @@ import {
} from '../constants/field_names/synthetics';
import { buildExistsFilter } from '../utils';
export function getSyntheticsDistributionConfig({
series,
indexPattern,
}: ConfigProps): SeriesConfig {
export function getSyntheticsDistributionConfig({ series, dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DISTRIBUTION,
defaultSeriesType: series?.seriesType || 'line',
@ -61,7 +58,7 @@ export function getSyntheticsDistributionConfig({
baseFilters: [],
definitionFields: [
{ field: 'monitor.name', nested: 'synthetics.step.name.keyword', singleSelection: true },
{ field: 'url.full', filters: buildExistsFilter('summary.up', indexPattern) },
{ field: 'url.full', filters: buildExistsFilter('summary.up', dataView) },
],
metricOptions: [
{

View file

@ -51,7 +51,7 @@ export const isStepLevelMetric = (metric?: string) => {
SYNTHETICS_DOCUMENT_ONLOAD,
].includes(metric);
};
export function getSyntheticsKPIConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getSyntheticsKPIConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.KPI,
defaultSeriesType: 'bar_stacked',
@ -78,7 +78,7 @@ export function getSyntheticsKPIConfig({ indexPattern }: ConfigProps): SeriesCon
palette: { type: 'palette', name: 'status' },
definitionFields: [
{ field: 'monitor.name', nested: SYNTHETICS_STEP_NAME, singleSelection: true },
{ field: 'url.full', filters: buildExistsFilter('summary.up', indexPattern) },
{ field: 'url.full', filters: buildExistsFilter('summary.up', dataView) },
],
metricOptions: [
{

View file

@ -15,7 +15,7 @@ import {
} from '@kbn/es-query';
import type { ReportViewType, SeriesUrl, UrlFilter } from '../types';
import type { AllSeries, AllShortSeries } from '../hooks/use_series_storage';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { URL_KEYS } from './constants/url_constants';
import { PersistableFilter } from '../../../../../../lens/common';
@ -78,17 +78,17 @@ export function createExploratoryViewUrl(
);
}
export function buildPhraseFilter(field: string, value: string, indexPattern: IndexPattern) {
const fieldMeta = indexPattern?.fields.find((fieldT) => fieldT.name === field);
export function buildPhraseFilter(field: string, value: string, dataView: DataView) {
const fieldMeta = dataView?.fields.find((fieldT) => fieldT.name === field);
if (fieldMeta) {
return [esBuildPhraseFilter(fieldMeta, value, indexPattern)];
return [esBuildPhraseFilter(fieldMeta, value, dataView)];
}
return [];
}
export function getQueryFilter(field: string, value: string[], indexPattern: IndexPattern) {
const fieldMeta = indexPattern?.fields.find((fieldT) => fieldT.name === field);
if (fieldMeta && indexPattern.id) {
export function getQueryFilter(field: string, value: string[], dataView: DataView) {
const fieldMeta = dataView?.fields.find((fieldT) => fieldT.name === field);
if (fieldMeta && dataView.id) {
return value.map((val) =>
buildQueryFilter(
{
@ -97,7 +97,7 @@ export function getQueryFilter(field: string, value: string[], indexPattern: Ind
query: `*${val}*`,
},
},
indexPattern.id!,
dataView.id!,
''
)
);
@ -106,21 +106,21 @@ export function getQueryFilter(field: string, value: string[], indexPattern: Ind
return [];
}
export function buildPhrasesFilter(field: string, value: string[], indexPattern: IndexPattern) {
const fieldMeta = indexPattern?.fields.find((fieldT) => fieldT.name === field);
export function buildPhrasesFilter(field: string, value: string[], dataView: DataView) {
const fieldMeta = dataView?.fields.find((fieldT) => fieldT.name === field);
if (fieldMeta) {
if (value.length === 1) {
return [esBuildPhraseFilter(fieldMeta, value[0], indexPattern)];
return [esBuildPhraseFilter(fieldMeta, value[0], dataView)];
}
return [esBuildPhrasesFilter(fieldMeta, value, indexPattern)];
return [esBuildPhrasesFilter(fieldMeta, value, dataView)];
}
return [];
}
export function buildExistsFilter(field: string, indexPattern: IndexPattern) {
const fieldMeta = indexPattern?.fields.find((fieldT) => fieldT.name === field);
export function buildExistsFilter(field: string, dataView: DataView) {
const fieldMeta = dataView?.fields.find((fieldT) => fieldT.name === field);
if (fieldMeta) {
return [esBuildExistsFilter(fieldMeta, indexPattern)];
return [esBuildExistsFilter(fieldMeta, dataView)];
}
return [];
}
@ -130,34 +130,34 @@ type FiltersType = Array<PersistableFilter | ExistsFilter | PhraseFilter>;
export function urlFilterToPersistedFilter({
urlFilters,
initFilters,
indexPattern,
dataView,
}: {
urlFilters: UrlFilter[];
initFilters?: FiltersType;
indexPattern: IndexPattern;
dataView: DataView;
}) {
const parsedFilters: FiltersType = initFilters ? [...initFilters] : [];
urlFilters.forEach(
({ field, values = [], notValues = [], wildcards = [], notWildcards = ([] = []) }) => {
if (values.length > 0) {
const filter = buildPhrasesFilter(field, values, indexPattern);
const filter = buildPhrasesFilter(field, values, dataView);
parsedFilters.push(...filter);
}
if (notValues.length > 0) {
const filter = buildPhrasesFilter(field, notValues, indexPattern)[0];
const filter = buildPhrasesFilter(field, notValues, dataView)[0];
filter.meta.negate = true;
parsedFilters.push(filter);
}
if (wildcards.length > 0) {
const filter = getQueryFilter(field, wildcards, indexPattern);
const filter = getQueryFilter(field, wildcards, dataView);
parsedFilters.push(...filter);
}
if (notWildcards.length > 0) {
const filter = getQueryFilter(field, notWildcards, indexPattern)[0];
const filter = getQueryFilter(field, notWildcards, dataView)[0];
filter.meta.negate = true;
parsedFilters.push(filter);
}

View file

@ -18,21 +18,21 @@ interface ExploratoryViewContextValue {
reportType: ReportViewType | typeof SELECT_REPORT_TYPE;
label: string;
}>;
indexPatterns: Record<string, string>;
dataViews: Record<string, string>;
reportConfigMap: ReportConfigMap;
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
theme$: AppMountParameters['theme$'];
}
export const ExploratoryViewContext = createContext<ExploratoryViewContextValue>({
indexPatterns: {},
dataViews: {},
} as ExploratoryViewContextValue);
export function ExploratoryViewContextProvider({
children,
reportTypes,
dataTypes,
indexPatterns,
dataViews,
reportConfigMap,
setHeaderActionMenu,
theme$,
@ -40,7 +40,7 @@ export function ExploratoryViewContextProvider({
const value = {
reportTypes,
dataTypes,
indexPatterns,
dataViews,
reportConfigMap,
setHeaderActionMenu,
theme$,

View file

@ -7,7 +7,7 @@
import React from 'react';
import Embeddable from './embeddable';
import { LensPublicStart } from '../../../../../../lens/public';
import { IndexPatternState } from '../hooks/use_app_index_pattern';
import { DataViewState } from '../hooks/use_app_data_view';
import { render } from '../rtl_helpers';
import { AddToCaseAction } from '../header/add_to_case_action';
import { ActionTypes } from './use_actions';
@ -77,7 +77,7 @@ const mockTimeRange = {
};
const mockOwner = 'securitySolution';
const mockAppId = 'securitySolutionUI';
const mockIndexPatterns = {} as IndexPatternState;
const mockDataViews = {} as DataViewState;
const mockReportType = 'kpi-over-time';
const mockTitle = 'mockTitle';
const mockLens = {
@ -110,7 +110,7 @@ describe('Embeddable', () => {
caseOwner={mockOwner}
customLensAttrs={mockLensAttrs}
customTimeRange={mockTimeRange}
indexPatterns={mockIndexPatterns}
indexPatterns={mockDataViews}
lens={mockLens}
reportType={mockReportType}
title={mockTitle}
@ -128,7 +128,7 @@ describe('Embeddable', () => {
caseOwner={mockOwner}
customLensAttrs={mockLensAttrs}
customTimeRange={mockTimeRange}
indexPatterns={mockIndexPatterns}
indexPatterns={mockDataViews}
lens={mockLens}
reportType={mockReportType}
withActions={mockActions}
@ -146,7 +146,7 @@ describe('Embeddable', () => {
caseOwner={mockOwner}
customLensAttrs={mockLensAttrs}
customTimeRange={mockTimeRange}
indexPatterns={mockIndexPatterns}
indexPatterns={mockDataViews}
lens={mockLens}
reportType={mockReportType}
withActions={mockActions}
@ -181,7 +181,7 @@ describe('Embeddable', () => {
caseOwner={mockOwner}
customLensAttrs={mockLensAttrs}
customTimeRange={mockTimeRange}
indexPatterns={mockIndexPatterns}
indexPatterns={mockDataViews}
isSingleMetric={true}
lens={mockLens}
reportType={mockReportType}
@ -213,7 +213,7 @@ describe('Embeddable', () => {
caseOwner={mockOwner}
customLensAttrs={mockLensAttrs}
customTimeRange={mockTimeRange}
indexPatterns={mockIndexPatterns}
indexPatterns={mockDataViews}
isSingleMetric={true}
lens={mockLens}
reportType={mockReportType}

View file

@ -14,7 +14,7 @@ import { AppDataType, ReportViewType } from '../types';
import { getLayerConfigs } from '../hooks/use_lens_attributes';
import { LensEmbeddableInput, LensPublicStart, XYState } from '../../../../../../lens/public';
import { OperationTypeComponent } from '../series_editor/columns/operation_type_select';
import { IndexPatternState } from '../hooks/use_app_index_pattern';
import { DataViewState } from '../hooks/use_app_data_view';
import { ReportConfigMap } from '../contexts/exploratory_view_config';
import { obsvReportConfigMap } from '../obsv_exploratory_view';
import { ActionTypes, useActions } from './use_actions';
@ -46,7 +46,7 @@ export interface ExploratoryEmbeddableProps {
export interface ExploratoryEmbeddableComponentProps extends ExploratoryEmbeddableProps {
lens: LensPublicStart;
indexPatterns: IndexPatternState;
indexPatterns: DataViewState;
}
// eslint-disable-next-line import/no-default-export

View file

@ -11,7 +11,7 @@ import { CoreStart } from 'kibana/public';
import type { ExploratoryEmbeddableProps, ExploratoryEmbeddableComponentProps } from './embeddable';
import { ObservabilityDataViews } from '../../../../utils/observability_data_views';
import { ObservabilityPublicPluginsStart } from '../../../../plugin';
import type { IndexPatternState } from '../hooks/use_app_index_pattern';
import type { DataViewState } from '../hooks/use_app_data_view';
import { EuiThemeProvider } from '../../../../../../../../src/plugins/kibana_react/common';
import type { AppDataType } from '../types';
@ -30,7 +30,7 @@ export function getExploratoryViewEmbeddable(
plugins: ObservabilityPublicPluginsStart
) {
return (props: ExploratoryEmbeddableProps) => {
const [indexPatterns, setIndexPatterns] = useState<IndexPatternState>({} as IndexPatternState);
const [indexPatterns, setIndexPatterns] = useState<DataViewState>({} as DataViewState);
const [loading, setLoading] = useState(false);
const series = props.attributes && props.attributes[0];

View file

@ -7,7 +7,7 @@
import React from 'react';
import { screen } from '@testing-library/dom';
import { render, mockAppIndexPattern } from './rtl_helpers';
import { render, mockAppDataView } from './rtl_helpers';
import { ExploratoryView } from './exploratory_view';
import * as obsvDataViews from '../../../utils/observability_data_views/observability_data_views';
import * as pluginHook from '../../../hooks/use_plugin_context';
@ -19,7 +19,7 @@ jest.spyOn(pluginHook, 'usePluginContext').mockReturnValue({
},
} as any);
describe('ExploratoryView', () => {
mockAppIndexPattern();
mockAppDataView();
beforeEach(() => {
const indexPattern = createStubIndexPattern({

View file

@ -22,7 +22,7 @@ import { ObservabilityPublicPluginsStart } from '../../../plugin';
import { useSeriesStorage } from './hooks/use_series_storage';
import { useLensAttributes } from './hooks/use_lens_attributes';
import { TypedLensByValueInput } from '../../../../../lens/public';
import { useAppIndexPatternContext } from './hooks/use_app_index_pattern';
import { useAppDataViewContext } from './hooks/use_app_data_view';
import { SeriesViews } from './views/series_views';
import { LensEmbeddable } from './lens_embeddable';
import { EmptyView } from './components/empty_view';
@ -52,7 +52,7 @@ export function ExploratoryView({
null
);
const { loadIndexPattern, loading } = useAppIndexPatternContext();
const { loadDataView, loading } = useAppDataViewContext();
const { firstSeries, allSeries, lastRefresh, reportType, setLastRefresh } = useSeriesStorage();
@ -68,11 +68,11 @@ export function ExploratoryView({
useEffect(() => {
allSeries.forEach((seriesT) => {
loadIndexPattern({
loadDataView({
dataType: seriesT.dataType,
});
});
}, [allSeries, loadIndexPattern]);
}, [allSeries, loadDataView]);
useEffect(() => {
setLensAttributes(lensAttributesT);

View file

@ -7,7 +7,7 @@
import React, { createContext, useContext, Context, useState, useCallback, useMemo } from 'react';
import { HttpFetchError } from 'kibana/public';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { AppDataType } from '../types';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { ObservabilityPublicPluginsStart } from '../../../../plugin';
@ -17,40 +17,38 @@ import { useExploratoryView } from '../contexts/exploratory_view_config';
import { DataViewInsufficientAccessError } from '../../../../../../../../src/plugins/data_views/common';
import { getApmDataViewTitle } from '../utils/utils';
export interface IndexPatternContext {
export interface DataViewContext {
loading: boolean;
indexPatterns: IndexPatternState;
indexPatternErrors: IndexPatternErrors;
dataViews: DataViewState;
dataViewErrors: DataViewErrors;
hasAppData: HasAppDataState;
loadIndexPattern: (params: { dataType: AppDataType }) => void;
loadDataView: (params: { dataType: AppDataType }) => void;
}
export const IndexPatternContext = createContext<Partial<IndexPatternContext>>({});
export const DataViewContext = createContext<Partial<DataViewContext>>({});
interface ProviderProps {
children: JSX.Element;
}
type HasAppDataState = Record<AppDataType, boolean | undefined>;
export type IndexPatternState = Record<AppDataType, IndexPattern>;
export type IndexPatternErrors = Record<AppDataType, HttpFetchError>;
export type DataViewState = Record<AppDataType, DataView>;
export type DataViewErrors = Record<AppDataType, HttpFetchError>;
type LoadingState = Record<AppDataType, boolean>;
export function IndexPatternContextProvider({ children }: ProviderProps) {
export function DataViewContextProvider({ children }: ProviderProps) {
const [loading, setLoading] = useState<LoadingState>({} as LoadingState);
const [indexPatterns, setIndexPatterns] = useState<IndexPatternState>({} as IndexPatternState);
const [indexPatternErrors, setIndexPatternErrors] = useState<IndexPatternErrors>(
{} as IndexPatternErrors
);
const [dataViews, setDataViews] = useState<DataViewState>({} as DataViewState);
const [dataViewErrors, setDataViewErrors] = useState<DataViewErrors>({} as DataViewErrors);
const [hasAppData, setHasAppData] = useState<HasAppDataState>({} as HasAppDataState);
const {
services: { dataViews },
services: { dataViews: dataViewsService },
} = useKibana<ObservabilityPublicPluginsStart>();
const { indexPatterns: indexPatternsList } = useExploratoryView();
const { dataViews: dataViewsList } = useExploratoryView();
const loadIndexPattern: IndexPatternContext['loadIndexPattern'] = useCallback(
const loadDataView: DataViewContext['loadDataView'] = useCallback(
async ({ dataType }) => {
if (typeof hasAppData[dataType] === 'undefined' && !loading[dataType]) {
setLoading((prevState) => ({ ...prevState, [dataType]: true }));
@ -58,8 +56,8 @@ export function IndexPatternContextProvider({ children }: ProviderProps) {
try {
let hasDataT = false;
let indices: string | undefined = '';
if (indexPatternsList[dataType]) {
indices = indexPatternsList[dataType];
if (dataViewsList[dataType]) {
indices = dataViewsList[dataType];
hasDataT = true;
}
switch (dataType) {
@ -84,10 +82,10 @@ export function IndexPatternContextProvider({ children }: ProviderProps) {
setHasAppData((prevState) => ({ ...prevState, [dataType]: hasDataT }));
if (hasDataT && indices) {
const obsvIndexP = new ObservabilityDataViews(dataViews);
const indPattern = await obsvIndexP.getDataView(dataType, indices);
const obsvDataV = new ObservabilityDataViews(dataViewsService);
const dataV = await obsvDataV.getDataView(dataType, indices);
setIndexPatterns((prevState) => ({ ...prevState, [dataType]: indPattern }));
setDataViews((prevState) => ({ ...prevState, [dataType]: dataV }));
}
setLoading((prevState) => ({ ...prevState, [dataType]: false }));
} catch (e) {
@ -95,48 +93,48 @@ export function IndexPatternContextProvider({ children }: ProviderProps) {
e instanceof DataViewInsufficientAccessError ||
(e as HttpFetchError).body === 'Forbidden'
) {
setIndexPatternErrors((prevState) => ({ ...prevState, [dataType]: e }));
setDataViewErrors((prevState) => ({ ...prevState, [dataType]: e }));
}
setLoading((prevState) => ({ ...prevState, [dataType]: false }));
}
}
},
[dataViews, hasAppData, indexPatternsList, loading]
[dataViewsService, hasAppData, dataViewsList, loading]
);
return (
<IndexPatternContext.Provider
<DataViewContext.Provider
value={{
hasAppData,
indexPatterns,
loadIndexPattern,
indexPatternErrors,
dataViews,
loadDataView,
dataViewErrors,
loading: !!Object.values(loading).find((loadingT) => loadingT),
}}
>
{children}
</IndexPatternContext.Provider>
</DataViewContext.Provider>
);
}
export const useAppIndexPatternContext = (dataType?: AppDataType) => {
const { loading, hasAppData, loadIndexPattern, indexPatterns, indexPatternErrors } = useContext(
IndexPatternContext as unknown as Context<IndexPatternContext>
export const useAppDataViewContext = (dataType?: AppDataType) => {
const { loading, hasAppData, loadDataView, dataViews, dataViewErrors } = useContext(
DataViewContext as unknown as Context<DataViewContext>
);
if (dataType && !indexPatterns?.[dataType] && !loading) {
loadIndexPattern({ dataType });
if (dataType && !dataViews?.[dataType] && !loading) {
loadDataView({ dataType });
}
return useMemo(() => {
return {
hasAppData,
loading,
indexPatterns,
indexPatternErrors,
indexPattern: dataType ? indexPatterns?.[dataType] : undefined,
dataViews,
dataViewErrors,
dataView: dataType ? dataViews?.[dataType] : undefined,
hasData: dataType ? hasAppData?.[dataType] : undefined,
loadIndexPattern,
loadDataView,
};
}, [dataType, hasAppData, indexPatternErrors, indexPatterns, loadIndexPattern, loading]);
}, [dataType, hasAppData, dataViewErrors, dataViews, loadDataView, loading]);
};

View file

@ -9,7 +9,7 @@ import { useCallback, useEffect, useState } from 'react';
import { Filter } from '@kbn/es-query';
import { useKibana } from '../../../../utils/kibana_react';
import { SeriesConfig, SeriesUrl } from '../types';
import { useAppIndexPatternContext } from './use_app_index_pattern';
import { useAppDataViewContext } from './use_app_data_view';
import { buildExistsFilter, urlFilterToPersistedFilter } from '../configurations/utils';
import { getFiltersFromDefs } from './use_lens_attributes';
import { RECORDS_FIELD, RECORDS_PERCENTAGE_FIELD } from '../configurations/constants';
@ -25,21 +25,21 @@ export const useDiscoverLink = ({ series, seriesConfig }: UseDiscoverLink) => {
application: { navigateToUrl },
} = kServices;
const { indexPatterns } = useAppIndexPatternContext();
const { dataViews } = useAppDataViewContext();
const locator = kServices.discover?.locator;
const [discoverUrl, setDiscoverUrl] = useState<string>('');
useEffect(() => {
const indexPattern = indexPatterns?.[series.dataType];
const dataView = dataViews?.[series.dataType];
if (indexPattern) {
if (dataView) {
const definitions = series.reportDefinitions ?? {};
const urlFilters = (series.filters ?? []).concat(getFiltersFromDefs(definitions));
const filters = urlFilterToPersistedFilter({
indexPattern,
dataView,
urlFilters,
initFilters: seriesConfig?.baseFilters,
}) as Filter[];
@ -51,7 +51,7 @@ export const useDiscoverLink = ({ series, seriesConfig }: UseDiscoverLink) => {
selectedMetricField !== RECORDS_FIELD &&
selectedMetricField !== RECORDS_PERCENTAGE_FIELD
) {
filters.push(buildExistsFilter(selectedMetricField, indexPattern)[0]);
filters.push(buildExistsFilter(selectedMetricField, dataView)[0]);
}
const getDiscoverUrl = async () => {
@ -59,14 +59,14 @@ export const useDiscoverLink = ({ series, seriesConfig }: UseDiscoverLink) => {
const newUrl = await locator.getUrl({
filters,
indexPatternId: indexPattern?.id,
indexPatternId: dataView?.id,
});
setDiscoverUrl(newUrl);
};
getDiscoverUrl();
}
}, [
indexPatterns,
dataViews,
series.dataType,
series.filters,
series.reportDefinitions,

View file

@ -11,11 +11,11 @@ import { allSeriesKey, reportTypeKey, UrlStorageContextProvider } from './use_se
import { renderHook } from '@testing-library/react-hooks';
import { useLensAttributes } from './use_lens_attributes';
import { ReportTypes } from '../configurations/constants';
import { mockIndexPattern } from '../rtl_helpers';
import { mockDataView } from '../rtl_helpers';
import { createKbnUrlStateStorage } from '../../../../../../../../src/plugins/kibana_utils/public';
import { TRANSACTION_DURATION } from '../configurations/constants/elasticsearch_fieldnames';
import * as lensAttributes from '../configurations/lens_attributes';
import * as indexPattern from './use_app_index_pattern';
import * as useAppDataViewHook from './use_app_data_view';
import * as theme from '../../../../hooks/use_theme';
import { dataTypes, obsvReportConfigMap, reportTypesList } from '../obsv_exploratory_view';
import { ExploratoryViewContextProvider } from '../contexts/exploratory_view_config';
@ -35,14 +35,14 @@ const mockSingleSeries = [
describe('useExpViewTimeRange', function () {
const storage = createKbnUrlStateStorage({ useHash: false });
// @ts-ignore
jest.spyOn(indexPattern, 'useAppIndexPatternContext').mockReturnValue({
indexPatterns: {
ux: mockIndexPattern,
apm: mockIndexPattern,
mobile: mockIndexPattern,
infra_logs: mockIndexPattern,
infra_metrics: mockIndexPattern,
synthetics: mockIndexPattern,
jest.spyOn(useAppDataViewHook, 'useAppDataViewContext').mockReturnValue({
dataViews: {
ux: mockDataView,
apm: mockDataView,
mobile: mockDataView,
infra_logs: mockDataView,
infra_metrics: mockDataView,
synthetics: mockDataView,
},
});
jest.spyOn(theme, 'useTheme').mockReturnValue({
@ -58,7 +58,7 @@ describe('useExpViewTimeRange', function () {
<ExploratoryViewContextProvider
reportTypes={reportTypesList}
dataTypes={dataTypes}
indexPatterns={{}}
dataViews={{}}
reportConfigMap={obsvReportConfigMap}
setHeaderActionMenu={jest.fn()}
theme$={themeServiceMock.createTheme$()}

View file

@ -19,7 +19,7 @@ import {
import { getDefaultConfigs } from '../configurations/default_configs';
import { ReportViewType, SeriesUrl, UrlFilter } from '../types';
import { IndexPatternState, useAppIndexPatternContext } from './use_app_index_pattern';
import { DataViewState, useAppDataViewContext } from './use_app_data_view';
import { ALL_VALUES_SELECTED } from '../../field_value_suggestions/field_value_combobox';
import { useTheme } from '../../../../hooks/use_theme';
import { EuiTheme } from '../../../../../../../../src/plugins/kibana_react/common';
@ -41,23 +41,23 @@ export function getLayerConfigs(
allSeries: AllSeries,
reportType: ReportViewType,
theme: EuiTheme,
indexPatterns: IndexPatternState,
dataViews: DataViewState,
reportConfigMap: ReportConfigMap
) {
const layerConfigs: LayerConfig[] = [];
allSeries.forEach((series, seriesIndex) => {
const indexPattern = indexPatterns?.[series?.dataType];
const dataView = dataViews?.[series?.dataType];
if (
indexPattern &&
dataView &&
!isEmpty(series.reportDefinitions) &&
!series.hidden &&
series.selectedMetricField
) {
const seriesConfig = getDefaultConfigs({
reportType,
indexPattern,
dataView,
dataType: series.dataType,
reportConfigMap,
});
@ -70,7 +70,7 @@ export function getLayerConfigs(
layerConfigs.push({
filters,
indexPattern,
indexPattern: dataView,
seriesConfig,
time: series.time,
name: series.name,
@ -90,7 +90,7 @@ export function getLayerConfigs(
export const useLensAttributes = (): TypedLensByValueInput['attributes'] | null => {
const { storage, allSeries, lastRefresh, reportType } = useSeriesStorage();
const { indexPatterns } = useAppIndexPatternContext();
const { dataViews } = useAppDataViewContext();
const { reportConfigMap } = useExploratoryView();
@ -101,14 +101,14 @@ export const useLensAttributes = (): TypedLensByValueInput['attributes'] | null
const allSeriesT: AllSeries = convertAllShortSeries(storage.get(allSeriesKey) ?? []);
const reportTypeT: ReportViewType = storage.get(reportTypeKey) as ReportViewType;
if (isEmpty(indexPatterns) || isEmpty(allSeriesT) || !reportTypeT) {
if (isEmpty(dataViews) || isEmpty(allSeriesT) || !reportTypeT) {
return null;
}
const layerConfigs = getLayerConfigs(
allSeriesT,
reportTypeT,
theme,
indexPatterns,
dataViews,
reportConfigMap
);
@ -121,5 +121,5 @@ export const useLensAttributes = (): TypedLensByValueInput['attributes'] | null
return lensAttributes.getJSON();
// we also want to check the state on allSeries changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [indexPatterns, reportType, storage, theme, lastRefresh, allSeries]);
}, [dataViews, reportType, storage, theme, lastRefresh, allSeries]);
};

View file

@ -12,7 +12,7 @@ import { ExploratoryView } from './exploratory_view';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { ObservabilityPublicPluginsStart } from '../../../plugin';
import { useBreadcrumbs } from '../../../hooks/use_breadcrumbs';
import { IndexPatternContextProvider } from './hooks/use_app_index_pattern';
import { DataViewContextProvider } from './hooks/use_app_data_view';
import {
createKbnUrlStateStorage,
withNotifyOnErrors,
@ -73,11 +73,11 @@ export function ExploratoryViewPage({
return (
<ObservabilityPageTemplate pageHeader={{ pageTitle: PAGE_TITLE }}>
<IndexPatternContextProvider>
<DataViewContextProvider>
<UrlStorageContextProvider storage={kbnUrlStateStorage}>
<ExploratoryView saveAttributes={saveAttributes} />
</UrlStorageContextProvider>
</IndexPatternContextProvider>
</DataViewContextProvider>
</ObservabilityPageTemplate>
);
}

View file

@ -101,7 +101,7 @@ export function ObservabilityExploratoryView() {
<ExploratoryViewContextProvider
reportTypes={reportTypesList}
dataTypes={dataTypes}
indexPatterns={{}}
dataViews={{}}
reportConfigMap={obsvReportConfigMap}
setHeaderActionMenu={appMountParameters.setHeaderActionMenu}
theme$={appMountParameters.theme$}

View file

@ -27,8 +27,8 @@ import {
import { ObservabilityPublicPluginsStart } from '../../../plugin';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';
import { lensPluginMock } from '../../../../../lens/public/mocks';
import * as useAppIndexPatternHook from './hooks/use_app_index_pattern';
import { IndexPatternContext, IndexPatternContextProvider } from './hooks/use_app_index_pattern';
import * as useAppDataViewHook from './hooks/use_app_data_view';
import { DataViewContext, DataViewContextProvider } from './hooks/use_app_data_view';
import {
AllSeries,
reportTypeKey,
@ -41,13 +41,16 @@ import * as useSeriesFilterHook from './hooks/use_series_filters';
import * as useHasDataHook from '../../../hooks/use_has_data';
import * as useValuesListHook from '../../../hooks/use_values_list';
import indexPatternData from './configurations/test_data/test_index_pattern.json';
import dataViewData from './configurations/test_data/test_data_view.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setIndexPatterns } from '../../../../../../../src/plugins/data/public/services';
import { IndexPattern, IndexPatternsContract } from '../../../../../../../src/plugins/data/common';
import type {
DataView,
DataViewsContract,
} from '../../../../../../../src/plugins/data_views/common';
import { AppDataType, SeriesUrl, UrlFilter } from './types';
import { createStubIndexPattern } from '../../../../../../../src/plugins/data/common/stubs';
import { createStubDataView } from '../../../../../../../src/plugins/data_views/common/stubs';
import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks';
import { dataViewPluginMocks } from '../../../../../../../src/plugins/data_views/public/mocks';
import { ListItem } from '../../../hooks/use_values_list';
@ -147,18 +150,18 @@ export function MockKibanaProvider<ExtraCore extends Partial<CoreStart>>({
core,
kibanaProps,
}: MockKibanaProviderProps<ExtraCore>) {
const indexPattern = mockIndexPattern;
const dataView = mockDataView;
setIndexPatterns({
...[indexPattern],
get: async () => indexPattern,
} as unknown as IndexPatternsContract);
...[dataView],
get: async () => dataView,
} as unknown as DataViewsContract);
return (
<KibanaContextProvider services={{ ...core }} {...kibanaProps}>
<EuiThemeProvider darkMode={false}>
<I18nProvider>
<IndexPatternContextProvider>{children}</IndexPatternContextProvider>
<DataViewContextProvider>{children}</DataViewContextProvider>
</I18nProvider>
</EuiThemeProvider>
</KibanaContextProvider>
@ -211,7 +214,7 @@ export function render<ExtraCore>(
<ExploratoryViewContextProvider
reportTypes={reportTypesList}
dataTypes={dataTypes}
indexPatterns={{}}
dataViews={{}}
reportConfigMap={obsvReportConfigMap}
setHeaderActionMenu={jest.fn()}
theme$={themeServiceMock.createTheme$()}
@ -257,19 +260,19 @@ export const mockUseHasData = () => {
return { spy, onRefreshTimeRange };
};
export const mockAppIndexPattern = (props?: Partial<IndexPatternContext>) => {
const loadIndexPattern = jest.fn();
const spy = jest.spyOn(useAppIndexPatternHook, 'useAppIndexPatternContext').mockReturnValue({
indexPattern: mockIndexPattern,
export const mockAppDataView = (props?: Partial<DataViewContext>) => {
const loadDataView = jest.fn();
const spy = jest.spyOn(useAppDataViewHook, 'useAppDataViewContext').mockReturnValue({
dataView: mockDataView,
hasData: true,
loading: false,
hasAppData: { ux: true } as any,
loadIndexPattern,
indexPatterns: { ux: mockIndexPattern } as unknown as Record<AppDataType, IndexPattern>,
indexPatternErrors: {} as any,
loadDataView,
dataViews: { ux: mockDataView } as unknown as Record<AppDataType, DataView>,
dataViewErrors: {} as any,
...(props || {}),
});
return { spy, loadIndexPattern };
return { spy, loadDataView };
};
export const mockUseValuesList = (values?: ListItem[]) => {
@ -369,12 +372,12 @@ export const mockHistory = {
},
};
export const mockIndexPattern = createStubIndexPattern({
export const mockDataView = createStubDataView({
spec: {
id: 'apm-*',
title: 'apm-*',
timeFieldName: '@timestamp',
fields: JSON.parse(indexPatternData.attributes.fields),
fields: JSON.parse(dataViewData.attributes.fields),
},
});

View file

@ -8,7 +8,7 @@
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { Breakdowns } from './breakdowns';
import { mockIndexPattern, mockUxSeries, render } from '../../rtl_helpers';
import { mockDataView, mockUxSeries, render } from '../../rtl_helpers';
import { getDefaultConfigs } from '../../configurations/default_configs';
import { RECORDS_FIELD } from '../../configurations/constants';
import { USER_AGENT_OS } from '../../configurations/constants/elasticsearch_fieldnames';
@ -17,7 +17,7 @@ import { obsvReportConfigMap } from '../../obsv_exploratory_view';
describe('Breakdowns', function () {
const dataViewSeries = getDefaultConfigs({
reportType: 'data-distribution',
indexPattern: mockIndexPattern,
dataView: mockDataView,
dataType: 'ux',
reportConfigMap: obsvReportConfigMap,
});
@ -62,7 +62,7 @@ describe('Breakdowns', function () {
it('does not show percentile breakdown for records metrics', function () {
const kpiConfig = getDefaultConfigs({
reportType: 'kpi-over-time',
indexPattern: mockIndexPattern,
dataView: mockDataView,
dataType: 'ux',
reportConfigMap: obsvReportConfigMap,
});

View file

@ -9,7 +9,7 @@ import { EuiComboBox, EuiFlexItem } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { SeriesConfig, SeriesUrl } from '../../types';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { useSeriesStorage } from '../../hooks/use_series_storage';
import { LABEL_FIELDS_BREAKDOWN } from '../../configurations/constants';
@ -19,9 +19,9 @@ interface Props {
seriesConfig?: SeriesConfig;
}
export function LabelsBreakdown({ series, seriesId }: Props) {
const { indexPattern } = useAppIndexPatternContext(series.dataType);
const { dataView } = useAppDataViewContext(series.dataType);
const labelFields = indexPattern?.fields.filter((field) => field.name.startsWith('labels.'));
const labelFields = dataView?.fields.filter((field) => field.name.startsWith('labels.'));
const { setSeries } = useSeriesStorage();

View file

@ -7,7 +7,7 @@
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { mockAppIndexPattern, mockUxSeries, render } from '../../rtl_helpers';
import { mockAppDataView, mockUxSeries, render } from '../../rtl_helpers';
import { DataTypesSelect } from './data_type_select';
import { DataTypes } from '../../configurations/constants';
import { DataTypesLabels } from '../../obsv_exploratory_view';
@ -15,7 +15,7 @@ import { DataTypesLabels } from '../../obsv_exploratory_view';
describe('DataTypeSelect', function () {
const seriesId = 0;
mockAppIndexPattern();
mockAppDataView();
it('should render properly', function () {
render(<DataTypesSelect seriesId={seriesId} series={mockUxSeries} />);

View file

@ -14,7 +14,7 @@ import { DateRangePicker } from '../../components/date_range_picker';
import { SeriesDatePicker } from '../../components/series_date_picker';
import { AppDataType, SeriesUrl } from '../../types';
import { ReportTypes } from '../../configurations/constants';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { SyntheticsAddData } from '../../../add_data_buttons/synthetics_add_data';
import { MobileAddData } from '../../../add_data_buttons/mobile_add_data';
import { UXAddData } from '../../../add_data_buttons/ux_add_data';
@ -36,7 +36,7 @@ const AddDataComponents: Record<AppDataType, React.FC | null> = {
export function DatePickerCol({ seriesId, series }: Props) {
const { reportType } = useSeriesStorage();
const { hasAppData } = useAppIndexPatternContext();
const { hasAppData } = useAppDataViewContext();
if (!series.dataType) {
return null;

View file

@ -8,7 +8,7 @@
import React from 'react';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { FilterExpanded } from './filter_expanded';
import { mockUxSeries, mockAppIndexPattern, mockUseValuesList, render } from '../../rtl_helpers';
import { mockUxSeries, mockAppDataView, mockUseValuesList, render } from '../../rtl_helpers';
import { USER_AGENT_NAME } from '../../configurations/constants/elasticsearch_fieldnames';
describe('FilterExpanded', function () {
@ -18,7 +18,7 @@ describe('FilterExpanded', function () {
it('render', async () => {
const initSeries = { filters };
mockAppIndexPattern();
mockAppDataView();
render(
<FilterExpanded

View file

@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
import React, { useMemo } from 'react';
import { EuiFilterButton, hexToRgb } from '@elastic/eui';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { useSeriesFilters } from '../../hooks/use_series_filters';
import { euiStyled } from '../../../../../../../../../src/plugins/kibana_react/common';
import FieldValueSuggestions from '../../../field_value_suggestions';
@ -41,7 +41,7 @@ export function FilterValueButton({
nestedField,
allSelectedValues,
}: Props) {
const { indexPatterns } = useAppIndexPatternContext(series.dataType);
const { dataViews } = useAppDataViewContext(series.dataType);
const { setFilter, removeFilter } = useSeriesFilters({ seriesId, series });
@ -103,7 +103,7 @@ export function FilterValueButton({
anchorPosition="rightCenter"
time={series.time}
asCombobox={false}
indexPatternTitle={indexPatterns[series.dataType]?.title}
dataViewTitle={dataViews[series.dataType]?.title}
/>
) : (
button

View file

@ -9,7 +9,7 @@ import React from 'react';
import { isEmpty } from 'lodash';
import { i18n } from '@kbn/i18n';
import { EuiBadge } from '@elastic/eui';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { SeriesConfig, SeriesUrl } from '../../types';
interface Props {
@ -18,7 +18,7 @@ interface Props {
}
export function IncompleteBadge({ seriesConfig, series }: Props) {
const { loading } = useAppIndexPatternContext();
const { loading } = useAppDataViewContext();
if (!seriesConfig) {
return null;

View file

@ -9,8 +9,8 @@ import { fireEvent, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { getDefaultConfigs } from '../../configurations/default_configs';
import {
mockAppIndexPattern,
mockIndexPattern,
mockAppDataView,
mockDataView,
mockUseValuesList,
mockUxSeries,
render,
@ -19,12 +19,12 @@ import { ReportDefinitionCol } from './report_definition_col';
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
describe('Series Builder ReportDefinitionCol', function () {
mockAppIndexPattern();
mockAppDataView();
const seriesId = 0;
const seriesConfig = getDefaultConfigs({
reportType: 'data-distribution',
indexPattern: mockIndexPattern,
dataView: mockDataView,
dataType: 'ux',
reportConfigMap: obsvReportConfigMap,
});

View file

@ -9,7 +9,7 @@ import React, { useMemo } from 'react';
import { isEmpty } from 'lodash';
import { ExistsFilter, PhraseFilter } from '@kbn/es-query';
import FieldValueSuggestions from '../../../field_value_suggestions';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { ESFilter } from '../../../../../../../../../src/core/types/elasticsearch';
import { PersistableFilter } from '../../../../../../../lens/common';
import { buildPhrasesFilter } from '../../configurations/utils';
@ -36,7 +36,7 @@ export function ReportDefinitionField({
onChange,
filters,
}: Props) {
const { indexPattern } = useAppIndexPatternContext(series.dataType);
const { dataView } = useAppDataViewContext(series.dataType);
const field = typeof fieldProp === 'string' ? fieldProp : fieldProp.field;
@ -62,10 +62,10 @@ export function ReportDefinitionField({
definitionFields.forEach((fieldObj) => {
const fieldT = typeof fieldObj === 'string' ? fieldObj : fieldObj.field;
if (indexPattern && selectedReportDefinitions?.[fieldT] && fieldT !== field) {
if (dataView && selectedReportDefinitions?.[fieldT] && fieldT !== field) {
const values = selectedReportDefinitions?.[fieldT];
if (!values.includes(ALL_VALUES_SELECTED)) {
const valueFilter = buildPhrasesFilter(fieldT, values, indexPattern)[0];
const valueFilter = buildPhrasesFilter(fieldT, values, dataView)[0];
if (valueFilter.query) {
filtersN.push(valueFilter.query);
}
@ -78,7 +78,7 @@ export function ReportDefinitionField({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(selectedReportDefinitions), JSON.stringify(baseFilters)]);
if (!indexPattern) {
if (!dataView) {
return null;
}
@ -86,7 +86,7 @@ export function ReportDefinitionField({
<FieldValueSuggestions
label={labels[field] ?? field}
sourceField={field}
indexPatternTitle={indexPattern.title}
dataViewTitle={dataView.title}
selectedValue={selectedReportDefinitions?.[field]}
onChange={(val?: string[]) => onChange(field, val)}
filters={queryFilters}

View file

@ -7,18 +7,18 @@
import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import { mockAppIndexPattern, mockIndexPattern, mockUxSeries, render } from '../../rtl_helpers';
import { mockAppDataView, mockDataView, mockUxSeries, render } from '../../rtl_helpers';
import { SelectedFilters } from './selected_filters';
import { getDefaultConfigs } from '../../configurations/default_configs';
import { USER_AGENT_NAME } from '../../configurations/constants/elasticsearch_fieldnames';
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
describe('SelectedFilters', function () {
mockAppIndexPattern();
mockAppDataView();
const dataViewSeries = getDefaultConfigs({
reportType: 'data-distribution',
indexPattern: mockIndexPattern,
dataView: mockDataView,
dataType: 'ux',
reportConfigMap: obsvReportConfigMap,
});

View file

@ -10,7 +10,7 @@ import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/e
import { i18n } from '@kbn/i18n';
import { FilterLabel } from '../../components/filter_label';
import { SeriesConfig, SeriesUrl, UrlFilter } from '../../types';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { useSeriesFilters } from '../../hooks/use_series_filters';
import { useSeriesStorage } from '../../hooks/use_series_storage';
@ -28,16 +28,16 @@ export function SelectedFilters({ seriesId, series, seriesConfig }: Props) {
const { removeFilter, replaceFilter } = useSeriesFilters({ seriesId, series });
const { indexPattern } = useAppIndexPatternContext(series.dataType);
const { dataView } = useAppDataViewContext(series.dataType);
if (filters.length === 0 || !indexPattern) {
if (filters.length === 0 || !dataView) {
return null;
}
const btnProps = {
seriesId,
series,
indexPattern,
dataView,
};
return (

View file

@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n';
import { useSeriesStorage } from '../../hooks/use_series_storage';
import { SeriesConfig, SeriesUrl } from '../../types';
import { useDiscoverLink } from '../../hooks/use_discover_link';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
interface Props {
seriesId: number;
@ -34,9 +34,9 @@ export function SeriesActions({ seriesId, series, seriesConfig, onEditClick }: P
const { href: discoverHref } = useDiscoverLink({ series, seriesConfig });
const { indexPatterns } = useAppIndexPatternContext();
const { dataViews } = useAppDataViewContext();
const indexPattern = indexPatterns?.[series.dataType];
const dataView = dataViews?.[series.dataType];
const deleteDisabled = seriesId === 0 && allSeries.length > 1;
const copySeries = () => {
@ -109,7 +109,7 @@ export function SeriesActions({ seriesId, series, seriesConfig, onEditClick }: P
icon="discoverApp"
href={discoverHref}
aria-label={VIEW_SAMPLE_DOCUMENTS_LABEL}
disabled={!series.dataType || !series.selectedMetricField || !indexPattern}
disabled={!series.dataType || !series.selectedMetricField || !dataView}
target="_blank"
>
{VIEW_SAMPLE_DOCUMENTS_LABEL}

View file

@ -19,7 +19,7 @@ import { EuiSelectable } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FilterProps } from '../columns/filter_expanded';
import { useAppIndexPatternContext } from '../../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../../hooks/use_app_data_view';
import { FilterValuesList } from './filter_values_list';
import { useFilterValues } from '../use_filter_values';
@ -28,9 +28,9 @@ export function LabelsFieldFilter(props: FilterProps) {
const [query, setQuery] = useState('');
const { indexPattern } = useAppIndexPatternContext(series.dataType);
const { dataView } = useAppDataViewContext(series.dataType);
const labelFields = indexPattern?.fields.filter((field) => field.name.startsWith('labels.'));
const labelFields = dataView?.fields.filter((field) => field.name.startsWith('labels.'));
const [isPopoverOpen, setPopover] = useState(false);

View file

@ -8,7 +8,7 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { ExpandedSeriesRow } from './expanded_series_row';
import { mockIndexPattern, mockUxSeries, render } from '../rtl_helpers';
import { mockDataView, mockUxSeries, render } from '../rtl_helpers';
import { getDefaultConfigs } from '../configurations/default_configs';
import { PERCENTILE } from '../configurations/constants';
import { obsvReportConfigMap } from '../obsv_exploratory_view';
@ -17,7 +17,7 @@ describe('ExpandedSeriesRow', function () {
const dataViewSeries = getDefaultConfigs({
reportConfigMap: obsvReportConfigMap,
reportType: 'kpi-over-time',
indexPattern: mockIndexPattern,
dataView: mockDataView,
dataType: 'ux',
});

View file

@ -8,7 +8,7 @@
import React from 'react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { mockAppIndexPattern, mockIndexPattern, mockUxSeries, render } from '../rtl_helpers';
import { mockAppDataView, mockDataView, mockUxSeries, render } from '../rtl_helpers';
import { getDefaultConfigs } from '../configurations/default_configs';
import { PERCENTILE } from '../configurations/constants';
import { ReportMetricOptions } from './report_metric_options';
@ -18,7 +18,7 @@ describe('ReportMetricOptions', function () {
const dataViewSeries = getDefaultConfigs({
dataType: 'ux',
reportType: 'kpi-over-time',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});
@ -31,7 +31,7 @@ describe('ReportMetricOptions', function () {
});
it('should display loading if index pattern is not available and is loading', async function () {
mockAppIndexPattern({ loading: true, indexPatterns: undefined });
mockAppDataView({ loading: true, dataViews: undefined });
const { container } = render(
<ReportMetricOptions
seriesId={0}
@ -44,7 +44,7 @@ describe('ReportMetricOptions', function () {
});
it('should not display loading if index pattern is already loaded', async function () {
mockAppIndexPattern({ loading: true });
mockAppDataView({ loading: true });
render(
<ReportMetricOptions
seriesId={0}
@ -57,7 +57,7 @@ describe('ReportMetricOptions', function () {
});
it('should include a tooltip for the report metric', async function () {
mockAppIndexPattern({ loading: false });
mockAppDataView({ loading: false });
const { getByText, findByText } = render(
<ReportMetricOptions
seriesId={0}

View file

@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { useSeriesStorage } from '../hooks/use_series_storage';
import { SeriesConfig, SeriesUrl } from '../types';
import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../hooks/use_app_data_view';
import { RECORDS_FIELD, RECORDS_PERCENTAGE_FIELD } from '../configurations/constants';
interface Props {
@ -35,7 +35,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
const [showOptions, setShowOptions] = useState(false);
const metricOptions = seriesConfig?.metricOptions;
const { indexPatterns, indexPatternErrors, loading } = useAppIndexPatternContext();
const { dataViews, dataViewErrors, loading } = useAppDataViewContext();
const onChange = (value?: string) => {
setSeries(seriesId, {
@ -52,14 +52,14 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
return null;
}
const indexPattern = indexPatterns?.[series.dataType];
const indexPatternError = indexPatternErrors?.[series.dataType];
const dataView = dataViews?.[series.dataType];
const dataViewError = dataViewErrors?.[series.dataType];
const options = (metricOptions ?? []).map(({ label, field, id }) => {
let disabled = false;
if (field !== RECORDS_FIELD && field !== RECORDS_PERCENTAGE_FIELD && field) {
disabled = !Boolean(indexPattern?.getFieldByName(field));
disabled = !Boolean(dataView?.getFieldByName(field));
}
return {
disabled,
@ -85,19 +85,19 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
};
});
if (indexPatternError && !indexPattern && !loading) {
if (dataViewError && !dataView && !loading) {
// TODO: Add a link to docs to explain how to add index patterns
return (
<EuiText color="danger" className="eui-textNoWrap">
{indexPatternError.body?.error === 'Forbidden' ||
indexPatternError.name === 'DataViewInsufficientAccessError'
{dataViewError.body?.error === 'Forbidden' ||
dataViewError.name === 'DataViewInsufficientAccessError'
? NO_PERMISSIONS
: indexPatternError.body.message}
: dataViewError.body.message}
</EuiText>
);
}
if (!indexPattern && !loading) {
if (!dataView && !loading) {
return <EuiText>{NO_DATA_AVAILABLE}</EuiText>;
}
@ -111,7 +111,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
onClick={() => setShowOptions((prevState) => !prevState)}
fill
size="s"
isLoading={!indexPattern && loading}
isLoading={!dataView && loading}
buttonRef={focusButton}
>
{SELECT_REPORT_METRIC_LABEL}
@ -133,7 +133,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
</EuiPopover>
)}
{series.selectedMetricField &&
(indexPattern ? (
(dataView ? (
<EuiToolTip position="top" content={REPORT_METRIC_TOOLTIP}>
<EuiBadge
iconType="cross"

View file

@ -12,7 +12,7 @@ import { rgba } from 'polished';
import { euiStyled } from '../../../../../../../../src/plugins/kibana_react/common';
import { AppDataType, ReportViewType, BuilderItem } from '../types';
import { SeriesContextValue, useSeriesStorage } from '../hooks/use_series_storage';
import { IndexPatternState, useAppIndexPatternContext } from '../hooks/use_app_index_pattern';
import { DataViewState, useAppDataViewContext } from '../hooks/use_app_data_view';
import { getDefaultConfigs } from '../configurations/default_configs';
import { ReportTypesSelect } from './columns/report_type_select';
import { ViewActions } from '../views/view_actions';
@ -28,23 +28,23 @@ export interface ReportTypeItem {
type ExpandedRowMap = Record<string, true>;
export const getSeriesToEdit = ({
indexPatterns,
dataViews,
allSeries,
reportType,
reportConfigMap,
}: {
allSeries: SeriesContextValue['allSeries'];
indexPatterns: IndexPatternState;
dataViews: DataViewState;
reportType: ReportViewType;
reportConfigMap: ReportConfigMap;
}): BuilderItem[] => {
const getDataViewSeries = (dataType: AppDataType) => {
if (indexPatterns?.[dataType]) {
if (dataViews?.[dataType]) {
return getDefaultConfigs({
dataType,
reportType,
reportConfigMap,
indexPattern: indexPatterns[dataType],
dataView: dataViews[dataType],
});
}
};
@ -61,7 +61,7 @@ export const SeriesEditor = React.memo(function () {
const { getSeries, allSeries, reportType } = useSeriesStorage();
const { loading, indexPatterns } = useAppIndexPatternContext();
const { loading, dataViews } = useAppDataViewContext();
const { reportConfigMap } = useExploratoryView();
@ -88,7 +88,7 @@ export const SeriesEditor = React.memo(function () {
const newEditorItems = getSeriesToEdit({
reportType,
allSeries,
indexPatterns,
dataViews,
reportConfigMap,
});
@ -108,7 +108,7 @@ export const SeriesEditor = React.memo(function () {
setItemIdToExpandedRowMap((prevState) => {
return { ...prevState, ...newExpandRows };
});
}, [allSeries, getSeries, indexPatterns, loading, reportConfigMap, reportType]);
}, [allSeries, getSeries, dataViews, loading, reportConfigMap, reportType]);
const toggleDetails = (item: BuilderItem) => {
const itemIdToExpandedRowMapValues = { ...itemIdToExpandedRowMap };

View file

@ -8,7 +8,7 @@ import { ExistsFilter, isExistsFilter } from '@kbn/es-query';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { useValuesList } from '../../../../hooks/use_values_list';
import { FilterProps } from './columns/filter_expanded';
import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../hooks/use_app_data_view';
import { ESFilter } from '../../../../../../../../src/core/types/elasticsearch';
import { PersistableFilter } from '../../../../../../lens/common';
@ -16,7 +16,7 @@ export function useFilterValues(
{ field, series, baseFilters, label }: FilterProps,
query?: string
) {
const { indexPatterns } = useAppIndexPatternContext(series.dataType);
const { dataViews } = useAppDataViewContext(series.dataType);
const queryFilters: ESFilter[] = [];
@ -36,6 +36,6 @@ export function useFilterValues(
time: series.time,
keepHistory: true,
filters: queryFilters,
indexPatternTitle: indexPatterns[series.dataType]?.title,
dataViewTitle: dataViews[series.dataType]?.title,
});
}

View file

@ -17,7 +17,7 @@ import {
} from '../../../../../lens/public';
import { PersistableFilter } from '../../../../../lens/common';
import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/common';
export const ReportViewTypes = {
dist: 'data-distribution',
@ -102,7 +102,7 @@ export interface UrlFilter {
}
export interface ConfigProps {
indexPattern: IndexPattern;
dataView: DataView;
series?: SeriesUrl;
}

View file

@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n';
import { SeriesUrl, BuilderItem } from '../types';
import { getSeriesToEdit } from '../series_editor/series_editor';
import { NEW_SERIES_KEY, useSeriesStorage } from '../hooks/use_series_storage';
import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern';
import { useAppDataViewContext } from '../hooks/use_app_data_view';
import { DEFAULT_TIME, ReportTypes } from '../configurations/constants';
import { useExploratoryView } from '../contexts/exploratory_view_config';
@ -21,13 +21,13 @@ export function AddSeriesButton() {
const addSeriesButtonRef = useRef<HTMLButtonElement>(null);
const { getSeries, allSeries, setSeries, reportType } = useSeriesStorage();
const { loading, indexPatterns } = useAppIndexPatternContext();
const { loading, dataViews } = useAppDataViewContext();
const { reportConfigMap } = useExploratoryView();
useEffect(() => {
setEditorItems(getSeriesToEdit({ allSeries, indexPatterns, reportType, reportConfigMap }));
}, [allSeries, getSeries, indexPatterns, loading, reportConfigMap, reportType]);
setEditorItems(getSeriesToEdit({ allSeries, dataViews, reportType, reportConfigMap }));
}, [allSeries, getSeries, dataViews, loading, reportConfigMap, reportType]);
const addSeries = () => {
const prevSeries = allSeries?.[0];

View file

@ -15,7 +15,7 @@ export function FieldValueSuggestions({
fullWidth,
sourceField,
label,
indexPatternTitle,
dataViewTitle,
selectedValue,
excludedValue,
filters,
@ -41,7 +41,7 @@ export function FieldValueSuggestions({
const [query, setQuery] = useState('');
const { values, loading } = useValuesList({
indexPatternTitle,
dataViewTitle,
query,
sourceField,
filters,

View file

@ -33,7 +33,7 @@ interface CommonProps {
}
export type FieldValueSuggestionsProps = CommonProps & {
indexPatternTitle?: string;
dataViewTitle?: string;
sourceField: string;
asCombobox?: boolean;
onChange: (val?: string[], excludedValue?: string[]) => void;

View file

@ -8,28 +8,29 @@
import React from 'react';
import { injectI18n } from '@kbn/i18n-react';
import { Filter, buildPhrasesFilter, buildPhraseFilter } from '@kbn/es-query';
import { FilterItem, IndexPattern } from '../../../../../../../src/plugins/data/public';
import { FilterItem } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/common';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
export function buildFilterLabel({
field,
value,
label,
indexPattern,
dataView,
negate,
}: {
label: string;
value: string | string[];
negate: boolean;
field: string;
indexPattern: IndexPattern;
dataView: DataView;
}) {
const indexField = indexPattern.getFieldByName(field)!;
const indexField = dataView.getFieldByName(field)!;
const filter =
value instanceof Array && value.length > 1
? buildPhrasesFilter(indexField, value, indexPattern)
: buildPhraseFilter(indexField, value as string, indexPattern);
? buildPhrasesFilter(indexField, value, dataView)
: buildPhraseFilter(indexField, value as string, dataView);
filter.meta.type = value instanceof Array && value.length > 1 ? 'phrases' : 'phrase';
@ -49,7 +50,7 @@ export interface FilterValueLabelProps {
negate: boolean;
removeFilter: (field: string, value: string | string[], notVal: boolean) => void;
invertFilter: (val: { field: string; value: string | string[]; negate: boolean }) => void;
indexPattern: IndexPattern;
dataView: DataView;
allowExclusion?: boolean;
}
export function FilterValueLabel({
@ -57,22 +58,22 @@ export function FilterValueLabel({
field,
value,
negate,
indexPattern,
dataView,
invertFilter,
removeFilter,
allowExclusion = true,
}: FilterValueLabelProps) {
const FilterItemI18n = injectI18n(FilterItem);
const filter = buildFilterLabel({ field, value, label, indexPattern, negate });
const filter = buildFilterLabel({ field, value, label, dataView, negate });
const {
services: { uiSettings },
} = useKibana();
return indexPattern ? (
return dataView ? (
<FilterItemI18n
indexPatterns={[indexPattern]}
indexPatterns={[dataView]}
id={`${field}-${value}-${negate}`}
filter={filter}
onRemove={() => {

View file

@ -17,7 +17,7 @@ export interface Props {
sourceField: string;
label: string;
query?: string;
indexPatternTitle?: string;
dataViewTitle?: string;
filters?: ESFilter[];
time?: { from: string; to: string };
keepHistory?: boolean;
@ -59,7 +59,7 @@ const getIncludeClause = (sourceField: string, query?: string) => {
export const useValuesList = ({
sourceField,
indexPatternTitle,
dataViewTitle,
query = '',
filters,
time,
@ -91,7 +91,7 @@ export const useValuesList = ({
const { data, loading } = useEsSearch(
createEsParams({
index: indexPatternTitle!,
index: dataViewTitle!,
body: {
query: {
bool: {
@ -135,7 +135,7 @@ export const useValuesList = ({
},
},
}),
[debouncedQuery, from, to, JSON.stringify(filters), indexPatternTitle, sourceField],
[debouncedQuery, from, to, JSON.stringify(filters), dataViewTitle, sourceField],
{ name: `get${label.replace(/\s/g, '')}ValuesList` }
);

View file

@ -6,7 +6,7 @@
*/
import { dataViewList, ObservabilityDataViews } from './observability_data_views';
import { mockCore, mockIndexPattern } from '../../components/shared/exploratory_view/rtl_helpers';
import { mockCore, mockDataView } from '../../components/shared/exploratory_view/rtl_helpers';
import { SavedObjectNotFound } from '../../../../../../src/plugins/kibana_utils/public';
const fieldFormats = {
@ -116,11 +116,11 @@ describe('ObservabilityIndexPatterns', function () {
});
it('should validate field formats', async function () {
mockIndexPattern.getFormatterForField = jest.fn().mockReturnValue({ params: () => {} });
mockDataView.getFormatterForField = jest.fn().mockReturnValue({ params: () => {} });
const obsv = new ObservabilityDataViews(dataViews!);
await obsv.validateFieldFormats('ux', mockIndexPattern);
await obsv.validateFieldFormats('ux', mockDataView);
expect(dataViews?.updateSavedObject).toHaveBeenCalledTimes(1);
expect(dataViews?.updateSavedObject).toHaveBeenCalledWith(

View file

@ -134,7 +134,7 @@ export const FiltersExpressionsSelect: React.FC<FilterExpressionsSelectProps> =
<FieldValueSuggestions
filters={[]}
key={fieldName}
indexPatternTitle={indexPattern.title}
dataViewTitle={indexPattern.title}
sourceField={fieldName}
label={title}
onChange={(vals) => {

View file

@ -57,7 +57,7 @@ export const FilterGroup = () => {
<FieldValueSuggestions
key={field}
compressed={false}
indexPatternTitle={indexPattern.title}
dataViewTitle={indexPattern.title}
sourceField={field}
label={label}
selectedValue={selectedItems}

View file

@ -26,7 +26,7 @@ export const SelectedFilters = ({ onChange }: Props) => {
...selectedItems.map((value) => (
<EuiFlexItem key={field + value} grow={false}>
<FilterValueLabel
indexPattern={indexPattern}
dataView={indexPattern}
removeFilter={() => {
onChange(
field,
@ -51,7 +51,7 @@ export const SelectedFilters = ({ onChange }: Props) => {
...excludedItems.map((value) => (
<EuiFlexItem key={field + value} grow={false}>
<FilterValueLabel
indexPattern={indexPattern}
dataView={indexPattern}
removeFilter={() => {
onChange(
field,

View file

@ -110,7 +110,7 @@ function LocalUIFilters() {
<FieldValueSuggestions
key={filterName}
sourceField={uxFiltersByName[filterName].fieldName}
indexPatternTitle={dataViewTitle}
dataViewTitle={dataViewTitle}
label={uxFiltersByName[filterName].title}
asCombobox={false}
selectedValue={

View file

@ -53,7 +53,7 @@ export function SelectedFilters({
{((uxUiFilters?.[name] ?? []) as string[]).map((value) => (
<FilterItem key={name + value} grow={false}>
<FilterValueLabel
indexPattern={indexPattern}
dataView={indexPattern}
removeFilter={() => {
onChange(
name,

View file

@ -47,7 +47,7 @@ export function SelectedWildcards({ indexPattern }: Props) {
return searchTerm ? (
<FilterValueLabel
indexPattern={indexPattern}
dataView={indexPattern}
removeFilter={() => {
updateSearchTerm('');
}}