-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui-feat - homepage with quick stats of all streams (#184)
- Loading branch information
Showing
10 changed files
with
382 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { LogStreamRetention, LogStreamStat } from '@/@types/parseable/api/stream'; | ||
import { getLogStreamRetention, getLogStreamStats } from '@/api/logStream'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
type MetaData = { | ||
[key: string]: { | ||
stats: LogStreamStat | {}; | ||
retention: LogStreamRetention | []; | ||
}; | ||
}; | ||
|
||
// until dedicated endpoint been provided - fetch one by one | ||
export const useGetStreamMetadata = () => { | ||
const [isLoading, setLoading] = useState<Boolean>(false); | ||
const [error, setError] = useState<Boolean>(false); | ||
const [metaData, setMetadata] = useState<MetaData | null>(null); | ||
|
||
const getStreamMetadata = useCallback(async (streams: string[]) => { | ||
setLoading(true); | ||
try { | ||
// stats | ||
const allStatsReqs = streams.map((stream) => getLogStreamStats(stream)); | ||
const allStatsRes = await Promise.all(allStatsReqs); | ||
|
||
// retention | ||
const allretentionReqs = streams.map((stream) => getLogStreamRetention(stream)); | ||
const allretentionRes = await Promise.all(allretentionReqs); | ||
|
||
const metadata = streams.reduce((acc, stream, index) => { | ||
return { | ||
...acc, | ||
[stream]: { stats: allStatsRes[index]?.data || {}, retention: allretentionRes[index]?.data || [] }, | ||
}; | ||
}, {}); | ||
setMetadata(metadata); | ||
} catch { | ||
setError(true); | ||
setMetadata(null); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}, []); | ||
|
||
return { | ||
isLoading, | ||
error, | ||
getStreamMetadata, | ||
metaData, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.