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

Commit 7d33b3b

Browse files
committed
Går mot det nye søket
1 parent ab2f086 commit 7d33b3b

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ENV=localhost
22
XP_BASE_URL=https://www.nav.no
3+
SEARCH_URL=https://navno-search-api.intern.nav.no
34
APP_BASE_URL=http://localhost:8088
45
APP_BASE_PATH=/dekoratoren
56
API_XP_SERVICES_URL=https://www.nav.no/_/service

.nais/vars/dev-stable.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ env:
1010
value: dev
1111
- name: XP_BASE_URL
1212
value: https://www.ekstern.dev.nav.no
13+
- name: SEARCH_URL
14+
value: https://navno-search-api.intern.dev.nav.no
1315
- name: APP_BASE_URL
1416
value: https://dekoratoren.ekstern.dev.nav.no
1517
- name: API_XP_SERVICES_URL

src/komponenter/header/header-regular/common/sok/Sok.tsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import SokResultater from './sok-innhold/SokResultater';
1313
import { Environment } from 'store/reducers/environment-duck';
1414
import Cookies from 'js-cookie';
1515
import 'komponenter/header/header-regular/common/sok/Sok.scss';
16+
import { useCookies } from 'react-cookie';
17+
import { decoratorContextCookie, decoratorLanguageCookie } from '../../../Header';
1618

1719
interface Props {
1820
id: string;
@@ -37,12 +39,16 @@ const Sok = (props: Props) => {
3739
const [loading, setLoading] = useState<boolean>(false);
3840
const [result, setResult] = useState<Sokeresultat | undefined>();
3941
const [error, setError] = useState<string | undefined>();
42+
const [cookies] = useCookies();
4043
const { searchInput, setSearchInput } = props;
4144
const numberOfResults = 5;
4245
const klassenavn = cls('sok-input', {
4346
engelsk: language === Locale.ENGELSK,
4447
});
4548

49+
const audience = cookies[decoratorContextCookie];
50+
const preferredLanguage = cookies[decoratorLanguageCookie];
51+
4652
useEffect(() => {
4753
if (!props.isOpen) {
4854
clearInput();
@@ -67,7 +73,7 @@ const Sok = (props: Props) => {
6773

6874
const getSearchUrl = () => {
6975
const { XP_BASE_URL } = environment;
70-
const url = `${XP_BASE_URL}/sok?ord=${searchInput}`;
76+
const url = `${XP_BASE_URL}/nytt-sok?ord=${searchInput}`;
7177
return genererUrl(XP_BASE_URL, url);
7278
};
7379

@@ -99,6 +105,8 @@ const Sok = (props: Props) => {
99105
setLoading(true);
100106
fetchSearchDebounced({
101107
value,
108+
audience,
109+
preferredLanguage,
102110
environment,
103111
setLoading,
104112
setError,
@@ -137,14 +145,16 @@ const Sok = (props: Props) => {
137145
/* Abstraction for debounce */
138146
interface FetchResult {
139147
value: string;
148+
audience: string;
149+
preferredLanguage: string;
140150
environment: Environment;
141151
setLoading: (value: boolean) => void;
142152
setError: (value?: string) => void;
143153
setResult: (value?: any) => void;
144154
}
145155

146156
const fetchSearch = (props: FetchResult) => {
147-
const { environment, value } = props;
157+
const { environment, value, audience, preferredLanguage } = props;
148158
const { setLoading, setError, setResult } = props;
149159
const { APP_URL } = environment;
150160
const url = `${APP_URL}/api/sok`;
@@ -157,7 +167,7 @@ const fetchSearch = (props: FetchResult) => {
157167
label: value,
158168
action: 'søk-dynamisk',
159169
});
160-
fetch(`${url}?ord=${encodeURIComponent(value)}`)
170+
fetch(`${url}?ord=${encodeURIComponent(value)}&audience=${audience}&preferredLanguage=${preferredLanguage}`)
161171
.then((response) => {
162172
if (response.ok) {
163173
return response;

src/server/api-handlers/sok.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RequestHandler } from 'express';
22

3-
const sokServiceUrl = `${process.env.API_XP_SERVICES_URL}/navno.nav.no.search/search2/sok`;
3+
const sokServiceUrl = `${process.env.SEARCH_URL}/content/decorator-search`;
44

55
export const getSokHandler: RequestHandler = (req, res) => {
66
const queryString = new URL(req.url, process.env.APP_BASE_URL).search;

src/server/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const clientEnv = ({ req }: Props): Environment => {
2828
return {
2929
ENV: process.env.ENV as string,
3030
XP_BASE_URL: process.env.XP_BASE_URL as string,
31+
SEARCH_URL: process.env.SEARCH_URL as string,
3132
APP_URL: appUrl as string,
3233
APP_BASE_URL: process.env.APP_BASE_URL as string,
3334
APP_BASE_PATH: process.env.APP_BASE_PATH as string,

src/store/reducers/environment-duck.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Breadcrumb } from 'komponenter/header/common/brodsmulesti/Brodsmulesti'
66
export interface Environment {
77
ENV: string;
88
XP_BASE_URL: string;
9+
SEARCH_URL: string;
910
APP_URL: string;
1011
APP_BASE_URL: string;
1112
APP_BASE_PATH: string;
@@ -57,6 +58,7 @@ export interface Cookies {
5758
export const initialState: Environment = {
5859
ENV: '',
5960
XP_BASE_URL: '',
61+
SEARCH_URL: '',
6062
APP_URL: '',
6163
APP_BASE_URL: '',
6264
APP_BASE_PATH: '',

0 commit comments

Comments
 (0)