Skip to content

Commit

Permalink
[Discover] Split saved searches out of discover plugin (elastic#138388)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored and Mpdreamz committed Sep 6, 2022
1 parent dc19874 commit f10c626
Show file tree
Hide file tree
Showing 74 changed files with 217 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ module.exports = {
* Discover overrides
*/
{
files: ['src/plugins/discover/**/*.{ts,tsx}'],
files: ['src/plugins/discover/**/*.{ts,tsx}', 'src/plugins/saved_search/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/ban-ts-comment': [
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Data Discovery
/src/plugins/discover/ @elastic/kibana-data-discovery
/src/plugins/saved_search/ @elastic/kibana-data-discovery
/x-pack/plugins/discover_enhanced/ @elastic/kibana-data-discovery
/test/functional/apps/discover/ @elastic/kibana-data-discovery
/x-pack/plugins/graph/ @elastic/kibana-data-discovery
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dataViews": "src/plugins/data_views",
"devTools": "src/plugins/dev_tools",
"discover": "src/plugins/discover",
"savedSearch": "src/plugins/saved_search",
"embeddableApi": "src/plugins/embeddable",
"embeddableExamples": "examples/embeddable_examples",
"esQuery": "packages/kbn-es-query/src",
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ Content is fetched from the remote (https://feeds.elastic.co) once a day, with p
oss plugins.
|{kib-repo}blob/{branch}/src/plugins/saved_search/README.md[savedSearch]
|Contains the saved search saved object definition and helpers.
|{kib-repo}blob/{branch}/src/plugins/screenshot_mode/README.md[screenshotMode]
|The service exposed by this plugin informs consumers whether they should optimize for non-interactivity. In this way plugins can avoid loading unnecessary code, data or other services.
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pageLoadAssetSize:
controls: 40000
expressionPartitionVis: 26338
sharedUX: 16225
savedSearch: 16225
ux: 20784
sessionView: 77750
cloudSecurityPosture: 19109
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"expressions"
],
"optionalPlugins": ["home", "share", "usageCollection", "spaces", "triggersActionsUi"],
"requiredBundles": ["kibanaUtils", "kibanaReact", "dataViews", "unifiedSearch"],
"requiredBundles": ["kibanaUtils", "kibanaReact", "dataViews", "unifiedSearch", "savedSearch"],
"extraPublicDirs": ["common"],
"owner": {
"name": "Data Discovery",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/discover/public/__mocks__/saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { SavedSearch } from '../services/saved_searches';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { createSearchSourceMock } from '@kbn/data-plugin/public/mocks';
import { dataViewMock } from './data_view';
import { dataViewWithTimefieldMock } from './data_view_with_timefield';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { HitsCounter } from '../hits_counter';
import { SavedSearch } from '../../../../services/saved_searches';
import { GetStateReturn } from '../../services/discover_state';
import { DiscoverHistogram } from './histogram';
import { DataCharts$, DataTotalHits$ } from '../../hooks/use_saved_search';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
IEmbeddable,
isErrorEmbeddable,
} from '@kbn/embeddable-plugin/public';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { useDiscoverServices } from '../../../../hooks/use_discover_services';
import { FIELD_STATISTICS_LOADED } from './constants';
import type { SavedSearch } from '../../../../services/saved_searches';
import type { GetStateReturn } from '../../services/discover_state';
import { AvailableFields$, DataRefetch$ } from '../../hooks/use_saved_search';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { useDiscoverServices } from '../../../../hooks/use_discover_services';
import { DocViewFilterFn } from '../../../../services/doc_views/doc_views_types';
import { DiscoverGrid } from '../../../../components/discover_grid/discover_grid';
Expand All @@ -27,7 +28,6 @@ import {
HIDE_ANNOUNCEMENTS,
} from '../../../../../common';
import { useColumns } from '../../../../hooks/use_data_grid_columns';
import { SavedSearch } from '../../../../services/saved_searches';
import { DataDocuments$, DataDocumentsMsg, RecordRawType } from '../../hooks/use_saved_search';
import { AppState, GetStateReturn } from '../../services/discover_state';
import { useDataState } from '../../hooks/use_data_state';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ import { useColumns } from '../../../../hooks/use_data_grid_columns';
import { DiscoverDocuments } from './discover_documents';
import { FetchStatus } from '../../../types';
import { useDataState } from '../../hooks/use_data_state';
import { SavedSearchURLConflictCallout } from '../../../../services/saved_searches';
import { FieldStatisticsTable } from '../field_stats_table';
import { VIEW_MODE } from '../../../../components/view_mode_toggle';
import { DOCUMENTS_VIEW_CLICK, FIELD_STATISTICS_VIEW_CLICK } from '../field_stats_table/constants';
import { hasActiveFilter } from './utils';
import { getRawRecordType } from '../../utils/get_raw_record_type';
import { SavedSearchURLConflictCallout } from '../../../../components/saved_search_url_conflict_callout/saved_search_url_conflict_callout';

/**
* Local storage key for sidebar persistence state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import type { SavedObject } from '@kbn/data-plugin/public';
import type { DataView, DataViewAttributes } from '@kbn/data-views-plugin/public';
import { ISearchSource } from '@kbn/data-plugin/public';
import { RequestAdapter } from '@kbn/inspector-plugin/common';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { DataTableRecord } from '../../../../types';
import { AppState, GetStateReturn } from '../../services/discover_state';
import { DataRefetch$, SavedSearchData } from '../../hooks/use_saved_search';
import { SavedSearch } from '../../../../services/saved_searches';

export interface DiscoverLayoutProps {
dataView: DataView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import type { ISearchSource } from '@kbn/data-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { unhashUrl } from '@kbn/kibana-utils-plugin/public';
import type { TopNavMenuData } from '@kbn/navigation-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { showOpenSearchPanel } from './show_open_search_panel';
import { getSharingData, showPublicUrlSwitch } from '../../../../utils/get_sharing_data';
import { DiscoverServices } from '../../../../build_services';
import { SavedSearch } from '../../../../services/saved_searches';
import { onSaveSearch } from './on_save_search';
import { GetStateReturn } from '../../services/discover_state';
import { openOptionsPopover } from './open_options_popover';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { SavedObjectSaveModal, showSaveModal, OnSaveProps } from '@kbn/saved-objects-plugin/public';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch, SaveSavedSearchOptions } from '../../../../services/saved_searches';
import { SavedSearch, SaveSavedSearchOptions } from '@kbn/saved-search-plugin/public';
import { DiscoverServices } from '../../../../build_services';
import { GetStateReturn } from '../../services/discover_state';
import { setBreadcrumbsTitle } from '../../../../utils/breadcrumbs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import React, { useCallback, useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
import type { DataViewAttributes } from '@kbn/data-views-plugin/public';
import type { SavedObject } from '@kbn/data-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { DiscoverLayout } from './components/layout';
import { setBreadcrumbsTitle } from '../../utils/breadcrumbs';
import { addHelpMenuToAppChrome } from '../../components/help_menu/help_menu_util';
import { useDiscoverState } from './hooks/use_discover_state';
import { useUrl } from './hooks/use_url';
import { SavedSearch, useSavedSearchAliasMatchRedirect } from '../../services/saved_searches';
import { useDiscoverServices } from '../../hooks/use_discover_services';
import { DataTableRecord } from '../../types';
import { useSavedSearchAliasMatchRedirect } from '../../hooks/saved_search_alias_match_redirect';

const DiscoverLayoutMemoized = React.memo(DiscoverLayout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
SavedSearch,
getSavedSearch,
getSavedSearchFullPathUrl,
} from '../../services/saved_searches';
} from '@kbn/saved-search-plugin/public';
import { getState } from './services/discover_state';
import { loadDataView, resolveDataView } from './utils/resolve_data_view';
import { DiscoverMainApp } from './discover_main_app';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
AggregateQuery,
Query,
} from '@kbn/es-query';
import { SavedSearch, getSavedSearch } from '@kbn/saved-search-plugin/public';
import { getState } from '../services/discover_state';
import { getStateDefaults } from '../utils/get_state_defaults';
import { DiscoverServices } from '../../../build_services';
import { SavedSearch, getSavedSearch } from '../../../services/saved_searches';
import { loadDataView } from '../utils/resolve_data_view';
import { useSavedSearch as useSavedSearchData, DataDocumentsMsg } from './use_saved_search';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import type { AutoRefreshDoneFn } from '@kbn/data-plugin/public';
import { ISearchSource } from '@kbn/data-plugin/public';
import { RequestAdapter } from '@kbn/inspector-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { getRawRecordType } from '../utils/get_raw_record_type';
import { DiscoverServices } from '../../../build_services';
import { DiscoverSearchSessionManager } from '../services/discover_search_session';
Expand All @@ -22,7 +23,6 @@ import { fetchAll } from '../utils/fetch_all';
import { useBehaviorSubject } from './use_behavior_subject';
import { sendResetMsg } from './use_saved_search_messages';
import { getFetch$ } from '../utils/get_fetch_observable';
import { SavedSearch } from '../../../services/saved_searches';
import type { DataTableRecord } from '../../../types';

export interface SavedSearchData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import { useMemo, useEffect } from 'react';
import { History } from 'history';
import { noSearchSessionStorageCapabilityMessage } from '@kbn/data-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { DiscoverSearchSessionManager } from '../services/discover_search_session';
import {
createSearchSessionRestorationDataProvider,
GetStateReturn,
} from '../services/discover_state';
import { DiscoverServices } from '../../../build_services';
import { SavedSearch } from '../../../services/saved_searches';

export function useSearchSession({
services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './discover_state';
import { createBrowserHistory, History } from 'history';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import type { SavedSearch } from '../../../services/saved_searches';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { SEARCH_FIELDS_FROM_SOURCE } from '../../../../common';

let history: History;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
syncQueryStateWithUrl,
} from '@kbn/data-plugin/public';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { DiscoverGridSettings } from '../../../components/discover_grid/types';
import { SavedSearch } from '../../../services/saved_searches';
import { handleSourceColumnState } from '../../../utils/state_helpers';
import { DISCOVER_APP_LOCATOR, DiscoverAppLocatorParams } from '../../../locator';
import { VIEW_MODE } from '../../../components/view_mode_toggle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DataPublicPluginStart, ISearchSource } from '@kbn/data-plugin/public';
import { Adapters } from '@kbn/inspector-plugin/common';
import { ReduxLikeStateContainer } from '@kbn/kibana-utils-plugin/common';
import { DataViewType } from '@kbn/data-views-plugin/public';
import type { SavedSearch, SortOrder } from '@kbn/saved-search-plugin/public';
import { getRawRecordType } from './get_raw_record_type';
import {
sendCompleteMsg,
Expand All @@ -19,7 +20,6 @@ import {
sendResetMsg,
} from '../hooks/use_saved_search_messages';
import { updateSearchSource } from './update_search_source';
import type { SavedSearch, SortOrder } from '../../../services/saved_searches';
import { fetchDocuments } from './fetch_documents';
import { fetchTotalHits } from './fetch_total_hits';
import { fetchChart } from './fetch_chart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { cloneDeep, isEqual } from 'lodash';
import { IUiSettingsClient } from '@kbn/core/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import {
DEFAULT_COLUMNS_SETTING,
DOC_HIDE_TIME_COLUMN_SETTING,
SEARCH_FIELDS_FROM_SOURCE,
SORT_DEFAULT_ORDER_SETTING,
} from '../../../../common';
import { SavedSearch } from '../../../services/saved_searches';

import { AppState } from '../services/discover_state';
import { getDefaultSort, getSortArray } from '../../../components/doc_table';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import { isOfAggregateQueryType } from '@kbn/es-query';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedObjectSaveOpts } from '@kbn/saved-objects-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { saveSavedSearch } from '@kbn/saved-search-plugin/public';
import { updateSearchSource } from './update_search_source';
import { SavedSearch } from '../../../services/saved_searches';
import { AppState } from '../services/discover_state';
import type { SortOrder } from '../../../services/saved_searches';
import { DiscoverServices } from '../../../build_services';
import { saveSavedSearch } from '../../../services/saved_searches';
/**
* Helper function to update and persist the given savedSearch
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { updateSearchSource } from './update_search_source';
import { createSearchSourceMock } from '@kbn/data-plugin/common/search/search_source/mocks';
import { dataViewMock } from '../../../__mocks__/data_view';
import type { SortOrder } from '../../../services/saved_searches';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { discoverServiceMock } from '../../../__mocks__/services';

describe('updateSearchSource', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import { ISearchSource } from '@kbn/data-plugin/public';
import { DataViewType, DataView } from '@kbn/data-views-plugin/public';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { SORT_DEFAULT_ORDER_SETTING } from '../../../../common';
import type { SortOrder } from '../../../services/saved_searches';
import { DiscoverServices } from '../../../build_services';
import { getSortForSearchSource } from '../../../components/doc_table';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import type { History } from 'history';

import { mountWithIntl } from '@kbn/test-jest-helpers';
import { SavedSearchURLConflictCallout } from './saved_search_url_conflict_callout';
import type { SavedSearch } from './types';

import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';
import { SavedSearch } from '@kbn/saved-search-plugin/public';

describe('SavedSearchURLConflictCallout', () => {
let spaces: ReturnType<typeof spacesPluginMock.createStartContract>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import { i18n } from '@kbn/i18n';
import type { History } from 'history';
import type { SpacesApi } from '@kbn/spaces-plugin/public';
import { getSavedSearchUrl } from './saved_searches_utils';

import type { SavedSearch } from './types';
import { getSavedSearchUrl, SavedSearch } from '@kbn/saved-search-plugin/public';

interface SavedSearchURLConflictCalloutProps {
savedSearch?: SavedSearch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import { ISearchSource } from '@kbn/data-plugin/public';
import { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { RecordRawType } from '../application/main/hooks/use_saved_search';
import { buildDataTableRecord } from '../utils/build_data_record';
import { DataTableRecord, EsHitRecord } from '../types';
import { ISearchEmbeddable, SearchInput, SearchOutput } from './types';
import { SavedSearch } from '../services/saved_searches';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import { DiscoverServices } from '../build_services';
import { SavedSearchEmbeddableComponent } from './saved_search_embeddable_component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {

import type { TimeRange } from '@kbn/es-query';

import { SearchInput, SearchOutput } from './types';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import { SavedSearchEmbeddable } from './saved_search_embeddable';
import {
getSavedSearch,
getSavedSearchUrl,
throwErrorOnSavedSearchUrlConflict,
} from '../services/saved_searches';
} from '@kbn/saved-search-plugin/public';
import { SearchInput, SearchOutput } from './types';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import { SavedSearchEmbeddable } from './saved_search_embeddable';
import { DiscoverServices } from '../build_services';

interface StartServices {
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 '@kbn/embeddable-plugin/public';
import type { Filter, TimeRange, Query } from '@kbn/es-query';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '../services/saved_searches';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { SortOrder } from '../components/doc_table/components/table_header/helpers';

export interface SearchInput extends EmbeddableInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { createSearchSourceMock } from '@kbn/data-plugin/common/search/search_source/mocks';
import { updateSearchSource } from './update_search_source';
import { dataViewMock } from '../../__mocks__/data_view';
import type { SortOrder } from '../../services/saved_searches';
import type { SortOrder } from '@kbn/saved-search-plugin/public';

describe('updateSearchSource', () => {
const defaults = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { ApplicationStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { IEmbeddable, ViewMode } from '@kbn/embeddable-plugin/public';
import { Action } from '@kbn/ui-actions-plugin/public';
import { getSavedSearchUrl } from '@kbn/saved-search-plugin/public';
import { SavedSearchEmbeddable } from './saved_search_embeddable';
import { SEARCH_EMBEDDABLE_TYPE } from '../../common';
import { getSavedSearchUrl } from '../services/saved_searches';

export const ACTION_VIEW_SAVED_SEARCH = 'ACTION_VIEW_SAVED_SEARCH';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { renderHook } from '@testing-library/react-hooks';
import type { History } from 'history';

import { useSavedSearchAliasMatchRedirect } from './saved_search_alias_match_redirect';
import type { SavedSearch } from './types';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';

import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';

Expand Down
Loading

0 comments on commit f10c626

Please sign in to comment.