Skip to content

Commit

Permalink
Update callbacks, don't show saved query button
Browse files Browse the repository at this point in the history
  • Loading branch information
attfarhan committed Sep 28, 2020
1 parent 0498375 commit 513c0a7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
5 changes: 0 additions & 5 deletions web/src/routes.tsx
Expand Up @@ -86,11 +86,6 @@ export const routes: readonly LayoutRouteProps<any>[] = [
allExpanded={false}
showSavedQueryModal={false}
deployType={window.context.deployType}
onShowMoreResultsClick={() => undefined}
onExpandAllResultsToggle={() => undefined}
onSavedQueryModalClose={() => undefined}
onDidCreateSavedQuery={() => undefined}
onSaveQueryClick={() => undefined}
didSave={false}
/>
) : (
Expand Down
38 changes: 32 additions & 6 deletions web/src/search/SearchConsolePage.tsx
Expand Up @@ -20,8 +20,16 @@ import { parseSearchURL } from '.'

interface SearchConsolePageProps
extends ThemeProps,
SettingsCascadeProps,
Omit<SearchResultsListProps, 'extensionsController'>,
Omit<
SearchResultsListProps,
| 'extensionsController'
| 'onSavedQueryModalClose'
| 'onShowMoreResultsClick'
| 'onExpandAllResultsToggle'
| 'onSavedQueryModalClose'
| 'onDidCreateSavedQuery'
| 'onSaveQueryClick'
>,
ExtensionsControllerProps<'executeCommand' | 'services' | 'extHostAPI'> {
globbing: boolean
history: H.History
Expand All @@ -45,6 +53,9 @@ export const SearchConsolePage: React.FunctionComponent<SearchConsolePageProps>
[searchQueries, props.patternType, props.extensionsController]
)
)

const [allExpanded, setAllExpanded] = useState(false)

const options: Monaco.editor.IEditorOptions = {
readOnly: false,
minimap: {
Expand Down Expand Up @@ -92,7 +103,7 @@ export const SearchConsolePage: React.FunctionComponent<SearchConsolePageProps>
return () => disposable.dispose()
}, [editorInstance, searchQueries, props.history])

const calculateCount = (): number => {
const calculateCount = useCallback((): number => {
// This function can only get called if the results were successfully loaded,
// so casting is the right thing to do here
const results = resultsOrError as GQL.ISearchResults
Expand All @@ -104,8 +115,9 @@ export const SearchConsolePage: React.FunctionComponent<SearchConsolePageProps>
return Math.max(results.matchCount * 2, 1000)
}
return Math.max(results.matchCount * 2 || 0, 1000)
}
const showMoreResults = (): void => {
}, [resultsOrError])

const showMoreResults = useCallback((): void => {
// Requery with an increased max result count.
if (!editorInstance) {
return
Expand All @@ -121,7 +133,16 @@ export const SearchConsolePage: React.FunctionComponent<SearchConsolePageProps>
}
editorInstance.setValue(query)
props.history.push('/search/console?q=' + encodeURI(query))
}
}, [props.history, calculateCount, editorInstance])

const onExpandAllResultsToggle = useCallback((): void => {
setAllExpanded(allExpanded => {
props.telemetryService.log(allExpanded ? 'allResultsExpanded' : 'allResultsCollapsed')
return allExpanded
})
}, [setAllExpanded, props.telemetryService])

const voidCallback = useCallback(() => undefined, [])

return (
<div className="w-100 p-2">
Expand Down Expand Up @@ -152,7 +173,12 @@ export const SearchConsolePage: React.FunctionComponent<SearchConsolePageProps>
<SearchResultsList
{...props}
resultsOrError={resultsOrError}
onExpandAllResultsToggle={onExpandAllResultsToggle}
showSavedQueryButton={false}
onDidCreateSavedQuery={voidCallback}
onSavedQueryModalClose={voidCallback}
onShowMoreResultsClick={showMoreResults}
onSaveQueryClick={voidCallback}
/>
))}
</div>
Expand Down
3 changes: 2 additions & 1 deletion web/src/search/results/SearchResultsInfoBar.tsx
Expand Up @@ -42,6 +42,7 @@ interface SearchResultsInfoBarProps

showDotComMarketing: boolean
// Saved queries
showSavedQueryButton?: boolean
onDidCreateSavedQuery: () => void
onSaveQueryClick: () => void
didSave: boolean
Expand Down Expand Up @@ -216,7 +217,7 @@ export const SearchResultsInfoBar: React.FunctionComponent<SearchResultsInfoBarP
</li>
)}

{props.authenticatedUser && (
{props.showSavedQueryButton && props.authenticatedUser && (
<li className="nav-item">
<button
type="button"
Expand Down
1 change: 1 addition & 0 deletions web/src/search/results/SearchResultsList.tsx
Expand Up @@ -65,6 +65,7 @@ export interface SearchResultsListProps
onExpandAllResultsToggle: () => void

// Saved queries
showSavedQueryButton: boolean
showSavedQueryModal: boolean
onSavedQueryModalClose: () => void
onDidCreateSavedQuery: () => void
Expand Down

0 comments on commit 513c0a7

Please sign in to comment.