Skip to content

Commit

Permalink
Migrate /data/common to /data/public
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Mar 9, 2022
1 parent 79a0b96 commit 933becd
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';
import { findTestSubject } from '@elastic/eui/lib/test';
import { ActionBar } from './components/action_bar/action_bar';
import { GetStateReturn } from './services/context_state';
import { SortDirection } from 'src/plugins/data/common';
import { SortDirection } from 'src/plugins/data/public';
import { ContextAppContent, ContextAppContentProps } from './context_app_content';
import { LoadingStatus } from './services/context_query_state';
import { indexPatternMock } from '../../__mocks__/index_pattern';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { EuiHorizontalRule, EuiText } from '@elastic/eui';
import { CONTEXT_STEP_SETTING, DOC_HIDE_TIME_COLUMN_SETTING } from '../../../common';
import type { DataView } from '../../../../data_views/public';
import { SortDirection } from '../../../../data/common';
import { SortDirection } from '../../../../data/public';
import { LoadingStatus } from './services/context_query_state';
import { ActionBar } from './components/action_bar/action_bar';
import { DiscoverGrid } from '../../components/discover_grid/discover_grid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { DataView } from '../../../../../data_views/public';
import { SortDirection } from '../../../../../data/common';
import { SortDirection } from '../../../../../data/public';
import { createSearchSourceStub } from './_stubs';
import { fetchAnchor, updateSearchSource } from './anchor';
import { indexPatternMock } from '../../../__mocks__/index_pattern';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import moment from 'moment';
import { get, last } from 'lodash';
import type { DataView } from 'src/plugins/data_views/public';
import { SortDirection } from 'src/plugins/data/common';
import { SortDirection } from 'src/plugins/data/public';
import { createContextSearchSourceStub } from './_stubs';
import { fetchSurroundingDocs, SurrDocType } from './context';
import { DataPublicPluginStart, Query } from '../../../../../data/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import moment from 'moment';
import { get, last } from 'lodash';
import { SortDirection } from 'src/plugins/data/common';
import { SortDirection } from 'src/plugins/data/public';
import type { DataView } from 'src/plugins/data_views/public';
import { createContextSearchSourceStub } from './_stubs';
import { DataPublicPluginStart, Query } from '../../../../../data/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import type { EsQuerySortValue, SortDirection } from 'src/plugins/data/common';
import type { EsQuerySortValue, SortDirection } from 'src/plugins/data/public';

