Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Timefilter service ⇒ NP #49491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ import {
createAction,
IncompatibleActionError,
} from '../../../../../../plugins/ui_actions/public';
import { FilterManager, esFilters } from '../../../../../../plugins/data/public';
import { TimefilterContract, changeTimeFilter, extractTimeFilter } from '../../timefilter';
import {
esFilters,
FilterManager,
TimefilterContract,
changeTimeFilter,
extractTimeFilter,
} from '../../../../../../plugins/data/public';
import { applyFiltersPopover } from '../apply_filters/apply_filters_popover';
import { IndexPatternsStart } from '../../index_patterns';
export const GLOBAL_APPLY_FILTER_ACTION = 'GLOBAL_APPLY_FILTER_ACTION';
Expand Down
9 changes: 0 additions & 9 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,3 @@ export {
mockFields,
mockIndexPattern,
} from './index_patterns';

export {
TimeHistoryContract,
TimefilterContract,
getTime,
InputTimeRange,
extractTimeFilter,
changeTimeFilter,
} from './timefilter';
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock';
import { queryServiceMock } from './query/query_service.mock';
import { timefilterServiceMock } from './timefilter/timefilter_service.mock';

function createDataSetupMock() {
return {
indexPatterns: indexPatternsServiceMock.createSetupContract(),
query: queryServiceMock.createSetupContract(),
timefilter: timefilterServiceMock.createSetupContract(),
};
}

