Skip to content

Commit

Permalink
[Discover] Removing SavedObject usage for savedSearch (elastic#112983)
Browse files Browse the repository at this point in the history
* [Discover] Step 2 - remove SavedObjectLoader

* Fix PR comments

* fix test names

* fix ts error

* add handling of missed 'so'

* add Embeddable error

* fix jest

* add DiscoverError component

* fix Joe comments

* add search params

* add throwErrorOnUrlConflict util method

* add error handling into transform plugin

* do some updates

* add spaces into visualize, visualizations

* fix Tim's comment

* pass false into createGetterSetter for getSpaces

* Fix comments

* Fix lint

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Uladzislau Lasitsa <Uladzislau_Lasitsa@epam.com>
# Conflicts:
#	src/plugins/discover/public/application/apps/context/services/context.ts
  • Loading branch information
alexwizp committed Oct 13, 2021
1 parent 7026ae8 commit d0e7c42
Show file tree
Hide file tree
Showing 74 changed files with 1,323 additions and 282 deletions.
4 changes: 2 additions & 2 deletions src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"savedObjects",
"indexPatternFieldEditor"
],
"optionalPlugins": ["home", "share", "usageCollection"],
"requiredBundles": ["kibanaUtils", "home", "kibanaReact", "fieldFormats"],
"optionalPlugins": ["home", "share", "usageCollection", "spaces"],
"requiredBundles": ["kibanaUtils", "home", "kibanaReact", "fieldFormats", "dataViews"],
"extraPublicDirs": ["common"],
"owner": {
"name": "Data Discovery",
Expand Down
34 changes: 0 additions & 34 deletions src/plugins/discover/public/__mocks__/saved_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,10 @@ import { indexPatternWithTimefieldMock } from './index_pattern_with_timefield';

export const savedSearchMock = {
id: 'the-saved-search-id',
type: 'search',
attributes: {
title: 'the-saved-search-title',
kibanaSavedObjectMeta: {
searchSourceJSON:
'{"highlightAll":true,"version":true,"query":{"query":"foo : \\"bar\\" ","language":"kuery"},"filter":[],"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}',
},
},
references: [
{
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
id: 'the-index-pattern-id',
},
],
migrationVersion: { search: '7.5.0' },
error: undefined,
searchSource: createSearchSourceMock({ index: indexPatternMock }),
} as unknown as SavedSearch;

export const savedSearchMockWithTimeField = {
id: 'the-saved-search-id-with-timefield',
type: 'search',
attributes: {
title: 'the-saved-search-title',
kibanaSavedObjectMeta: {
searchSourceJSON:
'{"highlightAll":true,"version":true,"query":{"query":"foo : \\"bar\\" ","language":"kuery"},"filter":[],"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}',
},
},
references: [
{
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
id: 'the-index-pattern-id',
},
],
migrationVersion: { search: '7.5.0' },
error: undefined,
searchSource: createSearchSourceMock({ index: indexPatternWithTimefieldMock }),
} as unknown as SavedSearch;
2 changes: 0 additions & 2 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
SAMPLE_SIZE_SETTING,
SORT_DEFAULT_ORDER_SETTING,
} from '../../common';
import { savedSearchMock } from './saved_search';
import { UI_SETTINGS } from '../../../data/common';
import { TopNavMenu } from '../../../navigation/public';
import { FORMATS_UI_SETTINGS } from 'src/plugins/field_formats/common';
Expand Down Expand Up @@ -78,7 +77,6 @@ export const discoverServiceMock = {
editIndexPattern: jest.fn(),
},
},
getSavedSearchById: (id?: string) => Promise.resolve(savedSearchMock),
navigation: {
ui: { TopNavMenu },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { Filter, IndexPattern, IndexPatternsContract, SearchSource } from 'src/plugins/data/public';
import {
Filter,
IndexPattern,
IndexPatternsContract,
ISearchSource
} from 'src/plugins/data/public';
import { reverseSortDir, SortDirection } from './utils/sorting';
import { convertIsoToMillis, extractNanos } from './utils/date_conversion';
import { fetchHitsInInterval } from './utils/fetch_hits_in_interval';
Expand Down Expand Up @@ -58,7 +63,7 @@ function fetchContextProvider(indexPatterns: IndexPatternsContract, useNewFields
}
const indexPattern = await indexPatterns.get(indexPatternId);
const { data } = getServices();
const searchSource = data.search.searchSource.createEmpty() as SearchSource;
const searchSource = data.search.searchSource.createEmpty();
updateSearchSource(searchSource, indexPattern, filters, Boolean(useNewFieldsApi));
const sortDirToApply = type === SurrDocType.SUCCESSORS ? sortDir : reverseSortDir(sortDir);

Expand Down Expand Up @@ -110,7 +115,7 @@ function fetchContextProvider(indexPatterns: IndexPatternsContract, useNewFields
}

export function updateSearchSource(
searchSource: SearchSource,
searchSource: ISearchSource,
indexPattern: IndexPattern,
filters: Filter[],
useNewFieldsApi: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function DiscoverDocumentsComponent({
sort={state.sort || []}
isLoading={isLoading}
searchDescription={savedSearch.description}
sharedItemTitle={savedSearch.lastSavedTitle}
sharedItemTitle={savedSearch.title}
onAddColumn={onAddColumn}
onFilter={onAddFilter as DocViewFilterFn}
onMoveColumn={onMoveColumn}
Expand All @@ -156,7 +156,7 @@ function DiscoverDocumentsComponent({
sort={(state.sort as SortPairArr[]) || []}
sampleSize={sampleSize}
searchDescription={savedSearch.description}
searchTitle={savedSearch.lastSavedTitle}
searchTitle={savedSearch.title}
setExpandedDoc={setExpandedDoc}
showTimeCol={showTimeCol}
services={services}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import { useDataGridColumns } from '../../../../helpers/use_data_grid_columns';
import { DiscoverDocuments } from './discover_documents';
import { FetchStatus } from '../../../../types';
import { useDataState } from '../../utils/use_data_state';
import {
SavedSearchURLConflictCallout,
useSavedSearchAliasMatchRedirect,
} from '../../../../../saved_searches';

/**
* Local storage key for sidebar persistence state
Expand All @@ -65,10 +69,18 @@ export function DiscoverLayout({
state,
stateContainer,
}: DiscoverLayoutProps) {
const { trackUiMetric, capabilities, indexPatterns, data, uiSettings, filterManager, storage } =
services;
const {
trackUiMetric,
capabilities,
indexPatterns,
data,
uiSettings,
filterManager,
storage,
history,
spaces,
} = services;
const { main$, charts$, totalHits$ } = savedSearchData$;

const [expandedDoc, setExpandedDoc] = useState<ElasticSearchHit | undefined>(undefined);
const [inspectorSession, setInspectorSession] = useState<InspectorSession | undefined>(undefined);
const fetchCounter = useRef<number>(0);
Expand All @@ -80,6 +92,8 @@ export function DiscoverLayout({
}
}, [dataState.fetchStatus]);

useSavedSearchAliasMatchRedirect({ savedSearch, spaces, history });

const timeField = useMemo(() => {
return indexPattern.type !== 'rollup' ? indexPattern.timeFieldName : undefined;
}, [indexPattern]);
Expand Down Expand Up @@ -174,6 +188,11 @@ export function DiscoverLayout({
resetSavedSearch={resetSavedSearch}
/>
<EuiPageBody className="dscPageBody" aria-describedby="savedSearchTitle">
<SavedSearchURLConflictCallout
savedSearch={savedSearch}
spaces={spaces}
history={history}
/>
<h1 id="savedSearchTitle" className="euiScreenReaderOnly">
{savedSearch.title}
</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { SavedObjectSaveModal, showSaveModal } from '../../../../../../../saved_objects/public';
import { SavedSearch } from '../../../../../saved_searches';
import { SavedSearch, SaveSavedSearchOptions } from '../../../../../saved_searches';
import { IndexPattern } from '../../../../../../../data/common';
import { DiscoverServices } from '../../../../../build_services';
import { GetStateReturn } from '../../services/discover_state';
Expand All @@ -27,11 +27,7 @@ async function saveDataSource({
indexPattern: IndexPattern;
navigateTo: (url: string) => void;
savedSearch: SavedSearch;
saveOptions: {
confirmOverwrite: boolean;
isTitleDuplicateConfirmed: boolean;
onTitleDuplicate: () => void;
};
saveOptions: SaveSavedSearchOptions;
services: DiscoverServices;
state: GetStateReturn;
}) {
Expand All @@ -47,14 +43,20 @@ async function saveDataSource({
}),
'data-test-subj': 'saveSearchSuccess',
});

if (savedSearch.id !== prevSavedSearchId) {
navigateTo(`/view/${encodeURIComponent(savedSearch.id)}`);
if (id !== prevSavedSearchId) {
navigateTo(`/view/${encodeURIComponent(id)}`);
} else {
// Update defaults so that "reload saved query" functions correctly
state.resetAppState();
services.chrome.docTitle.change(savedSearch.lastSavedTitle!);
setBreadcrumbsTitle(savedSearch, services.chrome);
services.chrome.docTitle.change(savedSearch.title!);

setBreadcrumbsTitle(
{
...savedSearch,
id: prevSavedSearchId ?? id,
},
services.chrome
);
}
}
}
Expand Down Expand Up @@ -106,11 +108,10 @@ export async function onSaveSearch({
}) => {
const currentTitle = savedSearch.title;
savedSearch.title = newTitle;
savedSearch.copyOnSave = newCopyOnSave;
const saveOptions = {
confirmOverwrite: false,
isTitleDuplicateConfirmed,
const saveOptions: SaveSavedSearchOptions = {
onTitleDuplicate,
copyOnSave: newCopyOnSave,
isTitleDuplicateConfirmed,
};
const response = await saveDataSource({
indexPattern,
Expand All @@ -133,7 +134,7 @@ export async function onSaveSearch({
<SavedObjectSaveModal
onSave={onSave}
onClose={() => {}}
title={savedSearch.title}
title={savedSearch.title ?? ''}
showCopyOnSave={!!savedSearch.id}
objectType={i18n.translate('discover.localMenu.saveSaveSearchObjectType', {
defaultMessage: 'search',
Expand Down
Loading

0 comments on commit d0e7c42

Please sign in to comment.