-
Notifications
You must be signed in to change notification settings - Fork 390
new: [STORIF-187] - Global quota usage table created. #13197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { Table } from 'src/components/Table/Table'; | ||
| import { TableBody } from 'src/components/TableBody'; | ||
| import { TableCell } from 'src/components/TableCell/TableCell'; | ||
| import { TableHead } from 'src/components/TableHead'; | ||
| import { TableRow } from 'src/components/TableRow/TableRow'; | ||
| import { TableRowEmpty } from 'src/components/TableRowEmpty/TableRowEmpty'; | ||
| import { TableRowError } from 'src/components/TableRowError/TableRowError'; | ||
| import { TableRowLoading } from 'src/components/TableRowLoading/TableRowLoading'; | ||
|
|
||
| import { useGetObjGlobalQuotasWithUsage } from '../hooks/useGetObjGlobalQuotasWithUsage'; | ||
| import { GlobalQuotasTableRow } from './GlobalQuotasTableRow'; | ||
|
|
||
| const quotaRowMinHeight = 58; | ||
|
|
||
| export const GlobalQuotasTable = () => { | ||
| const { | ||
| data: globalQuotasWithUsage, | ||
| isFetching: isFetchingGlobalQuotas, | ||
| isError: globalQuotasError, | ||
| } = useGetObjGlobalQuotasWithUsage(); | ||
|
|
||
| return ( | ||
| <Table | ||
| data-testid="table-endpoint-global-quotas" | ||
| sx={(theme) => ({ | ||
| marginTop: theme.spacingFunction(16), | ||
| minWidth: theme.breakpoints.values.sm, | ||
| })} | ||
| > | ||
| <TableHead> | ||
| <TableRow> | ||
| <TableCell sx={{ width: '25%' }}>Quota Name</TableCell> | ||
| <TableCell sx={{ width: '30%' }}>Account Quota Value</TableCell> | ||
| <TableCell sx={{ width: '35%' }}>Usage</TableCell> | ||
| </TableRow> | ||
| </TableHead> | ||
|
|
||
| <TableBody> | ||
| {isFetchingGlobalQuotas ? ( | ||
| <TableRowLoading columns={3} sx={{ height: quotaRowMinHeight }} /> | ||
| ) : globalQuotasError ? ( | ||
| <TableRowError | ||
| colSpan={3} | ||
| message="There was an error retrieving global object storage quotas." | ||
| /> | ||
| ) : globalQuotasWithUsage.length === 0 ? ( | ||
| <TableRowEmpty | ||
| colSpan={3} | ||
| message="There is no data available for this service." | ||
| sx={{ height: quotaRowMinHeight }} | ||
| /> | ||
| ) : ( | ||
| globalQuotasWithUsage.map((globalQuota, index) => { | ||
| return ( | ||
| <GlobalQuotasTableRow globalQuota={globalQuota} key={index} /> | ||
| ); | ||
| }) | ||
| )} | ||
| </TableBody> | ||
| </Table> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { Box, TooltipIcon, Typography } from '@linode/ui'; | ||
| import React from 'react'; | ||
|
|
||
| import { QuotaUsageBar } from 'src/components/QuotaUsageBar/QuotaUsageBar'; | ||
| import { TableCell } from 'src/components/TableCell/TableCell'; | ||
| import { TableRow } from 'src/components/TableRow/TableRow'; | ||
|
|
||
| import { convertResourceMetric, pluralizeMetric } from '../utils'; | ||
|
|
||
| import type { Quota, QuotaUsage } from '@linode/api-v4'; | ||
|
|
||
| interface GlobalQuotaWithUsage extends Quota { | ||
| usage?: QuotaUsage; | ||
| } | ||
| interface Params { | ||
| globalQuota: GlobalQuotaWithUsage; | ||
| } | ||
|
|
||
| const quotaRowMinHeight = 58; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to a constant file as QUOTA_ROW_MIN_HEIGHT since reused in multiple components |
||
|
|
||
| export const GlobalQuotasTableRow = ({ globalQuota }: Params) => { | ||
| const { convertedLimit, convertedResourceMetric } = convertResourceMetric({ | ||
| initialResourceMetric: pluralizeMetric( | ||
| globalQuota.quota_limit, | ||
| globalQuota.resource_metric | ||
| ), | ||
| initialUsage: globalQuota.usage?.usage ?? 0, | ||
| initialLimit: globalQuota.quota_limit, | ||
| }); | ||
|
|
||
| return ( | ||
| <TableRow sx={{ height: quotaRowMinHeight }}> | ||
| <TableCell> | ||
| <Box alignItems="center" display="flex" flexWrap="nowrap"> | ||
| <Typography | ||
| sx={{ | ||
| whiteSpace: 'nowrap', | ||
| }} | ||
| > | ||
| {globalQuota.quota_name} | ||
| </Typography> | ||
| <TooltipIcon | ||
| placement="top" | ||
| status="info" | ||
| sxTooltipIcon={{ | ||
| position: 'relative', | ||
| top: -2, | ||
| }} | ||
| text={globalQuota.description} | ||
| tooltipPosition="right" | ||
| /> | ||
| </Box> | ||
| </TableCell> | ||
|
|
||
| <TableCell> | ||
| {convertedLimit?.toLocaleString() ?? 'unknown'}{' '} | ||
| {convertedResourceMetric} | ||
| </TableCell> | ||
|
|
||
| <TableCell> | ||
| <Box sx={{ maxWidth: '80%' }}> | ||
| {globalQuota.usage?.usage ? ( | ||
| <QuotaUsageBar | ||
| limit={globalQuota.quota_limit} | ||
| resourceMetric={globalQuota.resource_metric} | ||
| usage={globalQuota.usage.usage} | ||
| /> | ||
| ) : ( | ||
| <Typography>n/a</Typography> | ||
| )} | ||
| </Box> | ||
| </TableCell> | ||
| </TableRow> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { | ||
| globalQuotaQueries, | ||
| useGlobalQuotasQuery, | ||
| useQueries, | ||
| } from '@linode/queries'; | ||
| import React from 'react'; | ||
|
|
||
| const SERVICE = 'object-storage'; | ||
|
|
||
| export function useGetObjGlobalQuotasWithUsage() { | ||
| const { | ||
| data: globalQuotas, | ||
| error: globalQuotasError, | ||
| isFetching: isFetchingGlobalQuotas, | ||
| } = useGlobalQuotasQuery(SERVICE); | ||
|
|
||
| // Quota Usage Queries | ||
| // For each global quota, fetch the usage in parallel | ||
| // This will only fetch for the paginated set | ||
| const globalQuotaIds = | ||
| globalQuotas?.data.map((quota) => quota.quota_id) ?? []; | ||
| const globalQuotaUsageQueries = useQueries({ | ||
| queries: globalQuotaIds.map((quotaId) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How many quota IDs could you end up having to fetch in parallel? Asking because this could end up being a bad performance bottleneck if running queries for dozens (hundreds) of IDs. |
||
| globalQuotaQueries.service(SERVICE)._ctx.usage(quotaId) | ||
| ), | ||
| }); | ||
|
|
||
| // Combine the quotas with their usage | ||
| const globalQuotasWithUsage = React.useMemo( | ||
| () => | ||
| globalQuotas?.data.map((quota, index) => ({ | ||
| ...quota, | ||
| usage: globalQuotaUsageQueries?.[index]?.data, | ||
| })) ?? [], | ||
| [globalQuotas, globalQuotaUsageQueries] | ||
| ); | ||
|
|
||
| return { | ||
| data: globalQuotasWithUsage, | ||
| isError: | ||
| globalQuotasError || | ||
| globalQuotaUsageQueries.some((query) => query.isError), | ||
| isFetching: | ||
| isFetchingGlobalQuotas || | ||
| globalQuotaUsageQueries.some((query) => query.isFetching), | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need a "get all" method as well? Could we have more than 500 records?