/**
* Returns `EsQuerySort` which is used to sort records in the ES query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fetchAnchor } from '../services/anchor';
import { fetchSurroundingDocs, SurrDocType } from '../services/context';
import { MarkdownSimple, toMountPoint, wrapWithTheme } from '../../../../../kibana_react/public';
import type { DataView } from '../../../../../data_views/public';
import { SortDirection } from '../../../../../data/common';
import { SortDirection } from '../../../../../data/public';
import {
ContextFetchState,
FailureReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
import type { Filter } from '@kbn/es-query';
import { METRIC_TYPE, UiCounterMetricType } from '@kbn/analytics';
import { useDiscoverServices } from '../../../../utils/use_discover_services';
import type { Query } from '../../../../../../data/common';
import type { Query } from '../../../../../../data/public';
import type { DataViewField, DataView } from '../../../../../../data_views/public';
import {
EmbeddableInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import type { Query, SavedObject, TimeRange } from '../../../../../../data/common';
import type { SavedObject } from '../../../../../../data/common';
import type { Query, TimeRange } from '../../../../../../data/public';
import type { DataViewAttributes } from '../../../../../../data_views/common';
import type { DataView } from '../../../../../../data_views/public';
import { ISearchSource } from '../../../../../../data/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';

import { DiscoverField } from './discover_field';
import { DataViewField } from '../../../../../../data_views/public';
import { stubIndexPattern } from '../../../../../../data/common/stubs';
import { KibanaContextProvider } from '../../../../../../kibana_react/public';
import { stubDataView } from '../../../../../../data_views/common/data_view.stub';

jest.mock('../../../../kibana_services', () => ({
getUiActions: jest.fn(() => {
Expand Down Expand Up @@ -46,7 +46,7 @@ function getComponent({
});

const props = {
indexPattern: stubIndexPattern,
indexPattern: stubDataView,
field: finalField,
getDetails: jest.fn(() => ({ buckets: [], error: '', exists: 1, total: 2, columns: [] })),
onAddFilter: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';

import { DiscoverFieldDetails } from './discover_field_details';
import { DataViewField } from '../../../../../../data_views/public';
import { stubIndexPattern } from '../../../../../../data/common/stubs';
import { stubDataView } from '../../../../../../data_views/common/data_view.stub';

describe('discover sidebar field details', function () {
const onAddFilter = jest.fn();
const defaultProps = {
indexPattern: stubIndexPattern,
indexPattern: stubDataView,
details: { buckets: [], error: '', exists: 1, total: 2, columns: [] },
onAddFilter,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useHistory } from 'react-router-dom';
import { useDiscoverServices } from '../../../../utils/use_discover_services';
import { DiscoverLayoutProps } from '../layout/types';
import { getTopNavLinks } from './get_top_nav_links';
import { Query, TimeRange } from '../../../../../../data/common/query';
import { Query, TimeRange } from '../../../../../../data/public';
import { getHeaderActionMenuMounter } from '../../../../kibana_services';
import { GetStateReturn } from '../../services/discover_state';
import { DataViewType } from '../../../../../../data_views/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/
import React, { useEffect, useState, memo, useCallback } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import { SavedObject } from 'src/plugins/data/common';
import { ISearchSource } from 'src/plugins/data/public';
import {
DataViewAttributes,
DataViewSavedObjectConflictError,
} from 'src/plugins/data_views/common';
import { ISearchSource, SavedObject } from 'src/plugins/data/common';
} from '../../../../data_views/common';
import {
SavedSearch,
getSavedSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

import { getDefaultSort } from './get_default_sort';
import {
stubIndexPattern,
stubIndexPatternWithoutTimeField,
} from '../../../../../data/common/stubs';
stubDataView,
stubDataViewWithoutTimeField,
} from '../../../../../data_views/common/data_view.stub';

describe('getDefaultSort function', function () {
test('should be a function', function () {
expect(typeof getDefaultSort === 'function').toBeTruthy();
});

test('should return default sort for an index pattern with timeFieldName', function () {
expect(getDefaultSort(stubIndexPattern, 'desc')).toEqual([['@timestamp', 'desc']]);
expect(getDefaultSort(stubIndexPattern, 'asc')).toEqual([['@timestamp', 'asc']]);
expect(getDefaultSort(stubDataView, 'desc')).toEqual([['@timestamp', 'desc']]);
expect(getDefaultSort(stubDataViewWithoutTimeField, 'asc')).toEqual([['@timestamp', 'asc']]);
});

test('should return default sort for an index pattern without timeFieldName', function () {
expect(getDefaultSort(stubIndexPatternWithoutTimeField, 'desc')).toEqual([]);
expect(getDefaultSort(stubIndexPatternWithoutTimeField, 'asc')).toEqual([]);
expect(getDefaultSort(stubDataViewWithoutTimeField, 'desc')).toEqual([]);
expect(getDefaultSort(stubDataViewWithoutTimeField, 'asc')).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import { getSort, getSortArray } from './get_sort';
import {
stubIndexPattern,
stubIndexPatternWithoutTimeField,
} from '../../../../../data/common/stubs';
stubDataView,
stubDataViewWithoutTimeField,
} from '../../../../../data_views/common/data_view.stub';

describe('docTable', function () {
describe('getSort function', function () {
Expand All @@ -19,32 +19,32 @@ describe('docTable', function () {
});

test('should return an array of objects', function () {
expect(getSort([['bytes', 'desc']], stubIndexPattern)).toEqual([{ bytes: 'desc' }]);
expect(getSort([['bytes', 'desc']], stubIndexPatternWithoutTimeField)).toEqual([
expect(getSort([['bytes', 'desc']], stubDataView)).toEqual([{ bytes: 'desc' }]);
expect(getSort([['bytes', 'desc']], stubDataViewWithoutTimeField)).toEqual([
{ bytes: 'desc' },
]);
});

test('should passthrough arrays of objects', () => {
expect(getSort([{ bytes: 'desc' }], stubIndexPattern)).toEqual([{ bytes: 'desc' }]);
expect(getSort([{ bytes: 'desc' }], stubDataView)).toEqual([{ bytes: 'desc' }]);
});

test('should return an empty array when passed an unsortable field', function () {
expect(getSort([['non-sortable', 'asc']], stubIndexPattern)).toEqual([]);
expect(getSort([['lol_nope', 'asc']], stubIndexPattern)).toEqual([]);
expect(getSort([['non-sortable', 'asc']], stubDataView)).toEqual([]);
expect(getSort([['lol_nope', 'asc']], stubDataView)).toEqual([]);

expect(getSort([['non-sortable', 'asc']], stubIndexPatternWithoutTimeField)).toEqual([]);
expect(getSort([['non-sortable', 'asc']], stubDataViewWithoutTimeField)).toEqual([]);
});

test('should return an empty array ', function () {
expect(getSort([], stubIndexPattern)).toEqual([]);
expect(getSort([['foo', 'bar']], stubIndexPattern)).toEqual([]);
expect(getSort([{ foo: 'bar' }], stubIndexPattern)).toEqual([]);
expect(getSort([], stubDataView)).toEqual([]);
expect(getSort([['foo', 'bar']], stubDataView)).toEqual([]);
expect(getSort([{ foo: 'bar' }], stubDataView)).toEqual([]);
});

test('should convert a legacy sort to an array of objects', function () {
expect(getSort(['foo', 'desc'], stubIndexPattern)).toEqual([{ foo: 'desc' }]);
expect(getSort(['foo', 'asc'], stubIndexPattern)).toEqual([{ foo: 'asc' }]);
expect(getSort(['foo', 'desc'], stubDataView)).toEqual([{ foo: 'desc' }]);
expect(getSort(['foo', 'asc'], stubDataView)).toEqual([{ foo: 'asc' }]);
});
});

Expand All @@ -54,26 +54,24 @@ describe('docTable', function () {
});

test('should return an array of arrays for sortable fields', function () {
expect(getSortArray([['bytes', 'desc']], stubIndexPattern)).toEqual([['bytes', 'desc']]);
expect(getSortArray([['bytes', 'desc']], stubDataView)).toEqual([['bytes', 'desc']]);
});

test('should return an array of arrays from an array of elasticsearch sort objects', function () {
expect(getSortArray([{ bytes: 'desc' }], stubIndexPattern)).toEqual([['bytes', 'desc']]);
expect(getSortArray([{ bytes: 'desc' }], stubDataView)).toEqual([['bytes', 'desc']]);
});

test('should sort by an empty array when an unsortable field is given', function () {
expect(getSortArray([{ 'non-sortable': 'asc' }], stubIndexPattern)).toEqual([]);
expect(getSortArray([{ lol_nope: 'asc' }], stubIndexPattern)).toEqual([]);
expect(getSortArray([{ 'non-sortable': 'asc' }], stubDataView)).toEqual([]);
expect(getSortArray([{ lol_nope: 'asc' }], stubDataView)).toEqual([]);

expect(getSortArray([{ 'non-sortable': 'asc' }], stubIndexPatternWithoutTimeField)).toEqual(
[]
);
expect(getSortArray([{ 'non-sortable': 'asc' }], stubDataViewWithoutTimeField)).toEqual([]);
});

test('should return an empty array when passed an empty sort array', () => {
expect(getSortArray([], stubIndexPattern)).toEqual([]);
expect(getSortArray([], stubDataView)).toEqual([]);

expect(getSortArray([], stubIndexPatternWithoutTimeField)).toEqual([]);
expect(getSortArray([], stubDataViewWithoutTimeField)).toEqual([]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

import { getSortForSearchSource } from './get_sort_for_search_source';
import { SortOrder } from '../components/table_header/helpers';
import {
stubIndexPattern,
stubIndexPatternWithoutTimeField,
} from '../../../../../data/common/stubs';
import { stubDataView, stubDataViewWithoutTimeField } from '../../../../../data/common/stubs';

describe('getSortForSearchSource function', function () {
test('should be a function', function () {
Expand All @@ -20,26 +17,24 @@ describe('getSortForSearchSource function', function () {

test('should return an object to use for searchSource when columns are given', function () {
const cols = [['bytes', 'desc']] as SortOrder[];
expect(getSortForSearchSource(cols, stubIndexPattern)).toEqual([{ bytes: 'desc' }]);
expect(getSortForSearchSource(cols, stubIndexPattern, 'asc')).toEqual([{ bytes: 'desc' }]);
expect(getSortForSearchSource(cols, stubDataView)).toEqual([{ bytes: 'desc' }]);
expect(getSortForSearchSource(cols, stubDataView, 'asc')).toEqual([{ bytes: 'desc' }]);

expect(getSortForSearchSource(cols, stubIndexPatternWithoutTimeField)).toEqual([
{ bytes: 'desc' },
]);
expect(getSortForSearchSource(cols, stubIndexPatternWithoutTimeField, 'asc')).toEqual([
expect(getSortForSearchSource(cols, stubDataViewWithoutTimeField)).toEqual([{ bytes: 'desc' }]);
expect(getSortForSearchSource(cols, stubDataViewWithoutTimeField, 'asc')).toEqual([
{ bytes: 'desc' },
]);
});

test('should return an object to use for searchSource when no columns are given', function () {
const cols = [] as SortOrder[];
expect(getSortForSearchSource(cols, stubIndexPattern)).toEqual([{ _doc: 'desc' }]);
expect(getSortForSearchSource(cols, stubIndexPattern, 'asc')).toEqual([{ _doc: 'asc' }]);
expect(getSortForSearchSource(cols, stubDataView)).toEqual([{ _doc: 'desc' }]);
expect(getSortForSearchSource(cols, stubDataView, 'asc')).toEqual([{ _doc: 'asc' }]);

expect(getSortForSearchSource(cols, stubIndexPatternWithoutTimeField)).toEqual([
expect(getSortForSearchSource(cols, stubDataViewWithoutTimeField)).toEqual([
{ _score: 'desc' },
]);
expect(getSortForSearchSource(cols, stubIndexPatternWithoutTimeField, 'asc')).toEqual([
expect(getSortForSearchSource(cols, stubDataViewWithoutTimeField, 'asc')).toEqual([
{ _score: 'asc' },
]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'src/plugins/embeddable/public';
import type { Filter } from '@kbn/es-query';
import { DataView } from '../../../data_views/public';
import { TimeRange, Query } from '../../../data/common';
import type { TimeRange, Query } from '../../../data/public';
import { SavedSearch } from '../services/saved_searches';
import { SortOrder } from '../components/doc_table/components/table_header/helpers';

Expand Down

0 comments on commit 933becd

Please sign in to comment.