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

Commit 76d388a

Browse files
committed
fix teamkatalogen in search
1 parent 07702ff commit 76d388a

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

components/productArea/content.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PAItem } from "../../pages/productArea/[id]";
33
import SearchResultLink from "../search/searchResultLink";
44
import { useContext } from "react";
55
import { UserState } from "../../lib/context";
6-
import { useGetProductAreas } from "../../lib/rest/productAreas";
76

87
interface ProductAreaContentProps {
98
currentItem: PAItem
@@ -12,11 +11,8 @@ interface ProductAreaContentProps {
1211
}
1312

1413
const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductAreaContentProps) => {
15-
const {productAreas, loading, error} = useGetProductAreas()
1614
const userInfo= useContext(UserState)
1715

18-
if (loading) return <div>Laster...</div>
19-
if (error) return <div>Noe gikk galt</div>
2016
return (
2117
<Tabs
2218
value={currentTab}

components/search/resultList.tsx

+42-31
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import SearchResultLink from './searchResultLink'
1111
import { Tabs } from '@navikt/ds-react'
1212
import React, { useContext, useEffect, useState } from 'react'
1313
import { SearchParam } from '../../pages/search'
14-
import { useRouter } from 'next/router'
1514
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
1615
import { UserState } from '../../lib/context'
16+
import { useSearchTeamKatalogen } from '../../lib/rest/teamkatalogen'
1717
import { useGetProductAreas } from '../../lib/rest/productAreas'
1818

1919
const Results = ({ children }: { children: React.ReactNode }) => (
@@ -82,18 +82,29 @@ const ResultList = ({
8282
// eslint-disable-next-line react-hooks/exhaustive-deps
8383
}, [search])
8484
const [deleteStoryQuery] = useDeleteStoryMutation()
85-
const userInfo= useContext(UserState)
85+
const userInfo = useContext(UserState)
86+
const { searchResult: teamkatalogen } = useSearchTeamKatalogen()
87+
const { productAreas } = useGetProductAreas()
8688
const deleteStory = (id: string) => deleteStoryQuery({
87-
variables:{
89+
variables: {
8890
id: id
8991
},
90-
refetchQueries:[
92+
refetchQueries: [
9193
{
9294
query: USER_INFO,
9395
}
9496
]
9597
})
9698

99+
const getTeamKatalogenInfo = (item: any) => {
100+
const tk = teamkatalogen?.find((it) => it.url == item?.teamkatalogenURL)
101+
const po = productAreas?.find((it) => it.id == tk?.productAreaID)
102+
return {
103+
productArea: po?.name,
104+
teamkatalogenTeam: tk?.name || item.group?.group
105+
}
106+
}
107+
97108
if (search && !!searchParam) {
98109
const { data, loading, error } = search
99110

@@ -128,25 +139,25 @@ const ResultList = ({
128139
</Tabs.List>
129140
<Tabs.Panel className="flex flex-col pt-4 gap-4" value="story">
130141
{datastories.map(
131-
(it, idx)=>
142+
(it, idx) =>
132143
(
133-
it.result.__typename ==='Story' && (
134-
<SearchResultLink
135-
key={idx}
136-
name={it.result.name}
137-
type={'story'}
138-
keywords={it.result.keywords}
139-
description={it.excerpt}
140-
link={`/story/${it.result.id}`}
141-
group={{
142-
group: it.result.groupName,
143-
teamkatalogenURL: it.result.teamkatalogenURL,
144-
}}
145-
//TODO: fix teamkatalogen
146-
/>
147-
)
144+
it.result.__typename === 'Story' && (
145+
<SearchResultLink
146+
key={idx}
147+
name={it.result.name}
148+
type={'story'}
149+
keywords={it.result.keywords}
150+
description={it.excerpt}
151+
link={`/story/${it.result.id}`}
152+
group={{
153+
group: it.result.groupName,
154+
teamkatalogenURL: it.result.teamkatalogenURL,
155+
}}
156+
{...getTeamKatalogenInfo(it.result)}
157+
/>
158+
)
148159
)
149-
160+
150161
)}
151162
</Tabs.Panel>
152163
<Tabs.Panel className="flex flex-col gap-4" value="dataproduct">
@@ -161,7 +172,7 @@ const ResultList = ({
161172
description={d.result.description}
162173
link={`/dataproduct/${d.result.id}/${d.result.slug}`}
163174
datasets={d.result.datasets}
164-
//TODO: fix teamkatalogen
175+
{...getTeamKatalogenInfo(d.result)}
165176
/>
166177
)
167178
)}
@@ -181,7 +192,7 @@ const ResultList = ({
181192
name={d.name}
182193
keywords={d.keywords}
183194
link={`/dataproduct/${d.id}/${d.slug}`}
184-
//TODO: fix teamkatalogen
195+
{...getTeamKatalogenInfo(d)}
185196
/>
186197
))}
187198
</Results>
@@ -203,11 +214,11 @@ const ResultList = ({
203214
name={s.name}
204215
resourceType={"datafortelling"}
205216
link={`/story/${s.id}`}
206-
//TODO: fix teamkatalogen
207-
keywords={s.keywords}
208-
editable = {true}
209-
description= {s.description}
210-
deleteResource = {deleteStory}
217+
{...getTeamKatalogenInfo(s)}
218+
keywords={s.keywords}
219+
editable={true}
220+
description={s.description}
221+
deleteResource={deleteStory}
211222
/>
212223
))}
213224
</Results>
@@ -230,10 +241,10 @@ const ResultList = ({
230241
id={p.id}
231242
name={p.name}
232243
link={p.link}
233-
//TODO: fix teamkatalogen
234-
description= {p.description}
244+
{...getTeamKatalogenInfo(p)}
245+
description={p.description}
235246
innsiktsproduktType={p.type}
236-
editable={!!userInfo?.googleGroups?.find(it=> it.email == p.group)}
247+
editable={!!userInfo?.googleGroups?.find(it => it.email == p.group)}
237248
/>
238249
))}
239250
</Results>

0 commit comments

Comments
 (0)