Skip to content

Commit eefb8c6

Browse files
authored
Merge pull request #69 from navikt/search-options
Search options
2 parents e685174 + 98f5aeb commit eefb8c6

File tree

4 files changed

+75
-15
lines changed

4 files changed

+75
-15
lines changed

xp-archive/client/contentTree/NavigationBar.module.css

+12
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77

88
.search {
99
margin-bottom: 1rem;
10+
display: flex;
11+
flex-direction: column;
12+
gap: 0.5rem;
13+
}
14+
15+
.radio {
16+
:global(.navds-body-short) {
17+
display: flex;
18+
flex-direction: row;
19+
gap: 0.5rem;
20+
align-items: center;
21+
}
1022
}

xp-archive/client/contentTree/NavigationBar.tsx

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
import { Tabs, Search } from '@navikt/ds-react';
2+
import { Tabs, Search, RadioGroup, Radio, HelpText } from '@navikt/ds-react';
33
import { LayerPanel } from './layerPanel/LayerPanel';
44
import { useAppState } from 'client/context/appState/useAppState';
55
import { fetchJson } from '@common/shared/fetchUtils';
@@ -26,6 +26,7 @@ export const NavigationBar = () => {
2626
const [searchResultIsOpen, setSearchResultIsOpen] = useState(false);
2727
const [searchQuery, setSearchQuery] = useState('');
2828
const [isLoading, setIsLoading] = useState(false);
29+
const [searchType, setSearchType] = useState<'curated' | 'other'>('curated');
2930
const [searchResult, setSearchResult] = useState<SearchResponse>({
3031
hits: [],
3132
total: 0,
@@ -38,7 +39,10 @@ export const NavigationBar = () => {
3839
const searchData = async () => {
3940
setIsLoading(true);
4041
const result = await fetchJson<SearchResponse>(SEARCH_API, {
41-
params: { query: searchQuery },
42+
params: {
43+
query: searchQuery,
44+
searchType,
45+
},
4246
});
4347
if (result) {
4448
setSearchResult(result);
@@ -67,10 +71,34 @@ export const NavigationBar = () => {
6771
searchData();
6872
}}
6973
>
74+
<RadioGroup
75+
legend="Søk i..."
76+
size="small"
77+
onChange={setSearchType}
78+
value={searchType}
79+
>
80+
<Radio className={style.radio} value="curated">
81+
Utvalgte innholdstyper
82+
<HelpText>
83+
<ul>
84+
<li>Produktside</li>
85+
<li>Situasjonsside</li>
86+
<li>Temaartikkel</li>
87+
<li>Slik gjør du det</li>
88+
<li>Aktuelt</li>
89+
<li>Artikkel</li>
90+
<li>Intern lenke</li>
91+
<li>Ekstern lenke</li>
92+
</ul>
93+
</HelpText>
94+
</Radio>
95+
<Radio value="other">Andre innholdstyper</Radio>
96+
</RadioGroup>
7097
<Search
7198
label={'Søk'}
7299
value={searchQuery}
73100
onChange={(value) => setSearchQuery(value)}
101+
size="small"
74102
/>
75103
</form>
76104
{searchResultIsOpen ? (

xp-archive/client/contentTree/search/SearchResult.tsx

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Button, Heading, HelpText, Loader } from '@navikt/ds-react';
2+
import { Button, Detail, Heading, Loader } from '@navikt/ds-react';
33
import { SearchResponse } from 'shared/types';
44
import { SearchResultItem } from './SearchResultItem/SearchResultItem';
55

@@ -12,7 +12,25 @@ type SearchResultProps = {
1212
};
1313

1414
export const SearchResult = ({ isLoading, searchResult, closeSearchResult }: SearchResultProps) => {
15-
const { hits, query } = searchResult;
15+
const { hits, query, total, hasMore } = searchResult;
16+
17+
const orderedHits = [...hits].sort((a, b) => {
18+
const orderedTypes = [
19+
'no.nav.navno:content-page-with-sidemenus',
20+
'no.nav.navno:situation-page',
21+
'no.nav.navno:themed-article-page',
22+
'no.nav.navno:guide-page',
23+
'no.nav.navno:current-topic-page',
24+
'no.nav.navno:main-article',
25+
'no.nav.navno:internal-link',
26+
'no.nav.navno:external-link',
27+
];
28+
29+
const indexA = orderedTypes.indexOf(a.type);
30+
const indexB = orderedTypes.indexOf(b.type);
31+
32+
return indexA - indexB;
33+
});
1634

1735
return (
1836
<div>
@@ -24,21 +42,23 @@ export const SearchResult = ({ isLoading, searchResult, closeSearchResult }: Sea
2442
<div>
2543
<div className={style.filteredHitsHeadingText}>
2644
<Heading size="small" level="2">
27-
{`Treff for "${query}" i sidetyper: (${hits.length})`}
45+
{`Treff for "${query}": (${total})`}
2846
</Heading>
29-
<HelpText>
30-
Treff i sidetypene Produktside, Situasjonsside, Temaartikkel og
31-
Slik gjør du det.
32-
</HelpText>
3347
</div>
3448
</div>
3549
<Button variant="tertiary" size="small" onClick={closeSearchResult}>
3650
Lukk
3751
</Button>
3852
</div>
39-
{hits.map((hit) => (
53+
{orderedHits.map((hit) => (
4054
<SearchResultItem hit={hit} key={hit._id + hit.layerLocale} />
4155
))}
56+
{hasMore && (
57+
<Detail>
58+
Viser kun de første 1000 treffene. Prøv å avgrens søket om du ikke fant
59+
det du lette etter.
60+
</Detail>
61+
)}
4262
</div>
4363
)}
4464
</div>

xp-archive/server/src/services/SearchService.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ export class SearchService {
88
private readonly SEARCH_API = xpServiceUrl('externalArchive/search');
99

1010
public getSearchHandler: RequestHandler = async (req, res) => {
11-
if (!validateQuery(req.query, ['query'], [])) {
11+
if (!validateQuery(req.query, ['query'], ['searchType'])) {
1212
return res.status(400).send('Missing or invalid parameters');
1313
}
1414

15-
const { query } = req.query;
16-
const searchResponse = await this.search(query);
15+
const { query, searchType } = req.query;
16+
const searchResponse = await this.search(query, searchType);
1717

1818
return res.status(200).json(searchResponse);
1919
};
2020

21-
private async search(query: string): Promise<SearchResponse | null> {
21+
private async search(query: string, searchType?: string): Promise<SearchResponse | null> {
2222
const searchResponse = await fetchJson<SearchResponse>(this.SEARCH_API, {
2323
headers: { secret: process.env.SERVICE_SECRET },
24-
params: { query },
24+
params: { query, searchType },
2525
});
2626

2727
return searchResponse;

0 commit comments

Comments
 (0)