@@ -20,7 +20,12 @@ import React, {
2020 useMemo ,
2121 useState ,
2222} from "react" ;
23- import { Link , useLoaderData , useLocation , useParams } from "react-router" ;
23+ import {
24+ useLoaderData ,
25+ useLocation ,
26+ useNavigate ,
27+ useParams ,
28+ } from "react-router" ;
2429import { getZaaktype , getZaaktypen } from "~/api/zaaktype.ts" ;
2530import {
2631 RelatedObjectBadge ,
@@ -57,6 +62,7 @@ export const ZaaktypeAttributeGridTab = ({
5762} : ZaaktypeAttributeGridTabProps ) => {
5863 const { fields } = useLoaderData ( ) as ZaaktypeLoaderData ;
5964 const location = useLocation ( ) ;
65+ const navigate = useNavigate ( ) ;
6066 const { serviceSlug, catalogusId } = useParams ( ) ;
6167 invariant ( serviceSlug , "serviceSlug must be provided!" ) ;
6268
@@ -108,30 +114,36 @@ export const ZaaktypeAttributeGridTab = ({
108114
109115 if ( ! Array . isArray ( raw ) ) return ;
110116
111- let cancelled = false ;
112-
117+ let abortControllers : AbortController [ ] = [ ] ;
113118 const run = async ( ) => {
114119 const urls = raw as string [ ] ;
120+ const uuid = urls
121+ . map ( ( url ) => getZaaktypeUUID ( { url } ) )
122+ . filter ( ( uuid ) : uuid is string => Boolean ( uuid ) ) ;
123+ const fetchTuples = uuid . map ( ( zaaktypeUUID ) =>
124+ getZaaktype ( { serviceSlug, zaaktypeUUID } ) ,
125+ ) ;
126+ const promises : Promise <
127+ components [ "schemas" ] [ "DetailResponse_ExpandableZaakType_" ]
128+ > [ ] = [ ] ;
115129
116- const fetches = urls . map ( ( url ) => {
117- const zaaktypeUUID = getZaaktypeUUID ( { url } ) ;
118- return zaaktypeUUID ? getZaaktype ( { serviceSlug , zaaktypeUUID } ) : null ;
130+ fetchTuples . forEach ( ( [ promise , abortController ] ) => {
131+ promises . push ( promise ) ;
132+ abortControllers . push ( abortController ) ;
119133 } ) ;
120134
121- const results = await Promise . all ( fetches ) ;
122- if ( cancelled ) return ;
123-
124- const zaaktypen = results
125- . filter ( ( res ) => res !== null )
126- . map ( ( res ) => res . result ) ;
127-
135+ const results = await Promise . all ( promises ) ;
136+ const zaaktypen = results . map ( ( result ) => result . result ) ;
128137 setSelectedDeelzaaktypenOptions ( mapZaaktypenToOptions ( zaaktypen ) ) ;
129138 } ;
130139
131140 void run ( ) ;
132141
133142 return ( ) => {
134- cancelled = true ;
143+ abortControllers . forEach ( ( abortController ) =>
144+ abortController . abort ( "useEffect cleanup" ) ,
145+ ) ;
146+ abortControllers = [ ] ;
135147 } ;
136148 } , [ isEditing , fields , object , serviceSlug ] ) ;
137149
@@ -164,10 +176,14 @@ export const ZaaktypeAttributeGridTab = ({
164176 uuid && `/${ serviceSlug } /${ catalogusId } /zaaktypen/${ uuid } ` ;
165177
166178 return to ? (
167- < Badge >
168- < Link key = { option . value } to = { to } >
169- { option . label }
170- </ Link >
179+ < Badge
180+ href = { to }
181+ onClick = { ( e : React . MouseEvent ) => {
182+ e . preventDefault ( ) ;
183+ navigate ( to ) ;
184+ } }
185+ >
186+ { option . label }
171187 </ Badge >
172188 ) : (
173189 < Badge key = { option . value } > { option . label } </ Badge >
0 commit comments