Skip to content

Commit

Permalink
[Discover] Cleanup usage of deprecated APIs (#128602)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Mar 29, 2022
1 parent eb51ea6 commit 617bb30
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { UI_SETTINGS } from '../../../data/public';
import { TopNavMenu } from '../../../navigation/public';
import { FORMATS_UI_SETTINGS } from 'src/plugins/field_formats/common';
import { LocalStorageMock } from './local_storage_mock';
import { fieldFormatsMock } from '../../../field_formats/common/mocks';
const dataPlugin = dataPluginMock.createStartContract();

export const discoverServiceMock = {
Expand All @@ -45,10 +46,7 @@ export const discoverServiceMock = {
save: true,
},
},
fieldFormats: {
getDefaultInstance: jest.fn(() => ({ convert: (value: unknown) => value })),
getFormatterForField: jest.fn(() => ({ convert: (value: unknown) => value })),
},
fieldFormats: fieldFormatsMock,
filterManager: dataPlugin.query.filterManager,
uiSettings: {
get: jest.fn((key: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* Side Public License, v 1.
*/

import { Filter } from '@kbn/es-query';
import { IUiSettingsClient } from 'kibana/public';
import { getState } from './context_state';
import { createBrowserHistory, History } from 'history';
import { FilterManager, Filter } from '../../../../../data/public';
import { FilterManager } from '../../../../../data/public';
import { coreMock } from '../../../../../../core/public/mocks';
import { SEARCH_FIELDS_FROM_SOURCE } from '../../../../common';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function DiscoverHistogram({
savedSearchData$,
timefilterUpdateHandler,
}: DiscoverHistogramProps) {
const { data, theme, uiSettings } = useDiscoverServices();
const { data, theme, uiSettings, fieldFormats } = useDiscoverServices();
const chartTheme = theme.useChartsTheme();
const chartBaseTheme = theme.useChartsBaseTheme();

Expand Down Expand Up @@ -207,7 +207,7 @@ export function DiscoverHistogram({
type: TooltipType.VerticalCursor,
};

const xAxisFormatter = data.fieldFormats.deserialize(chartData.yAxisFormat);
const xAxisFormatter = fieldFormats.deserialize(chartData.yAxisFormat);

const useLegacyTimeAxis = uiSettings.get(LEGACY_TIME_AXIS, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ function mountComponent(indexPattern: DataView, prevSidebarClosed?: boolean) {
const searchSourceMock = createSearchSourceMock({});
const services = {
...discoverServiceMock,
fieldFormats: {
getDefaultInstance: jest.fn(() => ({ convert: (value: unknown) => value })),
getFormatterForField: jest.fn(() => ({ convert: (value: unknown) => value })),
},
storage: new LocalStorageMock({
[SIDEBAR_CLOSED_KEY]: prevSidebarClosed,
}) as unknown as Storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { storiesOf } from '@storybook/react';
import React from 'react';
import { KBN_FIELD_TYPES } from '@kbn/field-types';
import { DiscoverFieldDetails } from '../discover_field_details';
import { DataView, IndexPatternField } from '../../../../../../../data_views/public';
import { DataViewField } from '../../../../../../../data_views/public';
import { DataView } from '../../../../../../../data_views/public';
import { fieldSpecMap } from './fields';
import { numericField as field } from './fields';
import { Bucket } from '../types';
Expand All @@ -36,7 +37,7 @@ const fieldFormat = {
defaultMap,
};

const scriptedField = new IndexPatternField({
const scriptedField = new DataViewField({
name: 'machine.os',
type: 'string',
esTypes: ['long'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ import { AvailableFields$ } from '../../utils/use_saved_search';

function getCompProps(): DiscoverSidebarProps {
const indexPattern = stubLogstashIndexPattern;

// @ts-expect-error _.each() is passing additional args to flattenHit
const hits = each(cloneDeep(realHits), indexPattern.flattenHit) as Array<
Record<string, unknown>
> as ElasticSearchHit[];
const hits = each(cloneDeep(realHits), (hit) =>
flattenHit(hit, indexPattern)
) as unknown as ElasticSearchHit[];

const indexPatternList = [
{ id: '0', attributes: { title: 'b' } } as SavedObject<DataViewAttributes>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ jest.mock('../../utils/calc_field_counts', () => ({
function getCompProps(): DiscoverSidebarResponsiveProps {
const indexPattern = stubLogstashIndexPattern;

// @ts-expect-error _.each() is passing additional args to flattenHit
const hits = each(cloneDeep(realHits), (hit) => flattenHit(hit, indexPattern)) as Array<
Record<string, unknown>
> as ElasticSearchHit[];
const hits = each(cloneDeep(realHits), (hit) =>
flattenHit(hit, indexPattern)
) as unknown as ElasticSearchHit[];

const indexPatternList = [
{ id: '0', attributes: { title: 'b' } } as SavedObject<DataViewAttributes>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { Subscription } from 'rxjs';
import { onlyDisabledFiltersChanged, Filter } from '@kbn/es-query';
import React from 'react';
import ReactDOM from 'react-dom';
import { i18n } from '@kbn/i18n';
Expand All @@ -18,14 +19,9 @@ import { ISearchEmbeddable, SearchInput, SearchOutput } from './types';
import { SavedSearch } from '../services/saved_searches';
import { Adapters, RequestAdapter } from '../../../inspector/common';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import {
APPLY_FILTER_TRIGGER,
esFilters,
FilterManager,
generateFilters,
} from '../../../data/public';
import { APPLY_FILTER_TRIGGER, FilterManager, generateFilters } from '../../../data/public';
import { DiscoverServices } from '../build_services';
import { Filter, ISearchSource, Query, TimeRange, FilterStateStore } from '../../../data/public';
import { ISearchSource, Query, TimeRange, FilterStateStore } from '../../../data/public';
import { DataView, DataViewField } from '../../../data_views/public';
import { SavedSearchEmbeddableComponent } from './saved_search_embeddable_component';
import { UiActionsStart } from '../../../ui_actions/public';
Expand Down Expand Up @@ -332,7 +328,7 @@ export class SavedSearchEmbeddable
{ forceFetch = false }: { forceFetch: boolean } = { forceFetch: false }
) {
const isFetchRequired =
!esFilters.onlyDisabledFiltersChanged(this.input.filters, this.prevFilters) ||
!onlyDisabledFiltersChanged(this.input.filters, this.prevFilters) ||
!isEqual(this.prevQuery, this.input.query) ||
!isEqual(this.prevTimeRange, this.input.timeRange) ||
!isEqual(searchProps.sort, this.input.sort || this.savedSearch.sort) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { monaco } from '@kbn/monaco';
import { getHeight } from './get_height';

describe('getHeight', () => {
window.innerHeight = 500;
Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 500 });

const getMonacoMock = (lineCount: number) => {
return {
getDomNode: jest.fn(() => {
Expand Down

0 comments on commit 617bb30

Please sign in to comment.