Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit bb926a6

Browse files
Search-results page: Fix search result layout block spacings (#60368)
* Fix search result page layout * Add max-size to the preview panel * Remove unused CSS * Fix wrapping adds extra spacing when it's empty * Fix paddings values for meta info block * hide badge on synthetic count filter * Fix spacing for getting started info tour * Remove legacy css class --------- Co-authored-by: Camden Cheek <camden@ccheek.com>
1 parent d99889d commit bb926a6

File tree

8 files changed

+71
-61
lines changed

8 files changed

+71
-61
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.root {
2+
display: flex;
3+
flex-direction: column;
4+
gap: 1rem;
5+
}

client/branded/src/search-ui/results/StreamingSearchResultsFooter.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,46 @@ import { Alert, LoadingSpinner, Code, Text, H2, H3, ErrorAlert } from '@sourcegr
77

88
import { StreamingProgressCount } from './progress/StreamingProgressCount'
99

10-
import styles from './StreamingSearchResultsList.module.scss'
10+
import styles from './StreamingSearchResultsFooter.module.scss'
1111

1212
export const StreamingSearchResultFooter: React.FunctionComponent<
1313
React.PropsWithChildren<{
1414
results?: AggregateStreamingSearchResults
1515
children?: React.ReactChild | React.ReactChild[]
16+
className?: string
1617
}>
17-
> = ({ results, children }) => {
18+
> = ({ results, children, className }) => {
1819
const skippedDisplay =
1920
results?.state === 'complete' && results.progress.skipped.find(skipped => skipped.reason.includes('display'))
2021
const resultLimitHit =
2122
results?.state === 'complete' && results.progress.skipped.some(skipped => skipped.reason.includes('-limit'))
2223

2324
return (
24-
<div className={classNames(styles.contentCentered, 'd-flex flex-column align-items-center')}>
25+
<div className={classNames(className, styles.root)}>
2526
{(!results || results?.state === 'loading') && (
26-
<div className="text-center my-4" data-testid="loading-container">
27+
<div className="text-center" data-testid="loading-container">
2728
<LoadingSpinner />
2829
</div>
2930
)}
3031

3132
{results?.state === 'complete' && results?.results.length > 0 && (
32-
<StreamingProgressCount progress={results.progress} state={results.state} className="mt-4 mb-2" />
33+
<StreamingProgressCount progress={results.progress} state={results.state} />
3334
)}
3435

3536
{results?.state === 'error' && (
3637
<ErrorAlert className="m-3" data-testid="search-results-list-error" error={results.error} />
3738
)}
3839

3940
{results?.state === 'complete' && !results.alert && results?.results.length === 0 && (
40-
<div className="pr-3 mt-3 align-self-stretch">
41-
<Alert variant="info">
42-
<H3 as={H2} className="m-0 py-1">
43-
No results matched your search.
44-
</H3>
45-
</Alert>
46-
</div>
41+
<Alert variant="info">
42+
<H3 as={H2} className="m-0 py-1">
43+
No results matched your search.
44+
</H3>
45+
</Alert>
4746
)}
4847

4948
{(skippedDisplay || resultLimitHit) && (
50-
<Alert className="d-flex flex-column m-3" variant="info">
49+
<Alert className="d-flex flex-column" variant="info">
5150
{skippedDisplay && (
5251
<Text className="m-0">
5352
<strong>Display limit hit.</strong> {skippedDisplay.message}
@@ -61,6 +60,8 @@ export const StreamingSearchResultFooter: React.FunctionComponent<
6160
)}
6261
</Alert>
6362
)}
63+
64+
{children}
6465
</div>
6566
)
6667
}

client/branded/src/search-ui/results/StreamingSearchResultsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const StreamingSearchResultsList: React.FunctionComponent<
282282
</div>
283283

284284
{itemsToShow >= resultsNumber && (
285-
<StreamingSearchResultFooter results={results}>
285+
<StreamingSearchResultFooter results={results} className="m-3">
286286
<>
287287
{results?.state === 'complete' && resultsNumber === 0 && (
288288
<NoResultsPage

client/branded/src/search-ui/results/filters/components/dynamic-filter/SearchDynamicFilter.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ const DynamicFilterItem: FC<DynamicFilterItemProps> = props => {
213213
onClick={() => onClick(filter, selected)}
214214
>
215215
<span className={styles.itemText}>{renderItem ? renderItem(filter, selected) : filter.label}</span>
216-
<DynamicFilterBadge exhaustive={filter.exhaustive} count={filter.count} />
216+
{/* NOTE: filter.count should _only_ be zero for the synthetic count filter. */}
217+
{filter.count > 0 && <DynamicFilterBadge exhaustive={filter.exhaustive} count={filter.count} />}
217218
{selected && <Icon svgPath={mdiClose} aria-hidden={true} className="ml-1 flex-shrink-0" />}
218219
</Button>
219220
</li>

client/web/src/search/results/components/new-search-content/NewSearchContent.module.scss

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
.content {
127127
grid-area: contents;
128128
overflow: auto;
129-
padding: 1rem;
130129

131130
&::-webkit-scrollbar {
132131
width: 0.5rem;
@@ -161,17 +160,10 @@
161160
}
162161
}
163162

164-
&--list {
165-
// Compensate content parent block paddings in order
166-
// to have paddings anywhere but content list with search matches
167-
margin: -1rem;
168-
169-
// This is needed because search list may have search result matches
170-
// block which have sticky header elements, sticky top position doesn't
171-
// take into account negative margins so we
172-
[data-result-header] {
173-
top: -1rem;
174-
}
163+
&-meta-info {
164+
display: flex;
165+
flex-direction: column;
166+
gap: 0.5rem;
175167
}
176168
}
177169

client/web/src/search/results/components/new-search-content/NewSearchContent.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
useCallback,
77
useEffect,
88
useLayoutEffect,
9-
useRef,
109
useMemo,
10+
useRef,
1111
} from 'react'
1212

1313
import { mdiClose } from '@mdi/js'
@@ -38,7 +38,7 @@ import {
3838
import { SettingsCascadeProps } from '@sourcegraph/shared/src/settings/settings'
3939
import { NOOP_TELEMETRY_SERVICE, TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
4040
import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent'
41-
import { Button, Icon, H2, H4, useScrollManager, Panel, useLocalStorage, Link } from '@sourcegraph/wildcard'
41+
import { Button, H2, H4, Icon, Link, Panel, useLocalStorage, useScrollManager } from '@sourcegraph/wildcard'
4242

4343
import { AuthenticatedUser } from '../../../../auth'
4444
import { useKeywordSearch } from '../../../../featureFlags/useFeatureFlag'
@@ -259,30 +259,33 @@ export const NewSearchContent: FC<NewSearchContentProps> = props => {
259259
aria-label="Aggregation results panel"
260260
onQuerySubmit={onQuerySubmit}
261261
telemetryService={telemetryService}
262+
className="m-3"
262263
/>
263264
)}
264265

265266
{aggregationUIMode !== AggregationUIMode.SearchPage && (
266-
<>
267+
<div className={styles.contentMetaInfo}>
267268
<DidYouMean
268269
telemetryService={props.telemetryService}
269270
query={submittedURLQuery}
270271
patternType={patternType}
271272
caseSensitive={caseSensitive}
272273
selectedSearchContextSpec={props.selectedSearchContextSpec}
274+
className="m-2"
273275
/>
274276

275277
{results?.alert?.kind && isSmartSearchAlert(results.alert.kind) && (
276-
<SmartSearch alert={results?.alert} onDisableSmartSearch={onDisableSmartSearch} />
278+
<SmartSearch
279+
alert={results?.alert}
280+
onDisableSmartSearch={onDisableSmartSearch}
281+
className="m-2"
282+
/>
277283
)}
278284

279-
<GettingStartedTour.Info
280-
className="mt-2 mb-3"
281-
isSourcegraphDotCom={props.isSourcegraphDotCom}
282-
/>
285+
<GettingStartedTour.Info className="m-2" isSourcegraphDotCom={props.isSourcegraphDotCom} />
283286

284287
{results?.alert && (!results?.alert.kind || !isSmartSearchAlert(results.alert.kind)) && (
285-
<div className={classNames(styles.alertArea, 'mt-4')}>
288+
<div className={classNames(styles.alertArea, 'm-2')}>
286289
{results?.alert?.kind === 'unowned-results' ? (
287290
<UnownedResultsAlert
288291
alertTitle={results.alert.title}
@@ -301,30 +304,31 @@ export const NewSearchContent: FC<NewSearchContentProps> = props => {
301304
)}
302305
</div>
303306
)}
307+
</div>
308+
)}
304309

305-
<StreamingSearchResultsList
306-
telemetryService={telemetryService}
307-
platformContext={platformContext}
308-
settingsCascade={settingsCascade}
309-
searchContextsEnabled={searchContextsEnabled}
310-
fetchHighlightedFileLineRanges={fetchHighlightedFileLineRanges}
311-
isSourcegraphDotCom={isSourcegraphDotCom}
312-
enableRepositoryMetadata={enableRepositoryMetadata}
313-
results={results}
314-
allExpanded={allExpanded}
315-
executedQuery={location.search}
316-
prefetchFileEnabled={true}
317-
prefetchFile={prefetchFile}
318-
enableKeyboardNavigation={true}
319-
showQueryExamplesOnNoResultsPage={true}
320-
queryState={queryState}
321-
buildSearchURLQueryFromQueryState={buildSearchURLQueryFromQueryState}
322-
selectedSearchContextSpec={selectedSearchContextSpec}
323-
logSearchResultClicked={onLogSearchResultClick}
324-
queryExamplesPatternType={patternType}
325-
className={styles.contentList}
326-
/>
327-
</>
310+
{aggregationUIMode !== AggregationUIMode.SearchPage && (
311+
<StreamingSearchResultsList
312+
telemetryService={telemetryService}
313+
platformContext={platformContext}
314+
settingsCascade={settingsCascade}
315+
searchContextsEnabled={searchContextsEnabled}
316+
fetchHighlightedFileLineRanges={fetchHighlightedFileLineRanges}
317+
isSourcegraphDotCom={isSourcegraphDotCom}
318+
enableRepositoryMetadata={enableRepositoryMetadata}
319+
results={results}
320+
allExpanded={allExpanded}
321+
executedQuery={location.search}
322+
prefetchFileEnabled={true}
323+
prefetchFile={prefetchFile}
324+
enableKeyboardNavigation={true}
325+
showQueryExamplesOnNoResultsPage={true}
326+
queryState={queryState}
327+
buildSearchURLQueryFromQueryState={buildSearchURLQueryFromQueryState}
328+
selectedSearchContextSpec={selectedSearchContextSpec}
329+
logSearchResultClicked={onLogSearchResultClick}
330+
queryExamplesPatternType={patternType}
331+
/>
328332
)}
329333
</div>
330334

@@ -403,6 +407,7 @@ const FilePreviewPanel: FC<FilePreviewPanelProps> = props => {
403407
<Panel
404408
defaultSize={300}
405409
minSize={256}
410+
maxSize={600}
406411
position="right"
407412
storageKey="file preview"
408413
ariaLabel="File sidebar"

client/web/src/search/suggestion/DidYouMean.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useMemo } from 'react'
22

33
import { mdiArrowRight } from '@mdi/js'
4+
import classNames from 'classnames'
45

56
import { SyntaxHighlightedSearchQuery } from '@sourcegraph/branded'
67
import { ALL_LANGUAGES } from '@sourcegraph/common'
@@ -126,13 +127,15 @@ interface DidYouMeanProps
126127
Pick<SearchContextProps, 'selectedSearchContextSpec'>,
127128
TelemetryProps {
128129
query: string
130+
className?: string
129131
}
130132

131133
export const DidYouMean: React.FunctionComponent<React.PropsWithChildren<DidYouMeanProps>> = ({
132134
telemetryService,
133135
query,
134136
patternType,
135137
caseSensitive,
138+
className,
136139
selectedSearchContextSpec,
137140
}) => {
138141
const suggestions = useMemo(() => getQuerySuggestions(query, patternType), [query, patternType])
@@ -145,7 +148,7 @@ export const DidYouMean: React.FunctionComponent<React.PropsWithChildren<DidYouM
145148

146149
if (suggestions.length > 0) {
147150
return (
148-
<div className={styles.root}>
151+
<div className={classNames(className, styles.root)}>
149152
<ul className={styles.container}>
150153
{suggestions.map(suggestion => {
151154
const builtURLQuery = buildSearchURLQuery(

client/web/src/search/suggestion/SmartSearch.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MouseEvent, useCallback } from 'react'
22

33
import { mdiChevronDown, mdiChevronUp, mdiArrowRight } from '@mdi/js'
4+
import classNames from 'classnames'
45

56
import { smartSearchIconSvgPath, SyntaxHighlightedSearchQuery } from '@sourcegraph/branded'
67
import { pluralize, formatSearchParameters } from '@sourcegraph/common'
@@ -29,6 +30,7 @@ import styles from './QuerySuggestion.module.scss'
2930
interface SmartSearchProps {
3031
alert: Required<AggregateStreamingSearchResults>['alert'] | undefined
3132
onDisableSmartSearch: () => void
33+
className?: string
3234
}
3335

3436
const alertContent: {
@@ -65,6 +67,7 @@ const alertContent: {
6567
export const SmartSearch: React.FunctionComponent<React.PropsWithChildren<SmartSearchProps>> = ({
6668
alert,
6769
onDisableSmartSearch,
70+
className,
6871
}) => {
6972
const [isCollapsed, setIsCollapsed] = useTemporarySetting('search.results.collapseSmartSearch')
7073

@@ -86,7 +89,7 @@ export const SmartSearch: React.FunctionComponent<React.PropsWithChildren<SmartS
8689
const content = alertContent[alert.kind](alert.proposedQueries?.length || 0)
8790

8891
return (
89-
<div className={styles.root}>
92+
<div className={classNames(className, styles.root)}>
9093
<Collapse isOpen={!isCollapsed} onOpenChange={opened => setIsCollapsed(!opened)}>
9194
<CollapseHeader className={styles.collapseButton}>
9295
<div className={styles.header}>

0 commit comments

Comments
 (0)