@@ -11,9 +11,9 @@ import SearchResultLink from './searchResultLink'
11
11
import { Tabs } from '@navikt/ds-react'
12
12
import React , { useContext , useEffect , useState } from 'react'
13
13
import { SearchParam } from '../../pages/search'
14
- import { useRouter } from 'next/router'
15
14
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
16
15
import { UserState } from '../../lib/context'
16
+ import { useSearchTeamKatalogen } from '../../lib/rest/teamkatalogen'
17
17
import { useGetProductAreas } from '../../lib/rest/productAreas'
18
18
19
19
const Results = ( { children } : { children : React . ReactNode } ) => (
@@ -82,18 +82,34 @@ const ResultList = ({
82
82
// eslint-disable-next-line react-hooks/exhaustive-deps
83
83
} , [ search ] )
84
84
const [ deleteStoryQuery ] = useDeleteStoryMutation ( )
85
- const userInfo = useContext ( UserState )
85
+ const userInfo = useContext ( UserState )
86
+ const { searchResult : teamkatalogen } = useSearchTeamKatalogen ( )
87
+ const { productAreas } = useGetProductAreas ( )
86
88
const deleteStory = ( id : string ) => deleteStoryQuery ( {
87
- variables :{
89
+ variables : {
88
90
id : id
89
91
} ,
90
- refetchQueries :[
92
+ refetchQueries : [
91
93
{
92
94
query : USER_INFO ,
93
95
}
94
96
]
95
97
} )
96
98
99
+ const getTeamKatalogenInfo = ( item : any ) => {
100
+ const getTeamID = ( url : string ) => {
101
+ var urlComponents = url ?. split ( "/" )
102
+ return urlComponents ?. [ urlComponents . length - 1 ]
103
+ }
104
+ const tk = teamkatalogen ?. find ( ( it ) => getTeamID ( it . url ) == getTeamID ( item ?. owner ?. teamkatalogenURL ) )
105
+ const po = productAreas ?. find ( ( it ) => it . id == tk ?. productAreaID )
106
+
107
+ return {
108
+ productArea : po ?. name ,
109
+ teamkatalogenTeam : tk ?. name || item . group ?. group
110
+ }
111
+ }
112
+
97
113
if ( search && ! ! searchParam ) {
98
114
const { data, loading, error } = search
99
115
@@ -106,6 +122,7 @@ const ResultList = ({
106
122
( d ) => d . result . __typename === 'Story'
107
123
)
108
124
125
+ //dataproducts.forEach((d) => console.log(getTeamKatalogenInfo(d.result)?.teamkatalogenTeam))
109
126
return (
110
127
< Results >
111
128
< Tabs
@@ -128,25 +145,25 @@ const ResultList = ({
128
145
</ Tabs . List >
129
146
< Tabs . Panel className = "flex flex-col pt-4 gap-4" value = "story" >
130
147
{ datastories . map (
131
- ( it , idx ) =>
148
+ ( it , idx ) =>
132
149
(
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
- )
150
+ it . result . __typename === 'Story' && (
151
+ < SearchResultLink
152
+ key = { idx }
153
+ name = { it . result . name }
154
+ type = { 'story' }
155
+ keywords = { it . result . keywords }
156
+ description = { it . excerpt }
157
+ link = { `/story/${ it . result . id } ` }
158
+ group = { {
159
+ group : it . result . groupName ,
160
+ teamkatalogenURL : it . result . teamkatalogenURL ,
161
+ } }
162
+ { ... getTeamKatalogenInfo ( it . result ) }
163
+ />
164
+ )
148
165
)
149
-
166
+
150
167
) }
151
168
</ Tabs . Panel >
152
169
< Tabs . Panel className = "flex flex-col gap-4" value = "dataproduct" >
@@ -161,7 +178,7 @@ const ResultList = ({
161
178
description = { d . result . description }
162
179
link = { `/dataproduct/${ d . result . id } /${ d . result . slug } ` }
163
180
datasets = { d . result . datasets }
164
- //TODO: fix teamkatalogen
181
+ { ... getTeamKatalogenInfo ( d . result ) }
165
182
/>
166
183
)
167
184
) }
@@ -181,7 +198,7 @@ const ResultList = ({
181
198
name = { d . name }
182
199
keywords = { d . keywords }
183
200
link = { `/dataproduct/${ d . id } /${ d . slug } ` }
184
- //TODO: fix teamkatalogen
201
+ { ... getTeamKatalogenInfo ( d ) }
185
202
/>
186
203
) ) }
187
204
</ Results >
@@ -203,11 +220,11 @@ const ResultList = ({
203
220
name = { s . name }
204
221
resourceType = { "datafortelling" }
205
222
link = { `/story/${ s . id } ` }
206
- //TODO: fix teamkatalogen
207
- keywords = { s . keywords }
208
- editable = { true }
209
- description = { s . description }
210
- deleteResource = { deleteStory }
223
+ { ... getTeamKatalogenInfo ( s ) }
224
+ keywords = { s . keywords }
225
+ editable = { true }
226
+ description = { s . description }
227
+ deleteResource = { deleteStory }
211
228
/>
212
229
) ) }
213
230
</ Results >
@@ -230,10 +247,10 @@ const ResultList = ({
230
247
id = { p . id }
231
248
name = { p . name }
232
249
link = { p . link }
233
- //TODO: fix teamkatalogen
234
- description = { p . description }
250
+ { ... getTeamKatalogenInfo ( p ) }
251
+ description = { p . description }
235
252
innsiktsproduktType = { p . type }
236
- editable = { ! ! userInfo ?. googleGroups ?. find ( it => it . email == p . group ) }
253
+ editable = { ! ! userInfo ?. googleGroups ?. find ( it => it . email == p . group ) }
237
254
/>
238
255
) ) }
239
256
</ Results >
0 commit comments