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

Commit 7b95515

Browse files
authored
Merge pull request #298 from navikt/refactor/ART-05-user-info
Refactor/art 05 user info
2 parents 03df908 + 04a712e commit 7b95515

30 files changed

+139
-437
lines changed

components/dataproducts/dataproductList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface DataproductsListProps {
2222
const groupDatasetsByDataproduct = (datasets: any[]) => {
2323
let dataproducts = new Map<string, Dataset[]>()
2424

25-
datasets.forEach((dataset) => {
25+
datasets?.forEach((dataset) => {
2626
dataproducts.set(dataset.dataproductID, dataproducts.get(dataset.dataproductID) || [])
2727
dataproducts.get(dataset.dataproductID)?.push(dataset)
2828
})
@@ -51,7 +51,7 @@ export const DataproductsList = ({ datasets }: DataproductsListProps) => {
5151
</ExpansionCard.Header>
5252
<ExpansionCard.Content className="text-center">
5353
<>
54-
{datasets.map((dataset) => {
54+
{datasets?.map((dataset) => {
5555
return <SearchResultLink
5656
key={dataset.id}
5757
group={dataset.owner}

components/dataproducts/dataset/dataset.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { isAfter, parseISO } from 'date-fns'
2-
import {
3-
UserInfoDetailsQuery,
4-
} from '../../../lib/schema/graphql'
52
import * as React from 'react'
63
import { useState } from 'react'
74
import EditDataset from './editDataset'
@@ -11,7 +8,7 @@ import LoaderSpinner from '../../lib/spinner'
118
import { Alert } from '@navikt/ds-react'
129

1310
const findAccessType = (
14-
groups: UserInfoDetailsQuery['userInfo']['groups'] | undefined,
11+
groups: any,
1512
dataset: any,
1613
isOwner: boolean
1714
) => {
@@ -29,7 +26,7 @@ const findAccessType = (
2926
interface EntryProps {
3027
dataproduct: any
3128
datasetID: string
32-
userInfo: UserInfoDetailsQuery['userInfo'] | undefined
29+
userInfo: any
3330
isOwner: boolean
3431
}
3532

components/dataproducts/dataset/datasetSourceForm.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const DataproductSourceForm = ({
3434
register('bigquery.table')
3535

3636
const teamProjects = userInfo?.gcpProjects
37-
.filter((project) => project.group.email == team)
38-
.map((group) => group.id)
37+
.filter((project: any) => project.group.email == team)
38+
.map((group: any) => group.id)
3939

4040
const handleNodeSelect = (e: any, node: string) => {
4141
const [projectID, datasetID, tableID] = node.split('/')
@@ -59,7 +59,7 @@ export const DataproductSourceForm = ({
5959
onNodeSelect={handleNodeSelect}
6060
onNodeToggle={(x, n) => setActivePaths(n)}
6161
>
62-
{teamProjects?.map((projectID) => (
62+
{teamProjects?.map((projectID: any) => (
6363
<Project
6464
key={projectID}
6565
projectID={projectID}

components/dataproducts/dataset/viewDataset.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PluggableList } from 'react-markdown/lib'
77
import remarkGfm from 'remark-gfm'
88
import {
99
PiiLevel,
10-
UserInfoDetailsQuery,
1110
} from '../../../lib/schema/graphql'
1211
import { backendHost } from '../../header/user'
1312
import TagPill from '../../lib/tagPill'
@@ -27,7 +26,7 @@ interface ViewDatasetProps {
2726
type: string
2827
expires?: any
2928
}
30-
userInfo: UserInfoDetailsQuery['userInfo'] | undefined
29+
userInfo: any
3130
isOwner: boolean
3231
setEdit: (value: boolean) => void
3332
}

components/dataproducts/newDataproductForm.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export const NewDataproductForm = () => {
129129
})
130130
}
131131

132+
const gcpProjects = userInfo?.gcpProjects as any[] || []
133+
132134
return (
133135
<div className="mt-8 md:w-[46rem]">
134136
<Heading level="1" size="large">
@@ -160,11 +162,11 @@ export const NewDataproductForm = () => {
160162
<option value="">Velg gruppe</option>
161163
{[
162164
...new Set(
163-
userInfo?.gcpProjects.map(
165+
gcpProjects.map(
164166
({ group }: { group: { name: string } }) => (
165167
<option
166168
value={
167-
userInfo?.groups.filter((g) => g.name === group.name)[0]
169+
userInfo?.groups.filter((g:any) => g.name === group.name)[0]
168170
.email
169171
}
170172
key={group.name}

components/header/user.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export const backendHost = () => {
99
}
1010

1111
export default function User() {
12-
const userInfo = useContext(UserState)
13-
const userOfNada = userInfo?.groups.find((gr) => gr.name === 'nada')
12+
const userData = useContext(UserState)
13+
const userOfNada = userData?.googleGroups.find((gr: any) => gr.name === 'nada')
1414

1515
const router = useRouter()
16-
return userInfo ? (
16+
return userData ? (
1717
<div className="flex flex-row min-w-fit">
1818
<Dropdown>
1919
<Header.Button
@@ -127,7 +127,7 @@ export default function User() {
127127
className="whitespace-nowrap hidden md:block text-base"
128128
as={Dropdown.Toggle}
129129
>
130-
{userInfo.name}
130+
{userData.name}
131131
</Header.Button>
132132
<Header.Button
133133
className="md:hidden w-[48px] flex justify-center"

components/insightProducts/editInsightProduct.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import * as yup from 'yup'
1717
import { useContext, useState } from 'react'
1818
import TagsSelector from '../lib/tagsSelector'
1919
import { UserState } from "../../lib/context";
20-
import { UPDATE_INSIGHT_PRODUCT_METADATA } from '../../lib/queries/insightProducts/editInsightProduct'
2120
import { useUpdateInsightProductMetadataMutation } from '../../lib/schema/graphql'
22-
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
2321

2422
const schema = yup.object().shape({
2523
name: yup.string().nullable().required('Skriv inn navnet på innsiktsproduktet'),
@@ -109,10 +107,6 @@ export const EditInsightProductMetadataForm = ({ id, name, description, type, li
109107
teamID: teamID,
110108
group: data.group,
111109
},
112-
refetchQueries: [
113-
{
114-
query: USER_INFO,
115-
}]
116110
}
117111

118112
updateInsightProductQuery(editInsightProductData).then(() => {
@@ -164,7 +158,7 @@ export const EditInsightProductMetadataForm = ({ id, name, description, type, li
164158
control={control}
165159
/>
166160
<TeamkatalogenSelector
167-
gcpGroups={userInfo?.gcpProjects.map(it => it.group.email)}
161+
gcpGroups={userInfo?.gcpProjects.map((it: any) => it.group.email)}
168162
register={register}
169163
watch={watch}
170164
errors={errors}

components/insightProducts/newInsightProduct.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const NewInsightProductForm = () => {
4646
const router = useRouter()
4747
const [productAreaID, setProductAreaID] = useState<string>('')
4848
const [teamID, setTeamID] = useState<string>('')
49-
const userInfo = useContext(UserState)
49+
const userData = useContext(UserState)
5050
const [isPrivacyCheckboxChecked, setIsPrivacyCheckboxChecked] = useState(false)
5151

5252
const handlePrivacyCheckboxChange = () => {
@@ -109,7 +109,6 @@ export const NewInsightProductForm = () => {
109109
refetchQueries: ['searchContent'],
110110
}
111111

112-
console.log(inputData)
113112
try {
114113
await createInsightProduct(inputData)
115114
amplitudeLog('skjema fullført', { skjemanavn: 'ny-innsiktsprodukt' })
@@ -126,7 +125,6 @@ export const NewInsightProductForm = () => {
126125
CREATE_INSIGHT_PRODUCT,
127126
{
128127
onCompleted: (data) => {
129-
console.log(data)
130128
router.push("/")
131129
},
132130
}
@@ -153,6 +151,8 @@ export const NewInsightProductForm = () => {
153151
})
154152
}
155153

154+
const gcpProjects = userData?.gcpProjects as any[] || []
155+
156156
return (
157157
<div className="mt-8 md:w-[46rem]">
158158
<Heading level="1" size="large">
@@ -205,11 +205,11 @@ export const NewInsightProductForm = () => {
205205
<option value="">Velg gruppe</option>
206206
{[
207207
...new Set(
208-
userInfo?.gcpProjects.map(
208+
gcpProjects.map(
209209
({ group }: { group: { name: string } }) => (
210210
<option
211211
value={
212-
userInfo?.groups.filter((g) => g.name === group.name)[0]
212+
userData?.groups.filter((g: any) => g.name === group.name)[0]
213213
.email
214214
}
215215
key={group.name}
@@ -222,7 +222,7 @@ export const NewInsightProductForm = () => {
222222
]}
223223
</Select>
224224
<TeamkatalogenSelector
225-
gcpGroups={userInfo?.gcpProjects.map(it => it.group.email)}
225+
gcpGroups={userData?.gcpProjects?.map((it: any) => it.group.email)}
226226
register={register}
227227
watch={watch}
228228
errors={errors}

components/lib/tagsSelector.tsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,38 @@ const theme: ThemeConfig = (t) => ({
6060

6161
const useBuildTagOptionsList = () => {
6262
const { data, error } = useKeywordsQuery()
63-
const userInfo = useContext(UserState)
63+
const userData = useContext(UserState)
6464
let tagsMap = new Map(
65-
userInfo?.dataproducts
66-
?.flatMap((it) => it.keywords)
67-
.map((it) => [it, 100000])
65+
userData?.dataproducts
66+
?.flatMap((it: any) => it.keywords)
67+
.map((it: any) => [it, 100000])
6868
)
6969
if (!error) {
70-
data?.keywords.forEach((it) =>
70+
data?.keywords.forEach((it: any) =>
7171
tagsMap.set(it.keyword, it.count + (tagsMap.get(it.keyword) || 0))
7272
)
7373
}
7474
return Array.from(tagsMap.entries())
75-
.sort((l, r) => r[1] - l[1])
75+
.sort((l: any, r: any) => r[1] - l[1])
7676
.map((it) => it[0])
7777
}
7878

7979
export const TagsSelector = ({ onAdd, onDelete, tags }: TagsSelectorProps) => {
8080
let tagOptions = useBuildTagOptionsList()
81-
const userInfo = useContext(UserState)
82-
const teamNames = userInfo?.allGoogleGroups?.map(
83-
(it) => it.name.split('@')[0]
81+
const userData = useContext(UserState)
82+
const teamNames = userData?.allGoogleGroups?.map(
83+
(it: any) => it.Name
8484
)
8585

8686
const tagsLikeTeamName = tags.filter((it) =>
87-
teamNames?.find((tn) => tn.toLocaleLowerCase() === it.toLocaleLowerCase())
87+
teamNames?.find((tn: any) => tn.toLocaleLowerCase() === it.toLocaleLowerCase())
8888
)
8989
const addNewTag = (text: string) => {
9090
//if there is a similar tag in the list, use it as the text
9191
const newTag = (
9292
tagOptions.find(
93-
(t) => t.toLocaleLowerCase() === text.toLocaleLowerCase()
94-
) ?? text
93+
(t: any) => t.toLocaleLowerCase() === text.toLocaleLowerCase()
94+
) as string ?? text
9595
).trim()
9696
onAdd(newTag)
9797
}
@@ -160,8 +160,8 @@ export const TagsSelector = ({ onAdd, onDelete, tags }: TagsSelectorProps) => {
160160
<CreatableSelect
161161
isMulti
162162
options={tagOptions.map((it) => ({
163-
value: it,
164-
label: it,
163+
value: it as string,
164+
label: it as string,
165165
}))}
166166
styles={styles}
167167
theme={theme}

components/productArea/content.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductA
112112
link={ip.link}
113113
id={ip.id}
114114
innsiktsproduktType={ip.type}
115-
editable={!!userInfo?.googleGroups?.find(it=> it.email == ip.group)}
115+
editable={!!userInfo?.googleGroups?.find((it: any)=> it.email == ip.group)}
116116
teamkatalogenTeam={ip.teamName}
117117
productArea={ip.productAreaName}
118118
/>

components/search/resultList.tsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { QueryResult } from '@apollo/client'
21
import ErrorMessage from '../lib/error'
32
import LoaderSpinner from '../lib/spinner'
43
import SearchResultLink from './searchResultLink'
54
import { Tabs } from '@navikt/ds-react'
65
import React, { useContext, useEffect, useState } from 'react'
76
import { SearchParam } from '../../pages/search'
8-
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
97
import { UserState } from '../../lib/context'
108
import { useSearchTeamKatalogen } from '../../lib/rest/teamkatalogen'
119
import { useGetProductAreas } from '../../lib/rest/productAreas'
@@ -65,11 +63,6 @@ const ResultList = ({
6563
variables: {
6664
id: id
6765
},
68-
refetchQueries: [
69-
{
70-
query: USER_INFO,
71-
}
72-
]
7366
})
7467

7568
const isDataProduct = (item: any) => !!item.datasets
@@ -89,7 +82,7 @@ const ResultList = ({
8982
}
9083

9184
if (search && !!searchParam) {
92-
const { data, loading, error } = search
85+
var { data, loading, error } = search
9386

9487
if (error) return <ErrorMessage error={error} />
9588
if (loading || !data) return <LoaderSpinner />
@@ -100,7 +93,6 @@ const ResultList = ({
10093
(d) => !isDataProduct(d.result)
10194
)
10295

103-
//dataproducts.forEach((d) => console.log(getTeamKatalogenInfo(d.result)?.teamkatalogenTeam))
10496
return (
10597
<Results>
10698
<Tabs
@@ -228,7 +220,7 @@ const ResultList = ({
228220
{...getTeamKatalogenInfo(p)}
229221
description={p.description}
230222
innsiktsproduktType={p.type}
231-
editable={!!userInfo?.googleGroups?.find(it => it.email == p.group)}
223+
editable={!!userInfo?.googleGroups?.find((it: any) => it.email == p.group)}
232224
/>
233225
))}
234226
</Results>

components/search/searchResultLink.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import humanizeDate from '../../lib/humanizeDate'
99
import DeleteModal from '../lib/deleteModal'
1010
import { useState } from 'react'
1111
import { useRouter } from 'next/router'
12-
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
1312
import TagPill from '../lib/tagPill'
1413

1514
export interface SearchResultProps {
@@ -72,11 +71,6 @@ export const SearchResultLink = ({
7271
variables:{
7372
id: id
7473
},
75-
refetchQueries:[
76-
{
77-
query: USER_INFO,
78-
}
79-
]
8074
})
8175
}
8276

0 commit comments

Comments
 (0)