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

Commit e5a5860

Browse files
authored
Merge pull request #281 from navikt/perf/no-more-graphql
Refactor ART02: Use rest api for product areas feature
2 parents 39026aa + d356161 commit e5a5860

16 files changed

+202
-499
lines changed

components/dataproducts/dataproductList.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const DataproductsList = ({ datasets }: DataproductsListProps) => {
5959
type={'Dataset'}
6060
keywords={dataset.keywords}
6161
link={`/dataproduct/${dataset.dataproductID}/${dataset.dataproduct.slug}/${dataset.id}`}
62+
productAreas={[]}
6263
/>
6364
})
6465
}

components/productArea/content.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Tabs } from "@navikt/ds-react";
22
import { PAItem } from "../../pages/productArea/[id]";
33
import SearchResultLink from "../search/searchResultLink";
4-
import { useProductAreasQuery, useTeamkatalogenQuery } from "../../lib/schema/graphql";
4+
import { useTeamkatalogenQuery } from "../../lib/schema/graphql";
55
import { useContext } from "react";
66
import { UserState } from "../../lib/context";
7+
import { useGetProductAreas } from "../../lib/rest/productAreas";
78

89
interface ProductAreaContentProps {
910
currentItem: PAItem
@@ -15,9 +16,11 @@ const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductA
1516
const tk = useTeamkatalogenQuery({
1617
variables: { q: '' },
1718
})
18-
const po = useProductAreasQuery()
19+
const {productAreas, loading, error} = useGetProductAreas()
1920
const userInfo= useContext(UserState)
2021

22+
if (loading) return <div>Laster...</div>
23+
if (error) return <div>Noe gikk galt</div>
2124
return (
2225
<Tabs
2326
value={currentTab}
@@ -72,7 +75,7 @@ const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductA
7275
link={`/story/${s.id}`}
7376
type={s.__typename}
7477
teamkatalogen={tk.data}
75-
productAreas={po.data}
78+
productAreas={productAreas}
7679
/>
7780
))}
7881
{currentItem.stories.length == 0 && "Ingen fortellinger"}
@@ -92,7 +95,7 @@ const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductA
9295
description={d.description}
9396
link={`/dataproduct/${d.id}/${d.slug}`}
9497
teamkatalogen={tk.data}
95-
productAreas={po.data}
98+
productAreas={productAreas}
9699
/>
97100
))}
98101
{currentItem.dataproducts.length == 0 && "Ingen dataprodukter"}
@@ -118,7 +121,7 @@ const ProductAreaContent = ({ currentItem, currentTab, setCurrentTab }: ProductA
118121
id={ip.id}
119122
innsiktsproduktType={ip.type}
120123
teamkatalogen={tk.data}
121-
productAreas={po.data}
124+
productAreas={productAreas}
122125
editable={!!userInfo?.googleGroups?.find(it=> it.email == ip.group)}
123126
/>
124127
))}

components/productArea/productAreaLinks.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { Heading, Link } from '@navikt/ds-react'
2-
import { useProductAreasQuery } from '../../lib/schema/graphql'
32
import ExploreAreasIcon from '../lib/icons/exploreAreasIcon'
3+
import { useGetProductAreas } from '../../lib/rest/productAreas'
4+
5+
const ProductAreaHasItems = (p: any)=> !!p?.teams.filter((it: any)=> it.dataproductsNumber+ it.storiesNumber> 0).length
46