Expand Down
15 changes: 1 addition & 14 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import { SearchService, SearchStart, createSearchBar, StatetfulSearchBarProps } from './search';
import { QueryService, QuerySetup } from './query';
import { TimefilterService, TimefilterSetup } from './timefilter';
import { IndexPatternsService, IndexPatternsSetup, IndexPatternsStart } from './index_patterns';
import { Storage, IStorageWrapper } from '../../../../../src/plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
Expand All @@ -44,7 +43,6 @@ export interface DataPluginStartDependencies {
*/
export interface DataSetup {
query: QuerySetup;
timefilter: TimefilterSetup;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing timefilter from the shim, shall we re-export the timefilter from the NP here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @ppisljar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the opposite approach and I've been using it in previous PR.
I've been working with other teams and promotes faster adaptation.
And it allows us to maintain less code.

indexPatterns: IndexPatternsSetup;
}

Expand All @@ -55,7 +53,6 @@ export interface DataSetup {
*/
export interface DataStart {
query: QuerySetup;
timefilter: TimefilterSetup;
indexPatterns: IndexPatternsStart;
search: SearchStart;
ui: {
Expand All @@ -79,24 +76,16 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
private readonly indexPatterns: IndexPatternsService = new IndexPatternsService();
private readonly query: QueryService = new QueryService();
private readonly search: SearchService = new SearchService();
private readonly timefilter: TimefilterService = new TimefilterService();

private setupApi!: DataSetup;
private storage!: IStorageWrapper;

public setup(core: CoreSetup): DataSetup {
const { uiSettings } = core;

this.storage = new Storage(window.localStorage);

const timefilterService = this.timefilter.setup({
uiSettings,
storage: this.storage,
});
this.setupApi = {
indexPatterns: this.indexPatterns.setup(),
query: this.query.setup(),
timefilter: timefilterService,
};

return this.setupApi;
Expand All @@ -118,14 +107,13 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
core,
data,
storage: this.storage,
timefilter: this.setupApi.timefilter,
});

uiActions.registerAction(
createFilterAction(
core.overlays,
data.query.filterManager,
this.setupApi.timefilter.timefilter,
data.query.timefilter.timefilter,
indexPatternsService
)
);
Expand All @@ -146,6 +134,5 @@ export class DataPlugin implements Plugin<DataSetup, DataStart, {}, DataPluginSt
this.indexPatterns.stop();
this.query.stop();
this.search.stop();
this.timefilter.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const mockFetchIndexPatterns = jest
.fn()
.mockReturnValue(Promise.resolve([mockIndexPattern]));

jest.mock('../../persisted_log', () => ({
jest.mock('../../../../../../../plugins/data/public/query/persisted_log', () => ({
PersistedLog: mockPersistedLogFactory,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Toast } from 'src/core/public';
import {
AutocompleteSuggestion,
AutocompleteSuggestionType,
PersistedLog,
} from '../../../../../../../plugins/data/public';
import {
withKibana,
Expand All @@ -47,7 +48,6 @@ import { Query, getQueryLog } from '../index';
import { fromUser, matchPairs, toUser } from '../lib';
import { QueryLanguageSwitcher } from './language_switcher';
import { SuggestionsComponent } from './typeahead/suggestions_component';
import { PersistedLog } from '../../persisted_log';
import { fetchIndexPatterns } from '../lib/fetch_index_patterns';
import { IDataPluginServices } from '../../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
import { I18nProvider } from '@kbn/i18n/react';
const startMock = coreMock.createStart();

import { timefilterServiceMock } from '../../../timefilter/timefilter_service.mock';
const timefilterSetupMock = timefilterServiceMock.createSetupContract();

timefilterSetupMock.history.get.mockImplementation(() => {
return [];
});
const mockTimeHistory = {
get: () => {
return [];
},
};

startMock.uiSettings.get.mockImplementation((key: string) => {
switch (key) {
Expand Down Expand Up @@ -140,7 +139,7 @@ describe('QueryBarTopRowTopRow', () => {
screenTitle: 'Another Screen',
isDirty: false,
indexPatterns: [mockIndexPattern],
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -154,7 +153,7 @@ describe('QueryBarTopRowTopRow', () => {
query: kqlQuery,
screenTitle: 'Another Screen',
indexPatterns: [mockIndexPattern],
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
disableAutoFocus: true,
isDirty: false,
})
Expand All @@ -167,7 +166,7 @@ describe('QueryBarTopRowTopRow', () => {
const component = mount(
wrapQueryBarTopRowInContext({
isDirty: false,
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -179,7 +178,7 @@ describe('QueryBarTopRowTopRow', () => {
const component = mount(
wrapQueryBarTopRowInContext({
showDatePicker: false,
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
isDirty: false,
})
);
Expand All @@ -196,7 +195,7 @@ describe('QueryBarTopRowTopRow', () => {
showDatePicker: true,
dateRangeFrom: 'now-7d',
dateRangeTo: 'now',
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -212,7 +211,7 @@ describe('QueryBarTopRowTopRow', () => {
showDatePicker: true,
dateRangeFrom: 'now-7d',
dateRangeTo: 'now',
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -232,7 +231,7 @@ describe('QueryBarTopRowTopRow', () => {
showDatePicker: false,
dateRangeFrom: 'now-7d',
dateRangeTo: 'now',
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -249,7 +248,7 @@ describe('QueryBarTopRowTopRow', () => {
indexPatterns: [mockIndexPattern],
showQueryInput: false,
showDatePicker: false,
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand All @@ -263,7 +262,7 @@ describe('QueryBarTopRowTopRow', () => {
isDirty: false,
screenTitle: 'Another Screen',
showDatePicker: false,
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ import {
import { EuiSuperUpdateButton, OnRefreshProps } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { Toast } from 'src/core/public';
import { TimeRange } from 'src/plugins/data/public';
import { TimeRange, TimeHistoryContract } from 'src/plugins/data/public';
import { useKibana } from '../../../../../../../plugins/kibana_react/public';
import { PersistedLog } from '../../../../../../../plugins/data/public';

import { IndexPattern } from '../../../index_patterns';
import { QueryBarInput } from './query_bar_input';
import { Query, getQueryLog } from '../index';
import { TimeHistoryContract } from '../../../timefilter';
import { IDataPluginServices } from '../../../types';
import { PersistedLog } from '../../persisted_log';

interface Props {
query?: Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { UiSettingsClientContract } from 'src/core/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { PersistedLog } from '../../persisted_log';
import { PersistedLog } from '../../../../../../../plugins/data/public';

export function getQueryLog(
uiSettings: UiSettingsClientContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { CoreStart } from 'src/core/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public';
import { TimefilterSetup } from '../../../timefilter';
import { SearchBar } from '../../../';
import { SearchBarOwnProps } from '.';
import { esFilters } from '../../../../../../../plugins/data/public';
Expand All @@ -32,7 +31,6 @@ interface StatefulSearchBarDeps {
core: CoreStart;
data: DataPublicPluginStart;
storage: IStorageWrapper;
timefilter: TimefilterSetup;
}

export type StatetfulSearchBarProps = SearchBarOwnProps & {
Expand All @@ -45,20 +43,21 @@ const defaultFiltersUpdated = (data: DataPublicPluginStart) => {
};
};

const defaultOnRefreshChange = (timefilter: TimefilterSetup) => {
const defaultOnRefreshChange = (data: DataPublicPluginStart) => {
const { timefilter } = data.query.timefilter;
return (options: { isPaused: boolean; refreshInterval: number }) => {
timefilter.timefilter.setRefreshInterval({
timefilter.setRefreshInterval({
value: options.refreshInterval,
pause: options.isPaused,
});
};
};

export function createSearchBar({ core, storage, timefilter, data }: StatefulSearchBarDeps) {
export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps) {
// App name should come from the core application service.
// Until it's available, we'll ask the user to provide it for the pre-wired component.
return (props: StatetfulSearchBarProps) => {
const { filterManager } = data.query;
const { filterManager, timefilter } = data.query;
const tfRefreshInterval = timefilter.timefilter.getRefreshInterval();
const fmFilters = filterManager.getFilters();
const [refreshInterval, setRefreshInterval] = useState(tfRefreshInterval.value);
Expand Down Expand Up @@ -119,7 +118,7 @@ export function createSearchBar({ core, storage, timefilter, data }: StatefulSea
isRefreshPaused={refreshPaused}
filters={filters}
onFiltersUpdated={defaultFiltersUpdated(data)}
onRefreshChange={defaultOnRefreshChange(timefilter)}
onRefreshChange={defaultOnRefreshChange(data)}
{...props}
/>
</KibanaContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ import { I18nProvider } from '@kbn/i18n/react';
import { coreMock } from '../../../../../../../../src/core/public/mocks';
const startMock = coreMock.createStart();

import { timefilterServiceMock } from '../../../timefilter/timefilter_service.mock';
import { mount } from 'enzyme';
const timefilterSetupMock = timefilterServiceMock.createSetupContract();

const mockTimeHistory = {
get: () => {
return [];
},
};

jest.mock('../../../../../data/public', () => {
return {
Expand Down Expand Up @@ -86,7 +90,7 @@ const kqlQuery = {
function wrapSearchBarInContext(testProps: any) {
const defaultOptions = {
appName: 'test',
timeHistory: timefilterSetupMock.history,
timeHistory: mockTimeHistory,
intl: null as any,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import ResizeObserver from 'resize-observer-polyfill';
import { get, isEqual } from 'lodash';

import { TimeRange } from 'src/plugins/data/common/types';
import { TimeHistoryContract } from 'src/plugins/data/public';
import { IndexPattern, Query, FilterBar } from '../../../../../data/public';
import { QueryBarTopRow } from '../../../query';
import { SavedQuery, SavedQueryAttributes } from '../index';
import { SavedQueryMeta, SaveQueryForm } from './saved_query_management/save_query_form';
import { SavedQueryManagementComponent } from './saved_query_management/saved_query_management_component';
import { SavedQueryService } from '../lib/saved_query_service';
import { createSavedQueryService } from '../lib/saved_query_service';
import { TimeHistoryContract } from '../../../timefilter';
import {
withKibana,
KibanaReactContextValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { capabilities } from 'ui/capabilities';
import { Subscription } from 'rxjs';
import { npStart } from 'ui/new_platform';
import { SavedObjectFinder } from 'ui/saved_objects/components/saved_object_finder';
import { extractTimeFilter, changeTimeFilter } from '../../../data/public';
import { extractTimeFilter, changeTimeFilter } from '../../../../../plugins/data/public';
import { start as data } from '../../../data/public/legacy';
import { esFilters } from '../../../../../plugins/data/public';

Expand Down
Loading