Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Søk i xp-archive #66

Merged
merged 42 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0ef4c5e
søkefelt
bdahle Dec 11, 2024
0e7fabb
searchService som henter tittel
bdahle Dec 12, 2024
d137b26
Refactor SearchService to update query parameter from 'title' to 'que…
bdahle Dec 13, 2024
de756c6
Refactor NavigationBar component to update search parameter from 'tit…
bdahle Dec 13, 2024
a07f90f
state for søkequery
bdahle Dec 13, 2024
5ce872e
loading state søk
bdahle Dec 13, 2024
6e117f5
oppdater type SearchResponse
bdahle Dec 13, 2024
22a57a9
viss antall treff
bdahle Dec 13, 2024
56ae759
searchResult-komponent
bdahle Dec 13, 2024
7663fa0
vis søkeresultater
bdahle Dec 13, 2024
8ae5405
gjør resultatene klikkbare
bdahle Dec 13, 2024
f631d25
styling søkeresultater
bdahle Dec 13, 2024
aaed8cf
valgt søketreff har annen farge
bdahle Dec 13, 2024
72e7208
fiks duplikate keys
bdahle Dec 13, 2024
b77e4d4
overskrift Søk
bdahle Dec 13, 2024
c471597
vis type-ikon i søk
bdahle Dec 13, 2024
87478bc
flytt classNames til common og bruk til selected search hit
bdahle Dec 13, 2024
ff60e8a
add close search button, and fix search on enter
bdahle Dec 16, 2024
435ec13
legg til layerLocale i søk
bdahle Dec 16, 2024
31cca9c
sett locale ved trykk i søk
bdahle Dec 16, 2024
450eaeb
search i egen komponent, skjule contentree funker ikke
bdahle Dec 16, 2024
b12de05
Revert "search i egen komponent, skjule contentree funker ikke"
bdahle Dec 17, 2024
48bba66
gjenbruk url for å hente ikon
bdahle Dec 17, 2024
b38b2b2
revert classNames spesifikt i tsconfig
bdahle Dec 17, 2024
d3f81f6
gjenbruk kode for å sette url i browser
bdahle Dec 17, 2024
8123ea4
bytt ut div med button
bdahle Dec 17, 2024
94dc52a
legg til path i søk og juster styling
bdahle Dec 17, 2024
eb00d68
juster ikon og avstand i søk
bdahle Dec 17, 2024
a7ab601
hvite knapper
bdahle Dec 17, 2024
6fb1bdb
hover farge søk
bdahle Dec 17, 2024
b170d3e
merge master
bdahle Dec 17, 2024
92329ed
vis treff på "innholdssider" øverst
bdahle Dec 18, 2024
c140b70
trekk ut SearchResultItem
bdahle Dec 18, 2024
0e8ae2e
SearchResultItem i egen fil
bdahle Dec 18, 2024
14c0c96
spacing i søket
bdahle Dec 18, 2024
24d3ea1
fjern heading
bdahle Dec 19, 2024
fd0121b
rydd i imports
bdahle Dec 19, 2024
c3ae50f
HelpText for sidetyper
bdahle Dec 19, 2024
3cf7425
bytt ut key=index med id+locale
bdahle Dec 19, 2024
0a57885
ubrukt import
bdahle Dec 19, 2024
f0f1d65
vis query igjen i trefftekst
bdahle Dec 19, 2024
f496255
filtrer ut mapper
bdahle Jan 2, 2025
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export const classNames = (...classNames: unknown[]) =>
classNames
.reduce<string>(
(acc, className) =>
typeof className === 'string' ? `${acc} ${className}` : acc,
(acc, className) => (typeof className === 'string' ? `${acc} ${className}` : acc),
''
)
.trim();
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { CmsCategoryPath } from '../../../../shared/cms-documents/_common';
import { BodyShort, Tooltip, TooltipProps } from '@navikt/ds-react';
import { classNames } from '../../../utils/classNames';
import { classNames } from '../../../../../common/src/client/utils/classNames';

import style from './CategoriesPath.module.css';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { BodyShort, Loader, LoaderProps } from '@navikt/ds-react';
import { classNames } from '../../../utils/classNames';
import { classNames } from '../../../../../common/src/client/utils/classNames';

import style from './ContentLoader.module.css';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { CategoriesMenu } from './categories/CategoriesMenu';
import { ContentMenu } from './contents/ContentMenu';
import { classNames } from '../../utils/classNames';
import { classNames } from '../../../../common/src/client/utils/classNames';
import { SearchInput } from './search/search-input/SearchInput';
import { SearchResult } from './search/search-result/SearchResult';
import { Alert, BodyLong, Heading } from '@navikt/ds-react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CmsCategoryListItem } from '../../../../../shared/cms-documents/categor
import { Category } from '../category/Category';
import { Checkbox } from '@navikt/ds-react';
import { useSearchState } from '../../../../context/search-state/useSearchState';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';

