-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Loading and Editing Saved Searches in Discover #8306
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
* under the License. | ||
*/ | ||
|
||
import { QueryStringContract } from 'src/plugins/data/public/'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately we should import public into common folder. the compiler might complain about this. we should consider taking the required function from the query string service (cache dataset) and exporting it in the common folder so that it's reusable by the dataset service and search source service There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where would i see it complaining? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am surprised too that CI is not failing. |
||
import { migrateLegacyQuery } from './migrate_legacy_query'; | ||
import { SearchSource, SearchSourceDependencies } from './search_source'; | ||
import { IndexPatternsContract } from '../../index_patterns/index_patterns'; | ||
|
@@ -56,6 +57,18 @@ | |
) => async (searchSourceFields: SearchSourceFields = {}) => { | ||
const fields = { ...searchSourceFields }; | ||
|
||
// When we load a saved search and the saved search contains a non index pattern data source this step creates the temperary index patterns and sets the appriopriate query | ||
if ( | ||
searchSourceDependencies.queryStringService && | ||
AMoo-Miki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fields.query?.dataset && | ||
fields.query?.dataset?.type !== 'INDEX_PATTERN' && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: at this point, don't need ? in ?.dataset |
||
!indexPatterns.isPresentInCache(fields.query.dataset.id) | ||
) { | ||
await searchSourceDependencies.queryStringService | ||
.getDatasetService() | ||
.cacheDataset(fields.query?.dataset); | ||
LDrago27 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this do the right thing if dataset is undefined? |
||
} | ||
|
||
// hydrating index pattern | ||
if (fields.index && typeof fields.index === 'string') { | ||
fields.index = await indexPatterns.get(searchSourceFields.index as any); | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import { DatasetSelector as ConnectedDatasetSelector } from './index'; | |||
import { DatasetSelector } from './dataset_selector'; | ||||
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; | ||||
import { Dataset } from '../../../common'; | ||||
import { of } from 'rxjs'; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
jest.mock('../../../../opensearch_dashboards_react/public', () => ({ | ||||
useOpenSearchDashboards: jest.fn(), | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,11 +240,10 @@ export default class QueryEditorUI extends Component<Props, State> { | |
|
||
if (!isEqual(this.props.query.dataset, prevQuery.dataset)) { | ||
if (this.inputRef) { | ||
const newQuery = this.queryString.getInitialQuery(); | ||
const newQueryString = newQuery.query; | ||
if (this.inputRef.getValue() !== newQueryString) { | ||
const newQueryString = this.props.query.query; | ||
if (this.inputRef.getValue() !== newQueryString && typeof newQueryString === 'string') { | ||
ashwin-pc marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is inputRef.getValue() behind prop because its a controlled input (e.g. its value is defined by props)? |
||
this.inputRef.setValue(newQueryString); | ||
this.onSubmit(newQuery); | ||
this.onSubmit(this.props.query); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
import { useLocation } from 'react-router-dom'; | ||
import { RequestAdapter } from '../../../../../inspector/public'; | ||
import { DiscoverViewServices } from '../../../build_services'; | ||
import { search } from '../../../../../data/public'; | ||
import { QueryState, search } from '../../../../../data/public'; | ||
import { validateTimeRange } from '../../helpers/validate_time_range'; | ||
import { updateSearchSource } from './update_search_source'; | ||
import { useIndexPattern } from './use_index_pattern'; | ||
|
@@ -354,16 +354,21 @@ | |
const savedSearchInstance = await getSavedSearchById(savedSearchId); | ||
setSavedSearch(savedSearchInstance); | ||
|
||
// if saved search does not exist, do not atempt to sync filters and query from savedObject | ||
if (!savedSearch) { | ||
// if saved search does not exist, or the URL has filter tyhen don't sync the saved search state with that | ||
if (!savedSearchInstance || !savedSearchId) { | ||
return; | ||
} | ||
|
||
// sync initial app filters from savedObject to filterManager | ||
const filters = cloneDeep(savedSearchInstance.searchSource.getOwnField('filter')); | ||
// Sync Query from the saved search | ||
const query = | ||
savedSearchInstance.searchSource.getField('query') || | ||
data.query.queryString.getDefaultQuery(); | ||
|
||
data.query.queryString.setQuery(query); | ||
|
||
// Sync Filters from the saved search | ||
const filters = cloneDeep(savedSearchInstance.searchSource.getOwnField('filter')); | ||
|
||
const actualFilters = []; | ||
|
||
if (filters !== undefined) { | ||
|
@@ -373,8 +378,11 @@ | |
} | ||
} | ||
|
||
filterManager.setAppFilters(actualFilters); | ||
data.query.queryString.setQuery(query); | ||
// Filters in URL are higher priority than the filters in saved search | ||
const urlFilters = (osdUrlStateStorage.get('_q') as QueryState)?.filters ?? []; | ||
if (!Array.isArray(urlFilters) || urlFilters.length === 0) { | ||
filterManager.setAppFilters(actualFilters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't we want to make sure to call |
||
} | ||
|
||
if (savedSearchInstance?.id) { | ||
chrome.recentlyAccessed.add( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
return !!indexPatternCache.get(id);