From 803d7d90de6145276ad8d1ba1a36bcfba841f7ba Mon Sep 17 00:00:00 2001 From: Farhan Attamimi Date: Tue, 23 Oct 2018 17:30:16 -0700 Subject: [PATCH 1/4] Use transformed queries from search extensions --- src/search/backend.tsx | 250 ++++++++++++++------------- src/search/results/SearchResults.tsx | 12 +- 2 files changed, 138 insertions(+), 124 deletions(-) diff --git a/src/search/backend.tsx b/src/search/backend.tsx index c8fba06bd0dc..1c5b673747c3 100644 --- a/src/search/backend.tsx +++ b/src/search/backend.tsx @@ -1,151 +1,161 @@ import { isEqual } from 'lodash' -import { Observable } from 'rxjs' -import { distinctUntilChanged, map, mergeMap } from 'rxjs/operators' +import { Observable, of } from 'rxjs' +import { catchError, distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators' import { SearchOptions } from '.' import { gql, queryGraphQL } from '../backend/graphql' import * as GQL from '../backend/graphqlschema' import { mutateConfigurationGraphQL } from '../configuration/backend' +import { ExtensionsControllerProps } from '../extensions/ExtensionsClientCommonContext' import { currentConfiguration } from '../settings/configuration' -import { createAggregateError } from '../util/errors' +import { asError, createAggregateError, ErrorLike } from '../util/errors' +import { SearchResults } from './results/SearchResults' -export function search(options: SearchOptions): Observable { - return queryGraphQL( - gql` - query Search($query: String!) { - search(query: $query) { - results { - __typename - limitHit - resultCount - approximateResultCount - missing { - name - } - cloning { - name - } - timedout { - name - } - indexUnavailable - dynamicFilters { - value - label - count - limitHit - kind - } - results { - ... on Repository { +export function search( + options: SearchOptions, + { extensionsController }: ExtensionsControllerProps +): Observable { + return extensionsController.registries.search.transformQuery(options.query).pipe( + switchMap(query => + queryGraphQL( + gql` + query Search($query: String!) { + search(query: $query) { + results { __typename - id - name - url - } - ... on FileMatch { - __typename - file { - path - url - commit { - oid - } - } - repository { - name - url - } limitHit - symbols { + resultCount + approximateResultCount + missing { name - containerName - url - kind - } - lineMatches { - preview - lineNumber - offsetAndLengths } - } - ... on CommitSearchResult { - __typename - refs { + cloning { name - displayName - prefix - repository { - name - } } - sourceRefs { + timedout { name - displayName - prefix - repository { - name - } - } - messagePreview { - value - highlights { - line - character - length - } } - diffPreview { + indexUnavailable + dynamicFilters { value - highlights { - line - character - length - } + label + count + limitHit + kind } - commit { - id - repository { + results { + ... on Repository { + __typename + id name url } - oid - abbreviatedOID - author { - person { + ... on FileMatch { + __typename + file { + path + url + commit { + oid + } + } + repository { + name + url + } + limitHit + symbols { + name + containerName + url + kind + } + lineMatches { + preview + lineNumber + offsetAndLengths + } + } + ... on CommitSearchResult { + __typename + refs { + name displayName - avatarURL + prefix + repository { + name + } + } + sourceRefs { + name + displayName + prefix + repository { + name + } + } + messagePreview { + value + highlights { + line + character + length + } + } + diffPreview { + value + highlights { + line + character + length + } + } + commit { + id + repository { + name + url + } + oid + abbreviatedOID + author { + person { + displayName + avatarURL + } + date + } + message + url + tree(path: "") { + canonicalURL + } } - date } - message - url - tree(path: "") { - canonicalURL + } + alert { + title + description + proposedQueries { + description + query } } + elapsedMilliseconds } } - alert { - title - description - proposedQueries { - description - query - } - } - elapsedMilliseconds } - } - } - `, - { query: options.query } - ).pipe( - map(({ data, errors }) => { - if (!data || !data.search || !data.search.results) { - throw createAggregateError(errors) - } - return data.search.results - }) + `, + { query } + ).pipe( + map(({ data, errors }) => { + if (!data || !data.search || !data.search.results) { + throw createAggregateError(errors) + } + return data.search.results + }), + catchError(error => [asError(error)]) + ) + ) ) } diff --git a/src/search/results/SearchResults.tsx b/src/search/results/SearchResults.tsx index 78fb5fb8d807..ed21cc4b5597 100644 --- a/src/search/results/SearchResults.tsx +++ b/src/search/results/SearchResults.tsx @@ -6,8 +6,10 @@ import { catchError, distinctUntilChanged, filter, map, startWith, switchMap, ta import { parseSearchURLQuery, SearchOptions } from '..' import * as GQL from '../../backend/graphqlschema' import { PageTitle } from '../../components/PageTitle' +import { ExtensionsControllerProps } from '../../extensions/ExtensionsClientCommonContext' import { currentConfiguration } from '../../settings/configuration' import { eventLogger } from '../../tracking/eventLogger' +import { isErrorLike } from '../../util/errors' import { search } from '../backend' import { FilterChip } from '../FilterChip' import { isSearchResults, submitSearch, toggleSearchFilter } from '../helpers' @@ -17,7 +19,7 @@ import { SearchResultsListOld } from './SearchResultsListOld' const UI_PAGE_SIZE = 75 -interface SearchResultsProps { +interface SearchResultsProps extends ExtensionsControllerProps { authenticatedUser: GQL.IUser | null location: H.Location history: H.History @@ -87,7 +89,7 @@ export class SearchResults extends React.Component @@ -95,8 +97,10 @@ export class SearchResults extends React.Component 0, + results_count: isErrorLike(results) ? 0 : results.results.length, + any_cloning: isErrorLike(results) + ? false + : results.cloning.length > 0, }, }, }), From d5c155ccc6c189a59fabc2c59c5372b3a2df0201 Mon Sep 17 00:00:00 2001 From: Farhan Attamimi Date: Tue, 23 Oct 2018 22:35:54 -0700 Subject: [PATCH 2/4] Fix unused --- src/search/backend.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/search/backend.tsx b/src/search/backend.tsx index 1c5b673747c3..386e79e378ed 100644 --- a/src/search/backend.tsx +++ b/src/search/backend.tsx @@ -1,5 +1,5 @@ import { isEqual } from 'lodash' -import { Observable, of } from 'rxjs' +import { Observable } from 'rxjs' import { catchError, distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators' import { SearchOptions } from '.' import { gql, queryGraphQL } from '../backend/graphql' @@ -8,7 +8,6 @@ import { mutateConfigurationGraphQL } from '../configuration/backend' import { ExtensionsControllerProps } from '../extensions/ExtensionsClientCommonContext' import { currentConfiguration } from '../settings/configuration' import { asError, createAggregateError, ErrorLike } from '../util/errors' -import { SearchResults } from './results/SearchResults' export function search( options: SearchOptions, From 4ac38ac2f97ded802bed88efdd6793897036dd49 Mon Sep 17 00:00:00 2001 From: Farhan Attamimi Date: Wed, 24 Oct 2018 18:44:53 -0700 Subject: [PATCH 3/4] Document when search observable emits, rename registry --- src/search/backend.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/search/backend.tsx b/src/search/backend.tsx index 386e79e378ed..b6a86080d33a 100644 --- a/src/search/backend.tsx +++ b/src/search/backend.tsx @@ -13,7 +13,10 @@ export function search( options: SearchOptions, { extensionsController }: ExtensionsControllerProps ): Observable { - return extensionsController.registries.search.transformQuery(options.query).pipe( + /** + * Emits whenever a search is executed, and whenever a search extension is registered as a search provider. + */ + return extensionsController.registries.queryTransformer.transformQuery(options.query).pipe( switchMap(query => queryGraphQL( gql` From 4679715d1e7f9410583c7dd04d3c4327c4a66453 Mon Sep 17 00:00:00 2001 From: Farhan Attamimi Date: Mon, 29 Oct 2018 09:36:16 -0700 Subject: [PATCH 4/4] docs: update --- src/search/backend.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search/backend.tsx b/src/search/backend.tsx index b6a86080d33a..8cd02c34c37d 100644 --- a/src/search/backend.tsx +++ b/src/search/backend.tsx @@ -14,7 +14,7 @@ export function search( { extensionsController }: ExtensionsControllerProps ): Observable { /** - * Emits whenever a search is executed, and whenever a search extension is registered as a search provider. + * Emits whenever a search is executed, and whenever an extension registers a query transformer. */ return extensionsController.registries.queryTransformer.transformQuery(options.query).pipe( switchMap(query =>