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

Commit ec1f03a

Browse files
authored
gateway: Pretty print limit numbers (#54584)
Large rate limits were hard to read, this formats numbers according to the machine locale as `1,000` or `1.000`. <img width="722" alt="Screenshot 2023-07-04 at 15 40 41@2x" src="https://github.com/sourcegraph/sourcegraph/assets/19534377/e729927e-ae85-454a-b877-b0d3b867ef40"> ## Test plan Verified manually, see screenshot.
1 parent abd06ad commit ec1f03a

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

client/web/src/enterprise/site-admin/dotcom/productSubscriptions/CodyGatewayRateLimitModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414

1515
import { UPDATE_CODY_GATEWAY_CONFIG } from './backend'
1616
import { ModelBadges } from './ModelBadges'
17-
import { prettyInterval } from './utils'
17+
import { numberFormatter, prettyInterval } from './utils'
1818

1919
export interface CodyGatewayRateLimitModalProps {
2020
onCancel: () => void
@@ -146,8 +146,8 @@ export const CodyGatewayRateLimitModal: React.FunctionComponent<
146146
onChange={onChangeLimitInterval}
147147
message={
148148
<>
149-
{limit} {mode === 'embeddings' ? 'tokens' : 'requests'} per{' '}
150-
{prettyInterval(limitInterval!)}
149+
{numberFormatter.format(BigInt(limit))} {mode === 'embeddings' ? 'tokens' : 'requests'}{' '}
150+
per {prettyInterval(limitInterval!)}
151151
</>
152152
}
153153
/>

client/web/src/enterprise/site-admin/dotcom/productSubscriptions/CodyServicesSection.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
} from './backend'
4848
import { CodyGatewayRateLimitModal } from './CodyGatewayRateLimitModal'
4949
import { ModelBadges } from './ModelBadges'
50-
import { prettyInterval } from './utils'
50+
import { numberFormatter, prettyInterval } from './utils'
5151

5252
import styles from './CodyServicesSection.module.scss'
5353

@@ -320,7 +320,8 @@ const RateLimitRow: React.FunctionComponent<RateLimitRowProps> = ({
320320
<CodyGatewayRateLimitSourceBadge source={rateLimit.source} />
321321
</td>
322322
<td>
323-
{rateLimit.limit} {mode === 'embeddings' ? 'tokens' : 'requests'} /{' '}
323+
{numberFormatter.format(BigInt(rateLimit.limit))}{' '}
324+
{mode === 'embeddings' ? 'tokens' : 'requests'} /{' '}
324325
{prettyInterval(rateLimit.intervalSeconds)}
325326
</td>
326327
<td>

client/web/src/enterprise/site-admin/dotcom/productSubscriptions/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ export function errorForPath(error: ApolloError | undefined, path: (string | num
3939
}
4040

4141
export const accessTokenPath = ['dotcom', 'productSubscription', 'currentSourcegraphAccessToken']
42+
43+
export const numberFormatter = new Intl.NumberFormat()

0 commit comments

Comments
 (0)