57
const ProductAreaLinks = () => {
68
var defaultProductAreaID = '6b149078-927b-4570-a1ce-97bbb9499fb6'
7-
const productAreasQuery = useProductAreasQuery()
8-
9-
if (productAreasQuery.data && productAreasQuery.data.productAreas.length > 0) {
10-
defaultProductAreaID =
11-
productAreasQuery.data.productAreas.find(
12-
(it) => it.id == '6b149078-927b-4570-a1ce-97bbb9499fb6'
13-
)?.id || productAreasQuery.data.productAreas[0].id
9+
const {productAreas} = useGetProductAreas()
10+
const productAreaWithItems = productAreas?.filter(it=> ProductAreaHasItems(it));
11+
if(productAreaWithItems.length>0){
12+
defaultProductAreaID = productAreaWithItems.find(it=> it.id== defaultProductAreaID)?.id || productAreaWithItems[0].id
13+
}else{
14+
return null
1415
}
15-
16+
1617
return (
1718
<div className="border border-border-default bg-white rounded-lg w-11/12 md:w-[17rem] md:h-[22rem] p-4 pt-8 flex items-center flex-col gap-8">
1819
<ExploreAreasIcon />

components/productArea/productAreaMobileMenu.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Back, Next } from "@navikt/ds-icons"
22
import { Button, Heading, Modal } from "@navikt/ds-react"
33
import { useState } from "react"
4-
import { ProductAreasQuery } from "../../lib/schema/graphql"
54
import { PAItems } from "../../pages/productArea/[id]"
65

76
interface MobileMenuProps {
87
open: boolean
98
setOpen: (value: boolean) => void
109
productAreaItems: PAItems
1110
setCurrentItem: (newCurrent: number) => void
12-
productAreas: ProductAreasQuery['productAreas']
11+
productAreas: any[]
1312
selectProductArea: (productAreaId: string) => void
1413
}
1514

components/productArea/productAreaView.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@ import { System } from '@navikt/ds-icons'
22
import { Heading } from '@navikt/ds-react'
33
import { useRouter } from 'next/router'
44
import { useState } from 'react'
5-
import { ProductAreasQuery } from '../../lib/schema/graphql'
65
import { PAItem, PAItems } from '../../pages/productArea/[id]'
76
import ProductAreaContent from './content'
87
import ProductAreaMobileMenu from './productAreaMobileMenu'
98
import ProductAreaSidebar from './sidebar'
109

1110
interface ProductAreaViewProps {
1211
paItems: PAItems
13-
productAreas: ProductAreasQuery['productAreas']
12+
productAreas: any[]
1413
}
1514

1615
const ProductAreaView = ({ paItems, productAreas }: ProductAreaViewProps) => {
1716
const router = useRouter()
18-
const currentItemName = (router.query.team as string) || paItems[0].name
17+
const currentItemName = (router.query.team as string) || paItems.length && paItems[0].name || ''
1918
const teamIdx = paItems.findIndex(
2019
(it) => it.name.toLowerCase() === currentItemName.toLowerCase() || it.id === currentItemName
2120
)
2221

2322
const currentItem = teamIdx > 0 ? teamIdx : 0
2423

2524
const initialTab = (item: PAItem) => {
26-
return item.dashboardURL ? 'dashboard' : 'stories'
25+
return item?.dashboardURL ? 'dashboard' : 'stories'
2726
}
2827

2928
const [currentTab, setCurrentTab] = useState(initialTab(paItems[teamIdx]))
3029
const [open, setOpen] = useState(false)
30+
31+
if(!currentItemName){
32+
return <div>Ingen produktområder samsvarer med søkekriteriene</div>
33+
}
34+
3135
const pathComponents = router.asPath.split('?')[0].split('/')
3236
const currentProductAreaId = pathComponents[pathComponents.length - 1]
3337

components/productArea/sidebar.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { Data } from '@navikt/ds-icons'
22
import { Select } from '@navikt/ds-react'
33
import { useRouter } from 'next/router'
44
import * as React from 'react'
5-
import { ProductAreasQuery } from '../../lib/schema/graphql'
65
import { PAItems } from '../../pages/productArea/[id]'
76
import DataproductLogo from '../lib/icons/dataproductLogo'
87

98
interface ProductAreaSidebarProps {
109
productAreaItems: PAItems
1110
setCurrentItem: (newCurrent: number) => void
1211
currentItem: number
13-
productAreas: ProductAreasQuery['productAreas']
12+
productAreas: any
1413
selectProductArea: (productAreaId: string) => void
1514
}
1615

@@ -23,23 +22,23 @@ const ProductAreaSidebar = ({
2322
}: ProductAreaSidebarProps) => {
2423
const relevantProductAreas = productAreas
2524
.filter(
26-
(it) =>
27-
it.dataproducts.length ||
28-
it.stories.length ||
29-
it.insightProducts.length
30-
).sort((l, r) => (l.name < r.name ? -1 : 1))
25+
(it: any) =>
26+
it.dataproductsNumber ||
27+
it.storiesNumber ||
28+
it.insightProductsNumber
29+
).sort((l: any, r: any) => (l.name < r.name ? -1 : 1))
3130
return (
3231
<div className="pr-[2rem] w-96 pt-[1.6rem] hidden md:block">
3332
<Select
3433
className="w-full mb-[1rem]"
3534
label=""
3635
onChange={(e) => selectProductArea(e.target.value)}
3736
value={
38-
relevantProductAreas.find((it) => it.name == productAreaItems[0].name)
37+
relevantProductAreas.find((it: any) => it.name == productAreaItems[0].name)
3938
?.id
4039
}
4140
>
42-
{relevantProductAreas.map((it, index) => (
41+
{relevantProductAreas.map((it: any, index: number) => (
4342
<option key={index} value={it.id}>
4443
{it.name}
4544
</option>

components/search/resultList.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
SearchContentWithOptionsQuery,
55
SearchOptions,
66
useDeleteStoryMutation,
7-
useProductAreasQuery,
87
useTeamkatalogenQuery,
98
} from '../../lib/schema/graphql'
109
import ErrorMessage from '../lib/error'
@@ -16,6 +15,7 @@ import { SearchParam } from '../../pages/search'
1615
import { useRouter } from 'next/router'
1716
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
1817
import { UserState } from '../../lib/context'
18+
import { useGetProductAreas } from '../../lib/rest/productAreas'
1919

2020
const Results = ({ children }: { children: React.ReactNode }) => (
2121
<div className="results">{children}</div>
@@ -87,7 +87,7 @@ const ResultList = ({
8787
variables: { q: '' },
8888
})
8989

90-
const po = useProductAreasQuery()
90+
const {productAreas} = useGetProductAreas()
9191
const [deleteStoryQuery] = useDeleteStoryMutation()
9292
const userInfo= useContext(UserState)
9393
const deleteStory = (id: string) => deleteStoryQuery({
@@ -150,7 +150,7 @@ const ResultList = ({
150150
teamkatalogenURL: it.result.teamkatalogenURL,
151151
}}
152152
teamkatalogen={tk.data}
153-
productAreas={po.data}
153+
productAreas={productAreas}
154154
/>
155155
)
156156
)
@@ -170,7 +170,7 @@ const ResultList = ({
170170
link={`/dataproduct/${d.result.id}/${d.result.slug}`}
171171
datasets={d.result.datasets}
172172
teamkatalogen={tk.data}
173-
productAreas={po.data}
173+
productAreas={productAreas}
174174
/>
175175
)
176176
)}
@@ -191,7 +191,7 @@ const ResultList = ({
191191
keywords={d.keywords}
192192
link={`/dataproduct/${d.id}/${d.slug}`}
193193
teamkatalogen={tk.data}
194-
productAreas={po.data}
194+
productAreas={productAreas}
195195
/>
196196
))}
197197
</Results>
@@ -214,7 +214,7 @@ const ResultList = ({
214214
resourceType={"datafortelling"}
215215
link={`/story/${s.id}`}
216216
teamkatalogen={tk.data}
217-
productAreas={po.data}
217+
productAreas={productAreas}
218218
keywords={s.keywords}
219219
editable = {true}
220220
description= {s.description}
@@ -242,7 +242,7 @@ const ResultList = ({
242242
name={p.name}
243243
link={p.link}
244244
teamkatalogen={tk.data}
245-
productAreas={po.data}
245+
productAreas={productAreas}
246246
description= {p.description}
247247
innsiktsproduktType={p.type}
248248
editable={!!userInfo?.googleGroups?.find(it=> it.email == p.group)}

components/search/searchResultLink.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import ReactMarkdown from 'react-markdown'
44
import { PluggableList } from 'react-markdown/lib'
55
import remarkGfm from 'remark-gfm'
66
import { CoApplicant, Table } from '@navikt/ds-icons'
7-
import { ProductAreasQuery, TeamkatalogenQuery, useDeleteInsightProductMutation, useDeleteStoryMutation } from '../../lib/schema/graphql'
7+
import { TeamkatalogenQuery, useDeleteInsightProductMutation, useDeleteStoryMutation } from '../../lib/schema/graphql'
88
import humanizeDate from '../../lib/humanizeDate'
99
import DeleteModal from '../lib/deleteModal'
1010
import { useState } from 'react'
1111
import { useRouter } from 'next/router'
1212
import { USER_INFO } from '../../lib/queries/userInfo/userInfo'
13-
import { GET_PRODUCT_AREAS } from '../../lib/queries/productAreas/productAreas'
1413
import TagPill from '../lib/tagPill'
1514

1615
export interface SearchResultProps {
@@ -33,7 +32,7 @@ export interface SearchResultProps {
3332
}
3433
}[]
3534
teamkatalogen?: TeamkatalogenQuery,
36-
productAreas?: ProductAreasQuery,
35+
productAreas?: any[],
3736
editable?: boolean,
3837
deleteResource?: (id: string) => Promise<any>,
3938
}
@@ -57,7 +56,7 @@ export const SearchResultLink = ({
5756
const [modal, setModal] = useState(false)
5857

5958
const tk = teamkatalogen?.teamkatalogen.find((it) => it.url == group?.teamkatalogenURL)
60-
const po = productAreas?.productAreas.find((it) => it.id == tk?.productAreaID)
59+
const po = productAreas?.find((it) => it.id == tk?.productAreaID)
6160
const owner = tk?.name || group?.group
6261
const router = useRouter();
6362
const [error, setError] = useState<string | undefined>(undefined)
@@ -78,9 +77,6 @@ export const SearchResultLink = ({
7877
id: id
7978
},
8079
refetchQueries:[
81-
{
82-
query: GET_PRODUCT_AREAS,
83-
},
8480
{
8581
query: USER_INFO,
8682
}

lib/queries/productAreas/productArea.ts

-89
This file was deleted.

0 commit comments

Comments
 (0)