import style from './RootCategory.module.css';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CmsContentListItem } from '../../../../../shared/cms-documents/content'
import { BodyShort, Link, Loader } from '@navikt/ds-react';
import { useApiFetch } from '../../../../fetch/useApiFetch';
import { useAppState } from '../../../../context/app-state/useAppState';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';

import style from './ContentLink.module.css';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef } from 'react';
import { Search } from '@navikt/ds-react';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';
import { SearchSettings } from './search-settings/SearchSettings';
import { useSearchState } from '../../../../context/search-state/useSearchState';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Button, HelpText, Label, Radio, RadioGroup } from '@navikt/ds-react';
import { ChevronDownIcon, XMarkIcon } from '@navikt/aksel-icons';
import { classNames } from '../../../../../utils/classNames';
import { classNames } from '../../../../../../../common/src/client/utils/classNames';
import { useSearchState } from '../../../../../context/search-state/useSearchState';

import style from './SearchSettings.module.css';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';
import { Alert, Button, Heading } from '@navikt/ds-react';
import { SearchResultHit } from './search-hit/SearchResultHit';
import { ContentLoader } from '../../../common/loader/ContentLoader';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { CmsContent } from '../../../../../shared/cms-documents/content';
import { Link } from '@navikt/ds-react';
import { useAppState } from '../../../../context/app-state/useAppState';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';

import style from './FilesView.module.css';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';
import { Button } from '@navikt/ds-react';
import { useAppState } from '../../../../context/app-state/useAppState';
import { ExpandIcon } from '@navikt/aksel-icons';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { CmsContentDocument } from '../../../../../shared/cms-documents/content';
import { Button, Checkbox, CheckboxGroup, Heading, HelpText, Label } from '@navikt/ds-react';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';
import { useAppState } from '../../../../context/app-state/useAppState';
import { ArrowDownRightIcon, DownloadIcon } from '@navikt/aksel-icons';
import { formatTimestamp } from '@common/shared/timestamp';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Link, Loader } from '@navikt/ds-react';
import { classNames } from '../../../../../utils/classNames';
import { classNames } from '../../../../../../../common/src/client/utils/classNames';
import Cookies from 'js-cookie';
import { DOWNLOAD_COOKIE_NAME } from '../../../../../../shared/downloadCookie';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import XMLViewer from 'react-xml-viewer';
import { Alert, Switch, Tooltip } from '@navikt/ds-react';
import { classNames } from '../../../../utils/classNames';
import { classNames } from '../../../../../../common/src/client/utils/classNames';

import style from './XmlView.module.css';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ToggleGroup, Tooltip, TooltipProps } from '@navikt/ds-react';
import { classNames } from '../../../utils/classNames';
import { classNames } from '../../../../../common/src/client/utils/classNames';
import { CmsContent } from '../../../../shared/cms-documents/content';

import style from './ViewSelector.module.css';
Expand Down
5 changes: 3 additions & 2 deletions xp-archive/client/contentTree/NavigationBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
border-right: 1px solid var(--a-border-divider);
grid-area: left;
overflow-y: auto;
padding: 0.5rem;
}

