mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
fix(code/frontend): should update search results if search options change (#41232)
This commit is contained in:
parent
376240d81b
commit
59297beb17
3 changed files with 33 additions and 14 deletions
|
@ -468,7 +468,9 @@ export class CodeQueryBar extends Component<Props, State> {
|
|||
/>
|
||||
<SearchOptions
|
||||
defaultRepoOptions={this.props.defaultRepoOptions}
|
||||
defaultSearchScope={this.props.currentRepository}
|
||||
defaultSearchScope={
|
||||
this.props.currentRepository || this.props.searchOptions.defaultRepoScope
|
||||
}
|
||||
repositorySearch={this.props.repositorySearch}
|
||||
saveSearchOptions={this.props.saveSearchOptions}
|
||||
repoSearchResults={this.props.repoSearchResults}
|
||||
|
|
|
@ -40,17 +40,14 @@ export class SearchBar extends React.PureComponent<Props> {
|
|||
|
||||
// Update the url and push to history as well.
|
||||
const previousQueries = querystring.parse(history.location.search.replace('?', ''));
|
||||
const queries: any =
|
||||
repoScopes.length === 0
|
||||
? {
|
||||
...previousQueries,
|
||||
q: query,
|
||||
}
|
||||
: {
|
||||
...previousQueries,
|
||||
q: query,
|
||||
repoScope: repoScopes,
|
||||
};
|
||||
const queries: any = {
|
||||
...previousQueries,
|
||||
repoScope: repoScopes,
|
||||
q: query,
|
||||
};
|
||||
if (repoScopes.length === 0) {
|
||||
delete queries.repoScope;
|
||||
}
|
||||
history.push(
|
||||
url.format({
|
||||
pathname: '/search',
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
*/
|
||||
|
||||
import produce from 'immer';
|
||||
|
||||
import querystring from 'querystring';
|
||||
import { Action, handleActions } from 'redux-actions';
|
||||
import { history } from '../utils/url';
|
||||
|
||||
import {
|
||||
DocumentSearchResult,
|
||||
|
@ -33,6 +34,7 @@ import {
|
|||
turnOffDefaultRepoScope,
|
||||
turnOnDefaultRepoScope,
|
||||
} from '../actions';
|
||||
import { RepositoryUtils } from '../../common/repository_utils';
|
||||
|
||||
export interface SearchState {
|
||||
scope: SearchScope;
|
||||
|
@ -51,12 +53,30 @@ export interface SearchState {
|
|||
|
||||
const repositories: Repository[] = [];
|
||||
|
||||
const getRepoScopeFromUrl = () => {
|
||||
const { repoScope } = querystring.parse(history.location.search.replace('?', ''));
|
||||
if (repoScope) {
|
||||
return String(repoScope)
|
||||
.split(',')
|
||||
.map(r => ({
|
||||
uri: r,
|
||||
org: RepositoryUtils.orgNameFromUri(r),
|
||||
name: RepositoryUtils.repoNameFromUri(r),
|
||||
})) as Repository[];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const initialState: SearchState = {
|
||||
query: '',
|
||||
isLoading: false,
|
||||
isScopeSearchLoading: false,
|
||||
scope: SearchScope.DEFAULT,
|
||||
searchOptions: { repoScope: [], defaultRepoScopeOn: false },
|
||||
searchOptions: {
|
||||
repoScope: getRepoScopeFromUrl(),
|
||||
defaultRepoScopeOn: false,
|
||||
},
|
||||
scopeSearchResults: { repositories, total: 0, took: 0 },
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue