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

Commit ebaab12

Browse files
authored
feat(svelte): Add support for creating search jobs from search results (#64308)
Closes srch-838 This commit extends the search progress popover and adds the search jobs section. In the React version the UI for the popover differs slightly when search jobs are enabled vs not enabled. I decided to ignore the differences and only impolemented the style used for the 'search jobs enabled' version, which makes the popover a bit more compact. The logic for validating and creating a search job is encapsulated in a class which makes it easy to conditionally show the search jobs UI. Additional changes: - Skipped items is now a list and uses `<details>` elements which is semantically more correct. We loose the styling of the chevron but I think that's OK. - LoadingSpinner was updated to work inline. - Logging was fixed (?) in the React version to send the correct meta-data. - Added integration tests for the search job popover behavior ## Test plan Integration tests and manual testing.
1 parent 93818e0 commit ebaab12

File tree

15 files changed

+416
-128
lines changed

15 files changed

+416
-128
lines changed

client/branded/src/search-ui/results/progress/StreamingProgressSkippedPopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export const ExhaustiveSearchMessage: FC<ExhaustiveSearchMessageProps> = props =
356356
if (!validationLoading) {
357357
telemetryService.log('SearchJobsSearchFormShown', { validState }, { validState })
358358
telemetryRecorder.recordEvent('search.exhaustiveJobs', 'view', {
359-
metadata: { validState: validState ? 1 : 0 },
359+
metadata: { validState: validState === 'valid' ? 1 : 0 },
360360
})
361361
}
362362
}, [telemetryService, telemetryRecorder, validationError, validationLoading])

client/web-sveltekit/src/app.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
window.context = Object.assign(
2020
{},
21-
// Injected window.context (via proxy or playwright) if available
21+
// Injected window.context (via proxy) if available
2222
window.context,
2323
// Dev specific overwrites
2424
{
2525
sentryDNS: undefined,
2626
},
27+
// Playwright specific overwrites
28+
window.playwrightContext
2729
)
2830
window.pageError = undefined
2931
</script>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script lang="ts" context="module">
2+
import { Story } from '@storybook/addon-svelte-csf'
3+
4+
import LoadingSpinner from './LoadingSpinner.svelte'
5+
6+
export const meta = {
7+
component: LoadingSpinner,
8+
}
9+
</script>
10+
11+
<Story name="Default">
12+
<h3>Default</h3>
13+
<div class="wrapper">
14+
<LoadingSpinner />
15+
</div>
16+
17+
<h3>--size="2rem"</h3>
18+
<div class="wrapper">
19+
<LoadingSpinner --size="2rem" />
20+
</div>
21+
22+
<h3>center={false}</h3>
23+
<div class="wrapper">
24+
<LoadingSpinner center={false} />
25+
</div>
26+
27+
<h3>inline={true}</h3>
28+
<div class="wrapper">
29+
<LoadingSpinner inline />
30+
</div>
31+
<button>
32+
<LoadingSpinner inline />
33+
<span>Loading...</span>
34+
</button>
35+
<br />
36+
<button style="font-size: 48px">
37+
<LoadingSpinner inline />
38+
<span>Loading...</span>
39+
</button>
40+
</Story>
41+
42+
<style lang="scss">
43+
.wrapper {
44+
display: flex;
45+
margin: 1rem;
46+
width: 10rem;
47+
height: 10rem;
48+
background-color: lightblue;
49+
}
50+
51+
button span {
52+
vertical-align: middle;
53+
}
54+
</style>
55+

client/web-sveltekit/src/lib/LoadingSpinner.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
export let center = true
44
</script>
55

6-
<div class:center>
7-
<div class="loading-spinner" class:inline aria-label="loading" aria-live="polite" />
6+
<div class:center class:inline>
7+
<div class="loading-spinner" aria-label="loading" aria-live="polite" />
88
</div>
99

1010
<style lang="scss">
@@ -14,6 +14,11 @@
1414
align-items: center;
1515
flex: 1;
1616
justify-content: center;
17+
18+
}
19+
20+
.inline {
21+
display: contents;
1722
}
1823
1924
.loading-spinner {
@@ -28,13 +33,12 @@
2833
2934
width: var(--size, 1rem);
3035
height: var(--size, 1rem);
31-
&.inline {
36+
.inline & {
3237
width: #{(16 / 14)}em;
3338
height: #{(16 / 14)}em;
3439
35-
vertical-align: bottom;
36-
display: inline-flex;
37-
align-items: center;
40+
vertical-align: middle;
41+
display: inline-block;
3842
}
3943
4044
border-radius: 50%;

client/web-sveltekit/src/lib/Popover.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
export let hoverDelay: number = 500
1717
export let hoverCloseDelay: number = 150
1818
export let closeOnEsc: boolean = true
19+
export let flip: boolean = true
1920
export let trigger: HTMLElement | null = null
2021
export let target: HTMLElement | undefined = undefined
2122
@@ -156,9 +157,9 @@
156157
placement,
157158
offset,
158159
shift: { padding: 4 },
159-
flip: {
160+
flip: flip ? {
160161
fallbackAxisSideDirection: 'start',
161-
},
162+
} : undefined,
162163
},
163164
}}
164165
on:click-outside={handleClickOutside}

client/web-sveltekit/src/routes/search/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
queryFromURL={data.queryFromURL}
4141
{queryState}
4242
selectedFilters={data.queryFilters}
43+
searchJob={data.searchJob}
4344
/>
4445
{:else}
4546
<SearchHome {queryState}>

client/web-sveltekit/src/routes/search/+page.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { PageLoad } from './$types'
1919
import DotcomFooterLinks from './DotcomFooterLinks.svelte'
2020
import { DefaultSearchContext } from './page.gql'
2121
import { queryExampleDotcom, queryExampleEnterprise } from './queryExamples'
22+
import { SearchJob } from './searchJob'
2223

2324
type SearchStreamCacheEntry = Observable<AggregateStreamingSearchResults>
2425

@@ -145,6 +146,9 @@ export const load: PageLoad = async ({ parent, url, depends }) => {
145146
patternType,
146147
searchMode,
147148
},
149+
searchJob: window.context.searchJobsEnabled
150+
? new SearchJob(getGraphQLClient(), `${query} patternType:${patternType}`)
151+
: undefined,
148152
}
149153
}
150154

client/web-sveltekit/src/routes/search/SearchResults.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
4646
import PreviewPanel from './PreviewPanel.svelte'
4747
import SearchAlert from './SearchAlert.svelte'
48+
import type { SearchJob } from './searchJob'
4849
import { getSearchResultComponent } from './searchResultFactory'
4950
import { setSearchResultsContext } from './searchResultsContext'
5051
import StreamingProgress from './StreamingProgress.svelte'
@@ -53,6 +54,7 @@
5354
export let queryFromURL: string
5455
export let selectedFilters: URLQueryFilter[]
5556
export let queryState: QueryStateStore
57+
export let searchJob: SearchJob | undefined = undefined
5658
5759
export function capture(): SearchResultsCapture {
5860
return $resultContainer?.scrollTop ?? 0
@@ -195,7 +197,7 @@
195197
data-scope-button>Filters</Button
196198
>
197199
{/if}
198-
<StreamingProgress {state} progress={$stream.progress} on:submit={onResubmitQuery} />
200+
<StreamingProgress {state} progress={$stream.progress} on:submit={onResubmitQuery} {searchJob} />
199201
</aside>
200202
<div class="result-list" bind:this={$resultContainer}>
201203
{#if $stream.alert}

0 commit comments

Comments
 (0)