.heading {
margin: 1rem;
.search {
margin-bottom: 1rem;
}
85 changes: 70 additions & 15 deletions xp-archive/client/contentTree/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import { Heading, Tabs } from '@navikt/ds-react';
import React, { useState } from 'react';
import { Tabs, Search } from '@navikt/ds-react';
import { LayerPanel } from './layerPanel/LayerPanel';
import { useAppState } from 'client/context/appState/useAppState';
import { fetchJson } from '@common/shared/fetchUtils';
import { SearchResponse } from 'shared/types';
import { SearchResult } from './search/SearchResult';

import style from './NavigationBar.module.css';

Expand All @@ -20,24 +23,76 @@ const getLabel = (locale: Locale) => {

export const NavigationBar = () => {
const { setSelectedLocale } = useAppState();
const [searchResultIsOpen, setSearchResultIsOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [isLoading, setIsLoading] = useState(false);
const [searchResult, setSearchResult] = useState<SearchResponse>({
hits: [],
total: 0,
hasMore: false,
query: '',
});

const SEARCH_API = `${import.meta.env.VITE_APP_ORIGIN}/xp/api/search`;

const searchData = async () => {
setIsLoading(true);
const result = await fetchJson<SearchResponse>(SEARCH_API, {
params: { query: searchQuery },
});
if (result) {
setSearchResult(result);
}
setSearchResultIsOpen(true);
setIsLoading(false);
return result;
};

const closeSearchResult = () => {
setSearchResultIsOpen(false);
setSearchQuery('');
};

return (
<div className={style.wrapper}>
<Heading size={'small'} className={style.heading}>
{'Innhold'}
</Heading>
<Tabs defaultValue="no" onChange={(locale) => setSelectedLocale(locale as Locale)}>
<Tabs.List>
<form
className={style.search}
role={'search'}
onSubmit={(e) => {
e.preventDefault();
if (!searchQuery) {
return;
}

searchData();
}}
>
<Search
label={'Søk'}
value={searchQuery}
onChange={(value) => setSearchQuery(value)}
/>
</form>
{searchResultIsOpen ? (
<SearchResult
isLoading={isLoading}
searchResult={searchResult}
closeSearchResult={closeSearchResult}
/>
) : (
<Tabs defaultValue="no" onChange={(locale) => setSelectedLocale(locale as Locale)}>
<Tabs.List>
{locales.map((locale) => (
<Tabs.Tab key={locale} value={locale} label={getLabel(locale)} />
))}
</Tabs.List>
{locales.map((locale) => (
<Tabs.Tab key={locale} value={locale} label={getLabel(locale)} />
<Tabs.Panel key={locale} value={locale}>
<LayerPanel locale={locale} />
</Tabs.Panel>
))}
</Tabs.List>
{locales.map((locale) => (
<Tabs.Panel key={locale} value={locale}>
<LayerPanel locale={locale} />
</Tabs.Panel>
))}
</Tabs>
</Tabs>
)}
</div>
);
};
20 changes: 16 additions & 4 deletions xp-archive/client/contentTree/contentTreeEntry/NavigationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,26 @@ type Props = {
entry: ContentTreeEntryData;
};

export const getContentIconUrl = (type: string) =>
`${import.meta.env.VITE_APP_ORIGIN}/xp/api/contentIcon?type=${type}`;

export const updateContentUrl = (id: string, locale: string) => {
const newUrl = `${xpArchiveConfig.basePath}/${id}/${locale}`;
window.history.pushState({}, '', newUrl);
};

export const NavigationItem = ({ entry }: Props) => {
const { setSelectedContentId } = useAppState();

const iconUrl = `${import.meta.env.VITE_APP_ORIGIN}/xp/api/contentIcon?type=${entry.type}`;
const label = (
<span style={{ display: 'flex', alignItems: 'center' }}>
<img src={iconUrl} width={20} height={20} style={{ marginRight: '5px' }} alt={''} />
<img
src={getContentIconUrl(entry.type)}
width={20}
height={20}
style={{ marginRight: '5px' }}
alt={''}
/>
{entry.displayName}
</span>
);
Expand All @@ -26,8 +39,7 @@ export const NavigationItem = ({ entry }: Props) => {
const onClick = () => {
if (!entry.isEmpty) {
setSelectedContentId(entry.id);
const newUrl = `${xpArchiveConfig.basePath}/${entry.id}/${entry.locale}`;
window.history.pushState({}, '', newUrl);
updateContentUrl(entry.id, entry.locale);
}
};

Expand Down
22 changes: 22 additions & 0 deletions xp-archive/client/contentTree/search/SearchResult.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.wrapper {
display: flex;
flex-direction: column;
}

.filteredHitsHeading {
display: flex;
justify-content: space-between;
margin-bottom: 0.5rem;
}

.filteredHitsHeadingText {
display: flex;
flex-direction: row;
align-items: center;
gap: 0.5rem;
}

.otherHitsHeading {
margin-top: 1.5rem;
margin-bottom: 0.5rem;
}
64 changes: 64 additions & 0 deletions xp-archive/client/contentTree/search/SearchResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { Button, Heading, HelpText, Loader } from '@navikt/ds-react';
import { SearchResponse } from 'shared/types';
import { SearchResultItem } from './SearchResultItem/SearchResultItem';

import style from './SearchResult.module.css';

type SearchResultProps = {
isLoading: boolean;
searchResult: SearchResponse;
closeSearchResult: () => void;
};

export const SearchResult = ({ isLoading, searchResult, closeSearchResult }: SearchResultProps) => {
const { hits, query } = searchResult;

const nonFolderHits = hits.filter((hit) => hit.type !== 'base:folder');

const filteredHits = nonFolderHits.filter(
(hit) =>
hit.type === 'no.nav.navno:content-page-with-sidemenus' ||
hit.type === 'no.nav.navno:themed-article-page' ||
hit.type === 'no.nav.navno:situation-page' ||
hit.type === 'no.nav.navno:guide-page'
);

const otherHits = nonFolderHits.filter((hit) => !filteredHits.includes(hit));

return (
<div>
{isLoading ? (
<Loader size={'3xlarge'} />
) : (
<div className={style.wrapper}>
<div className={style.filteredHitsHeading}>
<div>
<div className={style.filteredHitsHeadingText}>
<Heading size="small" level="2">
{`Treff for "${query}" i sidetyper: (${filteredHits.length})`}
</Heading>
<HelpText>
Treff i sidetypene Produktside, Situasjonsside, Temaartikkel og
Slik gjør du det.
</HelpText>
</div>
</div>
<Button variant="tertiary" size="small" onClick={closeSearchResult}>
Lukk
</Button>
</div>
{filteredHits.map((hit) => (
<SearchResultItem hit={hit} key={hit._id + hit.layerLocale} />
))}
<Heading size="small" level="2" className={style.otherHitsHeading}>
{`Treff for "${query}" i filer og annet: (${otherHits.length})`}
</Heading>
{otherHits.map((hit) => (
<SearchResultItem hit={hit} key={hit._id + hit.layerLocale} />
))}
</div>
)}
</div>
);
};
Loading
Loading