@@ -20,37 +20,41 @@ export const useGetStreamMetadata = () => {
2020 const [ metaData , setMetadata ] = useState < MetaData | null > ( null ) ;
2121 const [ userRoles ] = useAppStore ( ( store ) => store . userRoles ) ;
2222
23- const getStreamMetadata = useCallback ( async ( streams : string [ ] ) => {
24- setLoading ( true ) ;
25- try {
26- // stats
27- const allStatsReqs = streams . map ( ( stream ) => getLogStreamStats ( stream ) ) ;
28- const allStatsRes = await Promise . all ( allStatsReqs ) ;
23+ const getStreamMetadata = useCallback (
24+ async ( streams : string [ ] ) => {
25+ if ( ! userRoles ) return ;
26+ setLoading ( true ) ;
27+ try {
28+ // stats
29+ const allStatsReqs = streams . map ( ( stream ) => getLogStreamStats ( stream ) ) ;
30+ const allStatsRes = await Promise . all ( allStatsReqs ) ;
2931
30- // retention
31- const streamsWithSettingsAccess = _ . filter ( streams , ( stream ) =>
32- _ . includes ( getStreamsSepcificAccess ( userRoles , stream ) , 'StreamSettings' ) ,
33- ) ;
34- const allretentionReqs = streamsWithSettingsAccess . map ( ( stream ) => getLogStreamRetention ( stream ) ) ;
35- const allretentionRes = await Promise . all ( allretentionReqs ) ;
32+ // retention
33+ const streamsWithSettingsAccess = _ . filter ( streams , ( stream ) =>
34+ _ . includes ( getStreamsSepcificAccess ( userRoles , stream ) , 'StreamSettings' ) ,
35+ ) ;
36+ const allretentionReqs = streamsWithSettingsAccess . map ( ( stream ) => getLogStreamRetention ( stream ) ) ;
37+ const allretentionRes = await Promise . all ( allretentionReqs ) ;
3638
37- const metadata = streams . reduce ( ( acc , stream , index ) => {
38- return {
39- ...acc ,
40- [ stream ] : { stats : allStatsRes [ index ] ?. data || { } , retention : allretentionRes [ index ] ?. data || [ ] } ,
41- } ;
42- } , { } ) ;
43- setMetadata ( metadata ) ;
44- } catch {
45- setError ( true ) ;
46- setMetadata ( null ) ;
47- notifyError ( {
48- message : 'Unable to fetch stream data' ,
49- } ) ;
50- } finally {
51- setLoading ( false ) ;
52- }
53- } , [ ] ) ;
39+ const metadata = streams . reduce ( ( acc , stream , index ) => {
40+ return {
41+ ...acc ,
42+ [ stream ] : { stats : allStatsRes [ index ] ?. data || { } , retention : allretentionRes [ index ] ?. data || [ ] } ,
43+ } ;
44+ } , { } ) ;
45+ setMetadata ( metadata ) ;
46+ } catch {
47+ setError ( true ) ;
48+ setMetadata ( null ) ;
49+ notifyError ( {
50+ message : 'Unable to fetch stream data' ,
51+ } ) ;
52+ } finally {
53+ setLoading ( false ) ;
54+ }
55+ } ,
56+ [ userRoles ] ,
57+ ) ;
5458
5559 return {
5660 isLoading,
0 commit comments