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

Adds filter change to the chatbot #1494

Merged
merged 6 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const vimeoCdn = '*.vimeocdn.com'; // used for video preview images
const hotjarCom = '*.hotjar.com';
const hotjarIo = '*.hotjar.io';
const taskAnalytics = '*.taskanalytics.com';
const googleStorage = 'https://storage.googleapis.com';
mamikals marked this conversation as resolved.
Show resolved Hide resolved

const styleSrc = [
navNo,
Expand Down Expand Up @@ -51,7 +52,7 @@ const directives: Partial<CSPDirectives> = {
cdnNavNo,
DATA, // ds-css
],
'img-src': [navNo, vergicScreenSharing, vimeoCdn, hotjarCom, vergicDotCom],
'img-src': [navNo, vergicScreenSharing, vimeoCdn, hotjarCom, vergicDotCom, googleStorage],
'frame-src': [hotjarCom, vimeoPlayer, qbrick],
'connect-src': [navNo, boostChatbot, vergicScreenSharing, hotjarCom, hotjarIo, taskAnalytics],
};
Expand Down
21 changes: 20 additions & 1 deletion src/komponenter/footer/chatbot/ChatbotWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import { FridaIcon } from './FridaIcon';
import { BoostConfig, BoostObject } from './boost-config';

import style from './ChatbotWrapper.module.scss';
import { MenuValue } from 'utils/meny-storage-utils';
import { Locale } from 'store/reducers/language-duck';

const stateSelector = (state: AppState) => ({
chatbotParamEnabled: state.environment.PARAMS.CHATBOT,
chatbotParamVisible: state.environment.PARAMS.CHATBOT_VISIBLE,
featureToggles: state.featureToggles,
context: state.arbeidsflate.status,
env: state.environment.ENV,
language: state.language.language,
arbeidsflate: state.arbeidsflate.status,
});

const conversationCookieName = 'nav-chatbot%3Aconversation';
Expand All @@ -23,7 +27,7 @@ const boostApiUrlBaseTest = 'navtest';
const boostApiUrlBaseProduction = 'nav';

export const ChatbotWrapper = () => {
const { chatbotParamEnabled, chatbotParamVisible, env } = useSelector(stateSelector);
const { chatbotParamEnabled, chatbotParamVisible, env, language, arbeidsflate } = useSelector(stateSelector);
const [cookies, setCookie, removeCookie] = useCookies([conversationCookieName]);

// Do not mount chatbot on initial render. Prevents hydration errors
Expand Down Expand Up @@ -52,6 +56,13 @@ export const ChatbotWrapper = () => {
return;
}

let preferredFilter;
if (arbeidsflate === MenuValue.ARBEIDSGIVER) {
preferredFilter = 'arbeidsgiver';
} else {
preferredFilter = language === Locale.NYNORSK ? 'nynorsk' : 'bokmal';
}

const options: BoostConfig = {
chatPanel: {
settings: {
Expand All @@ -64,6 +75,11 @@ export const ChatbotWrapper = () => {
multiline: true,
},
},
header: {
filters: {
filterValues: preferredFilter,
},
},
},
};

Expand Down Expand Up @@ -116,6 +132,9 @@ export const ChatbotWrapper = () => {
domain: isProduction ? '.nav.no' : '.dev.nav.no',
});
});
boost.chatPanel.addEventListener('setFilterValue', function (ev: any) {
boost.chatPanel.setFilterValues(ev.detail.filterValue);
});

if (bufferLoad) {
setBufferLoad(false);
Expand Down