1
1
import React , { ReactNode } from 'react'
2
2
import styled , { css } from 'styled-components'
3
3
import Link from '~/shared/components/Link'
4
+ import { useMultipleStreamStatsQuery } from '~/hooks/useStreamStats'
4
5
5
6
const SingleBadge = styled . div `
6
7
display: flex;
@@ -26,6 +27,7 @@ const SingleBadge = styled.div`
26
27
margin-left: 8px;
27
28
}
28
29
`
30
+
29
31
type BadgeContainerProps = {
30
32
children : ReactNode
31
33
top ?: boolean
@@ -134,4 +136,59 @@ const DataUnionBadge = ({
134
136
135
137
const BadgeLink = ( { ...props } ) => < Link { ...props } />
136
138
137
- export { DataUnionBadge }
139
+ const StatsBadge = styled . div `
140
+ display: flex;
141
+ align-items: center;
142
+ padding: 4px 8px;
143
+ gap: 10px;
144
+ background: rgba(245, 245, 247, 0.6);
145
+ backdrop-filter: blur(13.3871px);
146
+ border-radius: 8px;
147
+
148
+ font-weight: 500;
149
+ font-size: 16px;
150
+ line-height: 24px;
151
+ color: #323232;
152
+
153
+ a,
154
+ a:link,
155
+ a:active,
156
+ a:focus,
157
+ a:hover,
158
+ a:visited {
159
+ color: white !important;
160
+ }
161
+
162
+ > * + * {
163
+ margin-left: 8px;
164
+ }
165
+ `
166
+
167
+ interface StreamStatsBadgeProps extends Omit < BadgeContainerProps , 'children' > {
168
+ streamIds : string [ ]
169
+ }
170
+
171
+ const StreamStatsBadge = ( { streamIds, ...props } : StreamStatsBadgeProps ) => {
172
+ const { data : stats , isLoading, error } = useMultipleStreamStatsQuery ( streamIds )
173
+
174
+ if ( error || isLoading ) {
175
+ return null
176
+ }
177
+
178
+ const messagesPerSecond = stats ?. messagesPerSecond
179
+ const formattedMsgRate =
180
+ typeof messagesPerSecond === 'number' ? messagesPerSecond . toFixed ( 1 ) : 'N/A'
181
+
182
+ return (
183
+ < BadgeContainer { ...props } >
184
+ < StatsBadge >
185
+ < span >
186
+ { streamIds . length } { streamIds . length === 1 ? 'Stream' : 'Streams' }
187
+ </ span >
188
+ < span > { formattedMsgRate } Msg/s</ span >
189
+ </ StatsBadge >
190
+ </ BadgeContainer >
191
+ )
192
+ }
193
+
194
+ export { DataUnionBadge , StreamStatsBadge }
0 commit comments