Skip to content

Commit

Permalink
[Discover] Migrate indexPattern to dataView based naming (#132012)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Jul 28, 2022
1 parent f93dd21 commit bcbef78
Show file tree
Hide file tree
Showing 167 changed files with 1,299 additions and 1,346 deletions.
4 changes: 0 additions & 4 deletions src/plugins/data_views/common/data_view.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export const stubDataViewWithoutTimeField = createStubDataView({
},
});

export const stubIndexPatternWithoutTimeField = stubDataViewWithoutTimeField;

export const stubLogstashDataView = createStubDataView({
spec: {
id: 'logstash-*',
Expand All @@ -45,8 +43,6 @@ export const stubLogstashDataView = createStubDataView({
},
});

export const stubLogstashIndexPattern = stubLogstashDataView;

export function stubbedSavedObjectDataView(
id: string | null = null
): SavedObject<DataViewAttributes> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { DataView } from '@kbn/data-views-plugin/common';

export function getIndexPatternMock(isTimebased = true) {
export function getDataViewMock(isTimebased = true) {
const fields = [
{
name: '_index',
Expand Down Expand Up @@ -73,7 +73,7 @@ export function getIndexPatternMock(isTimebased = true) {
aggregatable: true,
},
] as DataView['fields'];
const indexPatternMock = {
const dataViewMock = {
isTimeBased: () => isTimebased,
getName: () => 'test',
fields,
Expand All @@ -87,7 +87,7 @@ export function getIndexPatternMock(isTimebased = true) {
timeFieldName: isTimebased ? 'date' : undefined,
} as unknown as DataView;

indexPatternMock.fields.getByName = () => fields[0];
indexPatternMock.fields.getAll = () => fields;
return indexPatternMock;
dataViewMock.fields.getByName = () => fields[0];
dataViewMock.fields.getAll = () => fields;
return dataViewMock;
}
2 changes: 1 addition & 1 deletion src/plugins/discover/public/__mocks__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SORT_DEFAULT_ORDER_SETTING } from '../../common';
export const configMock = {
get: (key: string) => {
if (key === 'defaultIndex') {
return 'the-index-pattern-id';
return 'the-data-view-id';
} else if (key === SORT_DEFAULT_ORDER_SETTING) {
return 'desc';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ export const buildDataViewMock = ({
return dataView;
};

export const indexPatternMock = buildDataViewMock({ name: 'the-index-pattern', fields });
export const dataViewMock = buildDataViewMock({ name: 'the-data-view', fields });
2 changes: 1 addition & 1 deletion src/plugins/discover/public/__mocks__/data_view_complex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { DataView } from '@kbn/data-views-plugin/public';
import { buildDataViewMock } from './index_pattern';
import { buildDataViewMock } from './data_view';

const fields = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { DataView } from '@kbn/data-views-plugin/public';
import { buildDataViewMock } from './index_pattern';
import { buildDataViewMock } from './data_view';

const fields = [
{
Expand Down Expand Up @@ -52,7 +52,7 @@ const fields = [
},
] as DataView['fields'];

export const indexPatternWithTimefieldMock = buildDataViewMock({
export const dataViewWithTimefieldMock = buildDataViewMock({
name: 'index-pattern-with-timefield',
fields,
timeFieldName: 'timestamp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
*/

import { DataViewsContract } from '@kbn/data-views-plugin/public';
import { indexPatternMock } from './index_pattern';
import { dataViewMock } from './data_view';

export const indexPatternsMock = {
export const dataViewsMock = {
getCache: async () => {
return [indexPatternMock];
return [dataViewMock];
},
get: async (id: string) => {
if (id === 'the-index-pattern-id') {
return Promise.resolve(indexPatternMock);
} else if (id === 'invalid-index-pattern-id') {
if (id === 'the-data-view-id') {
return Promise.resolve(dataViewMock);
} else if (id === 'invalid-data-view-id') {
return Promise.reject('Invald');
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/discover/public/__mocks__/grid_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { DataView } from '@kbn/data-views-plugin/public';
import { indexPatternMock } from './index_pattern';
import { dataViewMock } from './data_view';
import { dataViewComplexMock } from './data_view_complex';
import { esHits } from './es_hits';
import { esHitsComplex } from './es_hits_complex';
Expand All @@ -27,7 +27,7 @@ const buildGridContext = (dataView: DataView, rows: EsHitRecord[]): GridContext
setExpanded: jest.fn(),
rows: usedRows,
onFilter: jest.fn(),
indexPattern: dataView,
dataView,
isDarkMode: false,
selectedDocs: [],
setSelectedDocs: jest.fn(),
Expand All @@ -43,6 +43,6 @@ const buildGridContext = (dataView: DataView, rows: EsHitRecord[]): GridContext
};
};

export const discoverGridContextMock = buildGridContext(indexPatternMock, esHits);
export const discoverGridContextMock = buildGridContext(dataViewMock, esHits);

export const discoverGridContextComplexMock = buildGridContext(dataViewComplexMock, esHitsComplex);
8 changes: 4 additions & 4 deletions src/plugins/discover/public/__mocks__/saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import { SavedSearch } from '../services/saved_searches';
import { createSearchSourceMock } from '@kbn/data-plugin/public/mocks';
import { indexPatternMock } from './index_pattern';
import { indexPatternWithTimefieldMock } from './index_pattern_with_timefield';
import { dataViewMock } from './data_view';
import { dataViewWithTimefieldMock } from './data_view_with_timefield';

export const savedSearchMock = {
id: 'the-saved-search-id',
searchSource: createSearchSourceMock({ index: indexPatternMock }),
searchSource: createSearchSourceMock({ index: dataViewMock }),
} as unknown as SavedSearch;

export const savedSearchMockWithTimeField = {
id: 'the-saved-search-id-with-timefield',
searchSource: createSearchSourceMock({ index: indexPatternWithTimefieldMock }),
searchSource: createSearchSourceMock({ index: dataViewWithTimefieldMock }),
} as unknown as SavedSearch;
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,65 @@
* Side Public License, v 1.
*/

import { indexPatternMock } from '../../../__mocks__/index_pattern';
import { dataViewMock } from '../../../__mocks__/data_view';
import { buildDataTableRecord } from '../../../utils/build_data_record';

export const mockAnchorHit = buildDataTableRecord(
{
_id: '123',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T18:52:17.000Z'] },
sort: [1623091937000, 2092],
_version: 1,
},
indexPatternMock,
dataViewMock,
true
);

export const mockPredecessorHits = [
{
_id: '1',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T19:14:29.000Z'] },
sort: ['2021-06-07T19:14:29.000Z', 2092],
_version: 1,
},
{
_id: '2',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T19:14:12.000Z'] },
sort: ['2021-06-07T19:14:12.000Z', 2431],
_version: 1,
},
{
_id: '3',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T19:10:22.000Z'] },
sort: ['2021-06-07T19:10:22.000Z', 2435],
_version: 1,
},
].map((entry) => buildDataTableRecord(entry, indexPatternMock));
].map((entry) => buildDataTableRecord(entry, dataViewMock));

export const mockSuccessorHits = [
{
_id: '11',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T18:49:39.000Z'] },
sort: ['2021-06-07T18:49:39.000Z', 2382],
_version: 1,
},
{
_id: '22',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T18:48:28.000Z'] },
sort: ['2021-06-07T18:48:28.000Z', 2631],
_version: 1,
},
{
_id: '33',
_index: 'the-index-pattern-id',
_index: 'the-data-view-id',
fields: { order_date: ['2021-06-07T18:47:16.000Z'] },
sort: ['2021-06-07T18:47:16.000Z', 2437],
_version: 1,
},
].map((entry) => buildDataTableRecord(entry, indexPatternMock));
].map((entry) => buildDataTableRecord(entry, dataViewMock));
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';
import { createFilterManagerMock } from '@kbn/data-plugin/public/query/filter_manager/filter_manager.mock';
import { mockTopNavMenu } from './__mocks__/top_nav_menu';
import { ContextAppContent } from './context_app_content';
import { indexPatternMock } from '../../__mocks__/index_pattern';
import { dataViewMock } from '../../__mocks__/data_view';
import { ContextApp } from './context_app';
import { DiscoverServices } from '../../build_services';
import { indexPatternsMock } from '../../__mocks__/index_patterns';
import { dataViewsMock } from '../../__mocks__/data_views';
import { act } from 'react-dom/test-utils';
import { uiSettingsMock } from '../../__mocks__/ui_settings';
import { themeServiceMock } from '@kbn/core/public/mocks';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('ContextApp test', () => {
save: true,
},
},
indexPatterns: indexPatternsMock,
dataViews: dataViewsMock,
toastNotifications: { addDanger: () => {} },
navigation: mockNavigationPlugin,
core: {
Expand All @@ -67,7 +67,7 @@ describe('ContextApp test', () => {
} as unknown as DiscoverServices;

const defaultProps = {
indexPattern: indexPatternMock,
dataView: dataViewMock,
anchorId: 'mocked_anchor_id',
};

Expand All @@ -79,7 +79,7 @@ describe('ContextApp test', () => {
showFilterBar: true,
showSaveQuery: false,
showDatePicker: false,
indexPatterns: [indexPatternMock],
indexPatterns: [dataViewMock],
useDefaultBehaviors: true,
};

Expand Down Expand Up @@ -116,11 +116,11 @@ describe('ContextApp test', () => {
expect(mockFilterManager.addFilters.mock.calls[0][0]).toEqual([
{
$state: { store: 'appState' },
meta: { alias: null, disabled: false, index: 'the-index-pattern-id', negate: false },
meta: { alias: null, disabled: false, index: 'the-data-view-id', negate: false },
query: { match_phrase: { message: '2021-06-08T07:52:19.000Z' } },
},
]);
expect(indexPatternsMock.updateSavedObject.mock.calls.length).toBe(1);
expect(indexPatternsMock.updateSavedObject.mock.calls[0]).toEqual([indexPatternMock, 0, true]);
expect(dataViewsMock.updateSavedObject.mock.calls.length).toBe(1);
expect(dataViewsMock.updateSavedObject.mock.calls[0]).toEqual([dataViewMock, 0, true]);
});
});
26 changes: 13 additions & 13 deletions src/plugins/discover/public/application/context/context_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ import { useDiscoverServices } from '../../hooks/use_discover_services';
const ContextAppContentMemoized = memo(ContextAppContent);

export interface ContextAppProps {
indexPattern: DataView;
dataView: DataView;
anchorId: string;
}

export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
export const ContextApp = ({ dataView, anchorId }: ContextAppProps) => {
const services = useDiscoverServices();
const { uiSettings, capabilities, indexPatterns, navigation, filterManager, core } = services;
const { uiSettings, capabilities, dataViews, navigation, filterManager, core } = services;

const isLegacy = useMemo(() => uiSettings.get(DOC_TABLE_LEGACY), [uiSettings]);
const useNewFieldsApi = useMemo(() => !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE), [uiSettings]);

useExecutionContext(core.executionContext, {
type: 'application',
page: 'context',
id: indexPattern.id || '',
id: dataView.id || '',
});

/**
Expand All @@ -62,7 +62,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
const { fetchedState, fetchContextRows, fetchAllRows, fetchSurroundingRows, resetFetchedState } =
useContextAppFetch({
anchorId,
indexPattern,
dataView,
appState,
useNewFieldsApi,
});
Expand Down Expand Up @@ -108,8 +108,8 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
const { columns, onAddColumn, onRemoveColumn, onSetColumns } = useColumns({
capabilities,
config: uiSettings,
indexPattern,
indexPatterns,
dataView,
dataViews,
state: appState,
useNewFieldsApi,
setAppState,
Expand All @@ -125,14 +125,14 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {

const addFilter = useCallback(
async (field: DataViewField | string, values: unknown, operation: string) => {
const newFilters = generateFilters(filterManager, field, values, operation, indexPattern);
const newFilters = generateFilters(filterManager, field, values, operation, dataView);
filterManager.addFilters(newFilters);
if (indexPatterns) {
if (dataViews) {
const fieldName = typeof field === 'string' ? field : field.name;
await popularizeField(indexPattern, fieldName, indexPatterns, capabilities);
await popularizeField(dataView, fieldName, dataViews, capabilities);
}
},
[filterManager, indexPatterns, indexPattern, capabilities]
[filterManager, dataViews, dataView, capabilities]
);

const TopNavMenu = navigation.ui.AggregateQueryTopNavMenu;
Expand All @@ -145,7 +145,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
showFilterBar: true,
showSaveQuery: false,
showDatePicker: false,
indexPatterns: [indexPattern],
indexPatterns: [dataView],
useDefaultBehaviors: true,
};
};
Expand Down Expand Up @@ -188,7 +188,7 @@ export const ContextApp = ({ indexPattern, anchorId }: ContextAppProps) => {
</EuiText>
<EuiSpacer size="s" />
<ContextAppContentMemoized
indexPattern={indexPattern}
dataView={dataView}
useNewFieldsApi={useNewFieldsApi}
isLegacy={isLegacy}
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { GetStateReturn } from './services/context_state';
import { SortDirection } from '@kbn/data-plugin/public';
import { ContextAppContent, ContextAppContentProps } from './context_app_content';
import { LoadingStatus } from './services/context_query_state';
import { indexPatternMock } from '../../__mocks__/index_pattern';
import { dataViewMock } from '../../__mocks__/data_view';
import { DiscoverGrid } from '../../components/discover_grid/discover_grid';
import { discoverServiceMock } from '../../__mocks__/services';
import { DocTableWrapper } from '../../components/doc_table/doc_table_wrapper';
Expand Down Expand Up @@ -51,12 +51,12 @@ describe('ContextAppContent test', () => {
};
const props = {
columns: ['order_date', '_source'],
indexPattern: indexPatternMock,
dataView: dataViewMock,
stateContainer: {} as unknown as GetStateReturn,
anchorStatus: anchorStatus || LoadingStatus.LOADED,
predecessorsStatus: LoadingStatus.LOADED,
successorsStatus: LoadingStatus.LOADED,
rows: [buildDataTableRecord(hit, indexPatternMock)],
rows: [buildDataTableRecord(hit, dataViewMock)],
predecessors: [],
successors: [],
defaultStepSize: 5,
Expand Down
Loading

0 comments on commit bcbef78

Please sign in to comment.