diff --git a/.eslintrc.js b/.eslintrc.js index 372ddb8533359..603559f732a1c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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': [ diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c51571ebaece6..4558c46e51fe1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/.i18nrc.json b/.i18nrc.json index b77d2c42508f1..cee83a60c1fd2 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -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", diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index 67626e0580390..e05ab3aa52b09 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -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. diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 955ec123c1626..be602cb739c46 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -120,6 +120,7 @@ pageLoadAssetSize: controls: 40000 expressionPartitionVis: 26338 sharedUX: 16225 + savedSearch: 16225 ux: 20784 sessionView: 77750 cloudSecurityPosture: 19109 diff --git a/src/plugins/discover/kibana.json b/src/plugins/discover/kibana.json index 7c8376795863a..78e5265bcb3ac 100644 --- a/src/plugins/discover/kibana.json +++ b/src/plugins/discover/kibana.json @@ -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", diff --git a/src/plugins/discover/public/__mocks__/saved_search.ts b/src/plugins/discover/public/__mocks__/saved_search.ts index 8cd6fbd5b9572..1f430de118317 100644 --- a/src/plugins/discover/public/__mocks__/saved_search.ts +++ b/src/plugins/discover/public/__mocks__/saved_search.ts @@ -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'; diff --git a/src/plugins/discover/public/application/main/components/chart/discover_chart.tsx b/src/plugins/discover/public/application/main/components/chart/discover_chart.tsx index becf20bff3cb2..2b50856fa84fc 100644 --- a/src/plugins/discover/public/application/main/components/chart/discover_chart.tsx +++ b/src/plugins/discover/public/application/main/components/chart/discover_chart.tsx @@ -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'; diff --git a/src/plugins/discover/public/application/main/components/field_stats_table/field_stats_table.tsx b/src/plugins/discover/public/application/main/components/field_stats_table/field_stats_table.tsx index 8334e0ec74257..59d8fae4afbeb 100644 --- a/src/plugins/discover/public/application/main/components/field_stats_table/field_stats_table.tsx +++ b/src/plugins/discover/public/application/main/components/field_stats_table/field_stats_table.tsx @@ -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'; diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 2a824ddf361fb..92443cea9f1ae 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -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'; @@ -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'; diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx index 1f353bdaeba28..4806e8f35a007 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx @@ -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 diff --git a/src/plugins/discover/public/application/main/components/layout/types.ts b/src/plugins/discover/public/application/main/components/layout/types.ts index 41e3e9d8b7718..e254dd8774a37 100644 --- a/src/plugins/discover/public/application/main/components/layout/types.ts +++ b/src/plugins/discover/public/application/main/components/layout/types.ts @@ -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; diff --git a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx index 39f842b58250c..5ce9f15ce43d9 100644 --- a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx +++ b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx @@ -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'; diff --git a/src/plugins/discover/public/application/main/components/top_nav/on_save_search.tsx b/src/plugins/discover/public/application/main/components/top_nav/on_save_search.tsx index 6491da5bd8baa..9f0c1f9552f2c 100644 --- a/src/plugins/discover/public/application/main/components/top_nav/on_save_search.tsx +++ b/src/plugins/discover/public/application/main/components/top_nav/on_save_search.tsx @@ -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'; diff --git a/src/plugins/discover/public/application/main/discover_main_app.tsx b/src/plugins/discover/public/application/main/discover_main_app.tsx index 21e709a7d1cc1..9b48be3ad1bc8 100644 --- a/src/plugins/discover/public/application/main/discover_main_app.tsx +++ b/src/plugins/discover/public/application/main/discover_main_app.tsx @@ -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); diff --git a/src/plugins/discover/public/application/main/discover_main_route.tsx b/src/plugins/discover/public/application/main/discover_main_route.tsx index 773eac7a556ed..cec20f64d82b2 100644 --- a/src/plugins/discover/public/application/main/discover_main_route.tsx +++ b/src/plugins/discover/public/application/main/discover_main_route.tsx @@ -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'; diff --git a/src/plugins/discover/public/application/main/hooks/use_discover_state.ts b/src/plugins/discover/public/application/main/hooks/use_discover_state.ts index 9d464d5267f60..b5cf634ebe3a0 100644 --- a/src/plugins/discover/public/application/main/hooks/use_discover_state.ts +++ b/src/plugins/discover/public/application/main/hooks/use_discover_state.ts @@ -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 { diff --git a/src/plugins/discover/public/application/main/hooks/use_saved_search.ts b/src/plugins/discover/public/application/main/hooks/use_saved_search.ts index def74bd94e7b1..3b9948f88d17e 100644 --- a/src/plugins/discover/public/application/main/hooks/use_saved_search.ts +++ b/src/plugins/discover/public/application/main/hooks/use_saved_search.ts @@ -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'; @@ -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 { diff --git a/src/plugins/discover/public/application/main/hooks/use_search_session.ts b/src/plugins/discover/public/application/main/hooks/use_search_session.ts index 1bdbc27968f73..af5768d7c4752 100644 --- a/src/plugins/discover/public/application/main/hooks/use_search_session.ts +++ b/src/plugins/discover/public/application/main/hooks/use_search_session.ts @@ -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, diff --git a/src/plugins/discover/public/application/main/services/discover_state.test.ts b/src/plugins/discover/public/application/main/services/discover_state.test.ts index 5ae2da5149d69..ccec7582ce8d3 100644 --- a/src/plugins/discover/public/application/main/services/discover_state.test.ts +++ b/src/plugins/discover/public/application/main/services/discover_state.test.ts @@ -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; diff --git a/src/plugins/discover/public/application/main/services/discover_state.ts b/src/plugins/discover/public/application/main/services/discover_state.ts index 847462510ceba..33393eeecdd75 100644 --- a/src/plugins/discover/public/application/main/services/discover_state.ts +++ b/src/plugins/discover/public/application/main/services/discover_state.ts @@ -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'; diff --git a/src/plugins/discover/public/application/main/utils/fetch_all.ts b/src/plugins/discover/public/application/main/utils/fetch_all.ts index 30d860f7fa669..42b415630e92c 100644 --- a/src/plugins/discover/public/application/main/utils/fetch_all.ts +++ b/src/plugins/discover/public/application/main/utils/fetch_all.ts @@ -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, @@ -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'; diff --git a/src/plugins/discover/public/application/main/utils/get_state_defaults.ts b/src/plugins/discover/public/application/main/utils/get_state_defaults.ts index 56996e999d6c9..5eb863372d90c 100644 --- a/src/plugins/discover/public/application/main/utils/get_state_defaults.ts +++ b/src/plugins/discover/public/application/main/utils/get_state_defaults.ts @@ -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'; diff --git a/src/plugins/discover/public/application/main/utils/persist_saved_search.ts b/src/plugins/discover/public/application/main/utils/persist_saved_search.ts index ac5554028d2e8..691a8a6604194 100644 --- a/src/plugins/discover/public/application/main/utils/persist_saved_search.ts +++ b/src/plugins/discover/public/application/main/utils/persist_saved_search.ts @@ -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 */ diff --git a/src/plugins/discover/public/application/main/utils/update_search_source.test.ts b/src/plugins/discover/public/application/main/utils/update_search_source.test.ts index 7e3029f02fac0..5ab1dd962652f 100644 --- a/src/plugins/discover/public/application/main/utils/update_search_source.test.ts +++ b/src/plugins/discover/public/application/main/utils/update_search_source.test.ts @@ -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', () => { diff --git a/src/plugins/discover/public/application/main/utils/update_search_source.ts b/src/plugins/discover/public/application/main/utils/update_search_source.ts index 3890924519fe1..aea864af91d81 100644 --- a/src/plugins/discover/public/application/main/utils/update_search_source.ts +++ b/src/plugins/discover/public/application/main/utils/update_search_source.ts @@ -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'; diff --git a/src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.test.tsx b/src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.test.tsx similarity index 96% rename from src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.test.tsx rename to src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.test.tsx index 0d2fd18a6afc7..d65bc83befa96 100644 --- a/src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.test.tsx +++ b/src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.test.tsx @@ -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; diff --git a/src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.ts b/src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.ts similarity index 93% rename from src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.ts rename to src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.ts index 3da3fc346ffaa..1fbb74d6130cb 100644 --- a/src/plugins/discover/public/services/saved_searches/saved_search_url_conflict_callout.ts +++ b/src/plugins/discover/public/components/saved_search_url_conflict_callout/saved_search_url_conflict_callout.ts @@ -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; diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx index c2e76e517f64d..647691496098e 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx @@ -27,11 +27,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'; diff --git a/src/plugins/discover/public/embeddable/search_embeddable_factory.ts b/src/plugins/discover/public/embeddable/search_embeddable_factory.ts index e43769bb8c383..331fa7103a825 100644 --- a/src/plugins/discover/public/embeddable/search_embeddable_factory.ts +++ b/src/plugins/discover/public/embeddable/search_embeddable_factory.ts @@ -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 { diff --git a/src/plugins/discover/public/embeddable/types.ts b/src/plugins/discover/public/embeddable/types.ts index a72d7d86f6801..dacb9b7d81d43 100644 --- a/src/plugins/discover/public/embeddable/types.ts +++ b/src/plugins/discover/public/embeddable/types.ts @@ -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 { diff --git a/src/plugins/discover/public/embeddable/utils/update_search_source.test.ts b/src/plugins/discover/public/embeddable/utils/update_search_source.test.ts index 00e0175f813c2..779fcfffde778 100644 --- a/src/plugins/discover/public/embeddable/utils/update_search_source.test.ts +++ b/src/plugins/discover/public/embeddable/utils/update_search_source.test.ts @@ -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 = { diff --git a/src/plugins/discover/public/embeddable/view_saved_search_action.ts b/src/plugins/discover/public/embeddable/view_saved_search_action.ts index 59e27de85c2bd..1b58489336423 100644 --- a/src/plugins/discover/public/embeddable/view_saved_search_action.ts +++ b/src/plugins/discover/public/embeddable/view_saved_search_action.ts @@ -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'; diff --git a/src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.test.ts b/src/plugins/discover/public/hooks/saved_search_alias_match_redirect.test.ts similarity index 97% rename from src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.test.ts rename to src/plugins/discover/public/hooks/saved_search_alias_match_redirect.test.ts index 62c2e447f6d8b..93f2c1be1ab6b 100644 --- a/src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.test.ts +++ b/src/plugins/discover/public/hooks/saved_search_alias_match_redirect.test.ts @@ -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'; diff --git a/src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.ts b/src/plugins/discover/public/hooks/saved_search_alias_match_redirect.ts similarity index 93% rename from src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.ts rename to src/plugins/discover/public/hooks/saved_search_alias_match_redirect.ts index e395ccbdaf264..983701236e59b 100644 --- a/src/plugins/discover/public/services/saved_searches/saved_search_alias_match_redirect.ts +++ b/src/plugins/discover/public/hooks/saved_search_alias_match_redirect.ts @@ -10,9 +10,7 @@ import type { History } from 'history'; import { useEffect } from 'react'; import { i18n } from '@kbn/i18n'; 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 SavedSearchAliasMatchRedirectProps { savedSearch?: SavedSearch; diff --git a/src/plugins/discover/public/index.ts b/src/plugins/discover/public/index.ts index 936efb7239313..b516161d0e97b 100644 --- a/src/plugins/discover/public/index.ts +++ b/src/plugins/discover/public/index.ts @@ -9,15 +9,6 @@ import { PluginInitializerContext } from '@kbn/core/public'; import { DiscoverPlugin } from './plugin'; -export type { SavedSearch } from './services/saved_searches'; -export { - getSavedSearch, - getSavedSearchFullPathUrl, - getSavedSearchUrl, - getSavedSearchUrlConflictMessage, - throwErrorOnSavedSearchUrlConflict, -} from './services/saved_searches'; - export type { DiscoverSetup, DiscoverStart } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { return new DiscoverPlugin(initializerContext); @@ -29,3 +20,16 @@ export { loadSharingDataHelpers } from './utils'; export { DISCOVER_APP_LOCATOR } from './locator'; export type { DiscoverAppLocator, DiscoverAppLocatorParams } from './locator'; + +// re-export types and static functions to give other plugins time to migrate away +export { + SavedSearch, + getSavedSearch, + getSavedSearchFullPathUrl, + getSavedSearchUrl, + getSavedSearchUrlConflictMessage, + throwErrorOnSavedSearchUrlConflict, + VIEW_MODE, + DiscoverGridSettings, + DiscoverGridSettingsColumn, +} from '@kbn/saved-search-plugin/public'; diff --git a/src/plugins/discover/public/utils/breadcrumbs.ts b/src/plugins/discover/public/utils/breadcrumbs.ts index e89186fc6f38d..ca968b43fdb2a 100644 --- a/src/plugins/discover/public/utils/breadcrumbs.ts +++ b/src/plugins/discover/public/utils/breadcrumbs.ts @@ -8,7 +8,7 @@ import { ChromeStart } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; -import { SavedSearch } from '../services/saved_searches'; +import { SavedSearch } from '@kbn/saved-search-plugin/public'; export function getRootBreadcrumbs(breadcrumb?: string) { return [ diff --git a/src/plugins/discover/public/utils/get_sharing_data.ts b/src/plugins/discover/public/utils/get_sharing_data.ts index 66a6a6f1eed10..6d99edd3d9fe1 100644 --- a/src/plugins/discover/public/utils/get_sharing_data.ts +++ b/src/plugins/discover/public/utils/get_sharing_data.ts @@ -14,12 +14,12 @@ import type { SerializedSearchSourceFields, } from '@kbn/data-plugin/public'; import type { Filter } from '@kbn/es-query'; +import type { SavedSearch, SortOrder } from '@kbn/saved-search-plugin/public'; import { DOC_HIDE_TIME_COLUMN_SETTING, SEARCH_FIELDS_FROM_SOURCE, SORT_DEFAULT_ORDER_SETTING, } from '../../common'; -import type { SavedSearch, SortOrder } from '../services/saved_searches'; import { getSortForSearchSource } from '../components/doc_table'; import { AppState, isEqualFilters } from '../application/main/services/discover_state'; diff --git a/src/plugins/discover/server/plugin.ts b/src/plugins/discover/server/plugin.ts index 888fcf55c2351..cfd62312fb6da 100644 --- a/src/plugins/discover/server/plugin.ts +++ b/src/plugins/discover/server/plugin.ts @@ -11,7 +11,6 @@ import type { PluginSetup as DataPluginSetup } from '@kbn/data-plugin/server'; import type { HomeServerPluginSetup } from '@kbn/home-plugin/server'; import { getUiSettings } from './ui_settings'; import { capabilitiesProvider } from './capabilities_provider'; -import { getSavedSearchObjectType } from './saved_objects'; import { registerSampleData } from './sample_data'; export class DiscoverServerPlugin implements Plugin { @@ -22,12 +21,8 @@ export class DiscoverServerPlugin implements Plugin { home?: HomeServerPluginSetup; } ) { - const getSearchSourceMigrations = plugins.data.search.searchSource.getAllMigrations.bind( - plugins.data.search.searchSource - ); core.capabilities.registerProvider(capabilitiesProvider); core.uiSettings.register(getUiSettings(core.docLinks)); - core.savedObjects.registerType(getSavedSearchObjectType(getSearchSourceMigrations)); if (plugins.home) { registerSampleData(plugins.home.sampleData); diff --git a/src/plugins/discover/server/sample_data/register_sample_data.ts b/src/plugins/discover/server/sample_data/register_sample_data.ts index a1ff9951d9179..a864045a5b2b7 100644 --- a/src/plugins/discover/server/sample_data/register_sample_data.ts +++ b/src/plugins/discover/server/sample_data/register_sample_data.ts @@ -8,8 +8,8 @@ import { i18n } from '@kbn/i18n'; import type { SampleDataRegistrySetup } from '@kbn/home-plugin/server'; +import { getSavedSearchFullPathUrl } from '@kbn/saved-search-plugin/common'; import { APP_ICON } from '../../common'; -import { getSavedSearchFullPathUrl } from '../../common/services/saved_searches'; function getDiscoverPathForSampleDataset(objId: string) { // TODO: remove the time range from the URL query when saved search objects start supporting time range configuration diff --git a/src/plugins/discover/tsconfig.json b/src/plugins/discover/tsconfig.json index 5cdc21844c8a1..efadcc88443a1 100644 --- a/src/plugins/discover/tsconfig.json +++ b/src/plugins/discover/tsconfig.json @@ -10,6 +10,7 @@ "references": [ { "path": "../../core/tsconfig.json" }, { "path": "../charts/tsconfig.json" }, + { "path": "../saved_search/tsconfig.json" }, { "path": "../data/tsconfig.json" }, { "path": "../expressions/tsconfig.json" }, { "path": "../embeddable/tsconfig.json" }, diff --git a/src/plugins/saved_search/README.md b/src/plugins/saved_search/README.md new file mode 100644 index 0000000000000..d2234f04494a1 --- /dev/null +++ b/src/plugins/saved_search/README.md @@ -0,0 +1,3 @@ +# Saved search + +Contains the saved search saved object definition and helpers. diff --git a/src/plugins/discover/common/services/saved_searches/index.ts b/src/plugins/saved_search/common/index.ts similarity index 100% rename from src/plugins/discover/common/services/saved_searches/index.ts rename to src/plugins/saved_search/common/index.ts diff --git a/src/plugins/discover/common/services/saved_searches/saved_searches_url.test.ts b/src/plugins/saved_search/common/saved_searches_url.test.ts similarity index 100% rename from src/plugins/discover/common/services/saved_searches/saved_searches_url.test.ts rename to src/plugins/saved_search/common/saved_searches_url.test.ts diff --git a/src/plugins/discover/common/services/saved_searches/saved_searches_url.ts b/src/plugins/saved_search/common/saved_searches_url.ts similarity index 100% rename from src/plugins/discover/common/services/saved_searches/saved_searches_url.ts rename to src/plugins/saved_search/common/saved_searches_url.ts diff --git a/src/plugins/saved_search/jest.config.js b/src/plugins/saved_search/jest.config.js new file mode 100644 index 0000000000000..849af79d37911 --- /dev/null +++ b/src/plugins/saved_search/jest.config.js @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/saved_search'], + testRunner: 'jasmine2', + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/saved_search', + coverageReporters: ['text', 'html'], + collectCoverageFrom: [ + '/src/plugins/saved_search/{common,public,server}/**/*.{js,ts,tsx}', + ], +}; diff --git a/src/plugins/saved_search/kibana.json b/src/plugins/saved_search/kibana.json new file mode 100644 index 0000000000000..d58d429474c87 --- /dev/null +++ b/src/plugins/saved_search/kibana.json @@ -0,0 +1,16 @@ +{ + "id": "savedSearch", + "version": "kibana", + "server": true, + "ui": true, + "requiredPlugins": [ + "data" + ], + "requiredBundles": ["kibanaUtils"], + "extraPublicDirs": ["common"], + "owner": { + "name": "Data Discovery", + "githubTeam": "kibana-data-discovery" + }, + "description": "This plugin contains the definition and helper methods around saved searches, used by discover and visualizations." +} diff --git a/src/plugins/saved_search/public/index.ts b/src/plugins/saved_search/public/index.ts new file mode 100644 index 0000000000000..047d663b16caa --- /dev/null +++ b/src/plugins/saved_search/public/index.ts @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export type { SavedSearch, SaveSavedSearchOptions, SortOrder } from './services/saved_searches'; +export { + getSavedSearch, + getSavedSearchFullPathUrl, + getSavedSearchUrl, + getSavedSearchUrlConflictMessage, + throwErrorOnSavedSearchUrlConflict, + saveSavedSearch, +} from './services/saved_searches'; +export type { + DiscoverGridSettings, + DiscoverGridSettingsColumn, +} from './services/saved_searches/types'; +export { VIEW_MODE } from './services/saved_searches/types'; + +export function plugin() { + return { + setup: () => {}, + start: () => {}, + }; +} diff --git a/src/plugins/discover/public/services/saved_searches/constants.ts b/src/plugins/saved_search/public/services/saved_searches/constants.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/constants.ts rename to src/plugins/saved_search/public/services/saved_searches/constants.ts diff --git a/src/plugins/discover/public/services/saved_searches/get_saved_searches.test.ts b/src/plugins/saved_search/public/services/saved_searches/get_saved_searches.test.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/get_saved_searches.test.ts rename to src/plugins/saved_search/public/services/saved_searches/get_saved_searches.test.ts diff --git a/src/plugins/discover/public/services/saved_searches/get_saved_searches.ts b/src/plugins/saved_search/public/services/saved_searches/get_saved_searches.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/get_saved_searches.ts rename to src/plugins/saved_search/public/services/saved_searches/get_saved_searches.ts diff --git a/src/plugins/discover/public/services/saved_searches/index.ts b/src/plugins/saved_search/public/services/saved_searches/index.ts similarity index 82% rename from src/plugins/discover/public/services/saved_searches/index.ts rename to src/plugins/saved_search/public/services/saved_searches/index.ts index c41c92df30084..fbdcfbf5793c6 100644 --- a/src/plugins/discover/public/services/saved_searches/index.ts +++ b/src/plugins/saved_search/public/services/saved_searches/index.ts @@ -13,8 +13,6 @@ export { getSavedSearchUrlConflictMessage, throwErrorOnSavedSearchUrlConflict, } from './saved_searches_utils'; -export { useSavedSearchAliasMatchRedirect } from './saved_search_alias_match_redirect'; -export { SavedSearchURLConflictCallout } from './saved_search_url_conflict_callout'; export type { SaveSavedSearchOptions } from './save_saved_searches'; export { saveSavedSearch } from './save_saved_searches'; export { SAVED_SEARCH_TYPE } from './constants'; diff --git a/src/plugins/discover/public/services/saved_searches/save_saved_searches.test.ts b/src/plugins/saved_search/public/services/saved_searches/save_saved_searches.test.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/save_saved_searches.test.ts rename to src/plugins/saved_search/public/services/saved_searches/save_saved_searches.test.ts diff --git a/src/plugins/discover/public/services/saved_searches/save_saved_searches.ts b/src/plugins/saved_search/public/services/saved_searches/save_saved_searches.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/save_saved_searches.ts rename to src/plugins/saved_search/public/services/saved_searches/save_saved_searches.ts diff --git a/src/plugins/discover/public/services/saved_searches/saved_searches_utils.test.ts b/src/plugins/saved_search/public/services/saved_searches/saved_searches_utils.test.ts similarity index 100% rename from src/plugins/discover/public/services/saved_searches/saved_searches_utils.test.ts rename to src/plugins/saved_search/public/services/saved_searches/saved_searches_utils.test.ts diff --git a/src/plugins/discover/public/services/saved_searches/saved_searches_utils.ts b/src/plugins/saved_search/public/services/saved_searches/saved_searches_utils.ts similarity index 92% rename from src/plugins/discover/public/services/saved_searches/saved_searches_utils.ts rename to src/plugins/saved_search/public/services/saved_searches/saved_searches_utils.ts index 5c13c9d78cb9e..cb20b24287943 100644 --- a/src/plugins/discover/public/services/saved_searches/saved_searches_utils.ts +++ b/src/plugins/saved_search/public/services/saved_searches/saved_searches_utils.ts @@ -8,13 +8,10 @@ import { i18n } from '@kbn/i18n'; import type { SavedSearchAttributes, SavedSearch } from './types'; -export { - getSavedSearchUrl, - getSavedSearchFullPathUrl, -} from '../../../common/services/saved_searches'; +export { getSavedSearchUrl, getSavedSearchFullPathUrl } from '../../../common'; export const getSavedSearchUrlConflictMessage = async (savedSearch: SavedSearch) => - i18n.translate('discover.savedSearchEmbeddable.legacyURLConflict.errorMessage', { + i18n.translate('savedSearch.legacyURLConflict.errorMessage', { defaultMessage: `This search has the same URL as a legacy alias. Disable the alias to resolve this error : {json}`, values: { json: savedSearch.sharingSavedObjectProps?.errorJSON, diff --git a/src/plugins/discover/public/services/saved_searches/types.ts b/src/plugins/saved_search/public/services/saved_searches/types.ts similarity index 86% rename from src/plugins/discover/public/services/saved_searches/types.ts rename to src/plugins/saved_search/public/services/saved_searches/types.ts index fe47dedf6013d..e0c1e8be4a3ed 100644 --- a/src/plugins/discover/public/services/saved_searches/types.ts +++ b/src/plugins/saved_search/public/services/saved_searches/types.ts @@ -8,8 +8,19 @@ import type { ResolvedSimpleSavedObject } from '@kbn/core/public'; import type { ISearchSource } from '@kbn/data-plugin/public'; -import { DiscoverGridSettingsColumn } from '../../components/discover_grid/types'; -import { VIEW_MODE } from '../../components/view_mode_toggle'; + +export enum VIEW_MODE { + DOCUMENT_LEVEL = 'documents', + AGGREGATED_LEVEL = 'aggregated', +} + +export interface DiscoverGridSettings { + columns?: Record; +} + +export interface DiscoverGridSettingsColumn { + width?: number; +} /** @internal **/ export interface SavedSearchAttributes { diff --git a/src/plugins/saved_search/server/index.ts b/src/plugins/saved_search/server/index.ts new file mode 100644 index 0000000000000..4ec3dc6fea491 --- /dev/null +++ b/src/plugins/saved_search/server/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { SavedSearchServerPlugin } from './plugin'; + +export const plugin = () => new SavedSearchServerPlugin(); diff --git a/src/plugins/saved_search/server/plugin.ts b/src/plugins/saved_search/server/plugin.ts new file mode 100644 index 0000000000000..ca41ed81e4088 --- /dev/null +++ b/src/plugins/saved_search/server/plugin.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { CoreSetup, CoreStart, Plugin } from '@kbn/core/server'; +import type { PluginSetup as DataPluginSetup } from '@kbn/data-plugin/server'; +import { getSavedSearchObjectType } from './saved_objects'; + +export class SavedSearchServerPlugin implements Plugin { + public setup( + core: CoreSetup, + plugins: { + data: DataPluginSetup; + } + ) { + const getSearchSourceMigrations = plugins.data.search.searchSource.getAllMigrations.bind( + plugins.data.search.searchSource + ); + core.savedObjects.registerType(getSavedSearchObjectType(getSearchSourceMigrations)); + + return {}; + } + + public start(core: CoreStart) { + return {}; + } + + public stop() {} +} diff --git a/src/plugins/discover/server/saved_objects/index.ts b/src/plugins/saved_search/server/saved_objects/index.ts similarity index 100% rename from src/plugins/discover/server/saved_objects/index.ts rename to src/plugins/saved_search/server/saved_objects/index.ts diff --git a/src/plugins/discover/server/saved_objects/search.ts b/src/plugins/saved_search/server/saved_objects/search.ts similarity index 100% rename from src/plugins/discover/server/saved_objects/search.ts rename to src/plugins/saved_search/server/saved_objects/search.ts diff --git a/src/plugins/discover/server/saved_objects/search_migrations.test.ts b/src/plugins/saved_search/server/saved_objects/search_migrations.test.ts similarity index 100% rename from src/plugins/discover/server/saved_objects/search_migrations.test.ts rename to src/plugins/saved_search/server/saved_objects/search_migrations.test.ts diff --git a/src/plugins/discover/server/saved_objects/search_migrations.ts b/src/plugins/saved_search/server/saved_objects/search_migrations.ts similarity index 100% rename from src/plugins/discover/server/saved_objects/search_migrations.ts rename to src/plugins/saved_search/server/saved_objects/search_migrations.ts diff --git a/src/plugins/saved_search/tsconfig.json b/src/plugins/saved_search/tsconfig.json new file mode 100644 index 0000000000000..3bfddf5ff5858 --- /dev/null +++ b/src/plugins/saved_search/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./target/types", + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true + }, + "include": [ + "common/**/*", + "public/**/*", + "server/**/*", + "../../../typings/**/*", + ], + "references": [ + { "path": "../../core/tsconfig.json" }, + { "path": "../data/tsconfig.json" }, + { "path": "../kibana_utils/tsconfig.json" }, + { "path": "../../../x-pack/plugins/spaces/tsconfig.json" } + ] +} diff --git a/src/plugins/visualizations/kibana.json b/src/plugins/visualizations/kibana.json index 62627208561da..69b9eb6c2b090 100644 --- a/src/plugins/visualizations/kibana.json +++ b/src/plugins/visualizations/kibana.json @@ -19,7 +19,7 @@ "dataViewEditor" ], "optionalPlugins": ["home", "share", "spaces", "savedObjectsTaggingOss"], - "requiredBundles": ["kibanaUtils", "discover", "kibanaReact"], + "requiredBundles": ["kibanaUtils", "savedSearch", "kibanaReact"], "extraPublicDirs": ["common/constants", "common/utils", "common/expression_functions"], "owner": { "name": "Vis Editors", diff --git a/src/plugins/visualizations/public/vis.ts b/src/plugins/visualizations/public/vis.ts index 8e89fa8619947..003a894fdfe11 100644 --- a/src/plugins/visualizations/public/vis.ts +++ b/src/plugins/visualizations/public/vis.ts @@ -26,7 +26,7 @@ import { getSavedSearch, SavedSearch, throwErrorOnSavedSearchUrlConflict, -} from '@kbn/discover-plugin/public'; +} from '@kbn/saved-search-plugin/public'; import { PersistedState } from './persisted_state'; import { getTypes, diff --git a/src/plugins/visualizations/public/visualize_app/types.ts b/src/plugins/visualizations/public/visualize_app/types.ts index e7e213d3a6416..88672430c2550 100644 --- a/src/plugins/visualizations/public/visualize_app/types.ts +++ b/src/plugins/visualizations/public/visualize_app/types.ts @@ -37,7 +37,7 @@ import type { UrlForwardingStart } from '@kbn/url-forwarding-plugin/public'; import type { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public'; import type { SpacesPluginStart } from '@kbn/spaces-plugin/public'; import type { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public'; -import type { SavedSearch } from '@kbn/discover-plugin/public'; +import type { SavedSearch } from '@kbn/saved-search-plugin/public'; import type { Vis, VisualizeEmbeddableContract, diff --git a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.test.ts b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.test.ts index ebc17b1e32c91..7e7f3eee7624a 100644 --- a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.test.ts +++ b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { getSavedSearch } from '@kbn/discover-plugin/public'; +import { getSavedSearch } from '@kbn/saved-search-plugin/public'; import type { VisualizeInput, VisSavedObject, Vis, VisParams } from '../..'; import { getVisualizationInstance, @@ -38,7 +38,7 @@ jest.mock('../../vis_async', () => ({ })); const { createVisAsync } = jest.requireMock('../../vis_async'); -jest.mock('@kbn/discover-plugin/public', () => ({ +jest.mock('@kbn/saved-search-plugin/public', () => ({ getSavedSearch: jest.fn().mockResolvedValue({ id: 'savedSearch', title: 'savedSearchTitle', diff --git a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts index 925f22d68a20e..4049f8242a02a 100644 --- a/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts +++ b/src/plugins/visualizations/public/visualize_app/utils/get_visualization_instance.ts @@ -13,7 +13,7 @@ import { getSavedSearch, SavedSearch, throwErrorOnSavedSearchUrlConflict, -} from '@kbn/discover-plugin/public'; +} from '@kbn/saved-search-plugin/public'; import { createVisAsync } from '../../vis_async'; import { convertToSerializedVis, getSavedVisualization } from '../../utils/saved_visualize_utils'; import { diff --git a/src/plugins/visualizations/tsconfig.json b/src/plugins/visualizations/tsconfig.json index e44374e23f623..02eda42929b9f 100644 --- a/src/plugins/visualizations/tsconfig.json +++ b/src/plugins/visualizations/tsconfig.json @@ -24,7 +24,7 @@ { "path": "../saved_objects_tagging_oss/tsconfig.json" }, { "path": "../kibana_utils/tsconfig.json" }, { "path": "../kibana_react/tsconfig.json" }, - { "path": "../discover/tsconfig.json" }, + { "path": "../saved_search/tsconfig.json" }, { "path": "../url_forwarding/tsconfig.json" }, { "path": "../navigation/tsconfig.json" }, { "path": "../home/tsconfig.json" }, diff --git a/tsconfig.base.json b/tsconfig.base.json index c3a37ced8434e..ffdf80f1fe0c1 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -145,6 +145,8 @@ "@kbn/saved-objects-tagging-oss-plugin/*": ["src/plugins/saved_objects_tagging_oss/*"], "@kbn/saved-objects-plugin": ["src/plugins/saved_objects"], "@kbn/saved-objects-plugin/*": ["src/plugins/saved_objects/*"], + "@kbn/saved-search-plugin": ["src/plugins/saved_search"], + "@kbn/saved-search-plugin/*": ["src/plugins/saved_search/*"], "@kbn/screenshot-mode-plugin": ["src/plugins/screenshot_mode"], "@kbn/screenshot-mode-plugin/*": ["src/plugins/screenshot_mode/*"], "@kbn/share-plugin": ["src/plugins/share"], diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index bd439267fb8a8..ca63bc25a13f5 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -3189,7 +3189,6 @@ "discover.savedSearch.savedObjectName": "Recherche enregistrée", "discover.savedSearchAliasMatchRedirect.objectNoun": "Recherche {savedSearch}", "discover.savedSearchEmbeddable.action.viewSavedSearch.displayName": "Ouvrir dans Discover", - "discover.savedSearchEmbeddable.legacyURLConflict.errorMessage": "Cette recherche a la même URL qu'un alias hérité. Désactiver l'alias pour résoudre cette erreur : {json}", "discover.savedSearchURLConflictCallout.objectNoun": "Recherche {savedSearch}", "discover.searchGenerationWithDescription": "Tableau généré par la recherche {searchTitle}", "discover.searchGenerationWithDescriptionGrid": "Tableau généré par la recherche {searchTitle} ({searchDescription})", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 1ed18a64287a6..f08cef9461776 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -3187,7 +3187,6 @@ "discover.savedSearch.savedObjectName": "保存検索", "discover.savedSearchAliasMatchRedirect.objectNoun": "{savedSearch}検索", "discover.savedSearchEmbeddable.action.viewSavedSearch.displayName": "Discoverで開く", - "discover.savedSearchEmbeddable.legacyURLConflict.errorMessage": "この検索にはレガシーエイリアスと同じURLがあります。このエラーを解決するには、エイリアスを無効にしてください:{json}", "discover.savedSearchURLConflictCallout.objectNoun": "{savedSearch}検索", "discover.searchGenerationWithDescription": "検索{searchTitle}で生成されたテーブル", "discover.searchGenerationWithDescriptionGrid": "検索{searchTitle}で生成されたテーブル({searchDescription})", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 69af29fea4b0a..9c77c51ccf1e1 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -3190,7 +3190,6 @@ "discover.savedSearch.savedObjectName": "已保存搜索", "discover.savedSearchAliasMatchRedirect.objectNoun": "{savedSearch} 搜索", "discover.savedSearchEmbeddable.action.viewSavedSearch.displayName": "在 Discover 中打开", - "discover.savedSearchEmbeddable.legacyURLConflict.errorMessage": "此搜索具有与旧版别名相同的 URL。请禁用别名以解决此错误:{json}", "discover.savedSearchURLConflictCallout.objectNoun": "{savedSearch} 搜索", "discover.searchGenerationWithDescription": "搜索 {searchTitle} 生成的表", "discover.searchGenerationWithDescriptionGrid": "搜索 {searchTitle} 生成的表({searchDescription})",