WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/api-v4/src/quotas/quotas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,38 @@ export const getQuotaUsage = (type: QuotaType, id: string) =>
setURL(`${BETA_API_ROOT}/${type}/quotas/${id}/usage`),
setMethod('GET'),
);

/**
* getGlobalQuotas
*
* Returns a paginated list of global quotas for a particular service specified by `type`.
*
* This request can be filtered on `quota_name`, `service_name` and `scope`.
*
* @param type { QuotaType } retrieve quotas within this service type.
*/
export const getGlobalQuotas = (
type: QuotaType,
params: Params = {},
filter: Filter = {},
) =>
Request<Page<Quota>>(
setURL(`${BETA_API_ROOT}/${type}/global-quotas`),
setMethod('GET'),
setXFilter(filter),
setParams(params),
);

/**
* getGlobalQuotaUsage
*
* Returns the usage for a single global quota within a particular service specified by `type`.
*
* @param type { QuotaType } retrieve a quota within this service type.
* @param id { string } the quota ID to look up.
*/
export const getGlobalQuotaUsage = (type: QuotaType, id: string) =>
Request<QuotaUsage>(
setURL(`${BETA_API_ROOT}/${type}/global-quotas/${id}/usage`),
setMethod('GET'),
);
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ describe('Quota workflow tests', () => {
usage: Math.round(mockQuotas[2].quota_limit * 0.1),
}),
];

cy.wrap(selectedDomain).as('selectedDomain');
cy.wrap(mockEndpoints).as('mockEndpoints');
cy.wrap(mockQuotas).as('mockQuotas');
cy.wrap(mockQuotaUsages).as('mockQuotaUsages');

mockGetObjectStorageQuotaUsages(
selectedDomain,
'bytes',
Expand Down Expand Up @@ -134,6 +136,7 @@ describe('Quota workflow tests', () => {
},
}).as('getFeatureFlags');
});

it('Quotas and quota usages display properly', function () {
cy.visitWithLogin('/account/quotas');
cy.wait(['@getFeatureFlags', '@getObjectStorageEndpoints']);
Expand Down Expand Up @@ -332,9 +335,11 @@ describe('Quota workflow tests', () => {
.should('be.visible')
.click();
cy.wait('@getQuotasError');
cy.get('[data-qa-error-msg="true"]')
.should('be.visible')
.should('have.text', errorMsg);
cy.get('[data-testid="endpoint-quotas-table-container"]').within(() => {
cy.get('[data-qa-error-msg="true"]')
.should('be.visible')
.should('have.text', errorMsg);
});
});
});

Expand Down Expand Up @@ -508,9 +513,12 @@ describe('Quota workflow tests', () => {
.should('be.visible')
.click();
cy.wait('@getQuotasError');
cy.get('[data-qa-error-msg="true"]')
.should('be.visible')
.should('have.text', errorMsg);

cy.get('[data-testid="endpoint-quotas-table-container"]').within(() => {
cy.get('[data-qa-error-msg="true"]')
.should('be.visible')
.should('have.text', errorMsg);
});
});

// this test executed in context of internal user, using mockApiInternalUser()
Expand Down
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;

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>
);
};
24 changes: 21 additions & 3 deletions packages/manager/src/features/Account/Quotas/Quotas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { DocumentTitleSegment } from 'src/components/DocumentTitle';
import { Link } from 'src/components/Link';
import { useFlags } from 'src/hooks/useFlags';

import { QuotasTable } from './QuotasTable';
import { GlobalQuotasTable } from './GlobalQuotasTable/GlobalQuotasTable';
import { QuotasTable } from './QuotasTable/QuotasTable';
import { useGetLocationsForQuotaService } from './utils';

import type { Quota } from '@linode/api-v4';
Expand All @@ -41,14 +42,26 @@ export const Quotas = () => {
return (
<>
<DocumentTitleSegment segment="Quotas" />

<Paper
sx={(theme: Theme) => ({
marginTop: theme.spacingFunction(16),
})}
variant="outlined"
>
<Typography variant="h2">Object Storage: global</Typography>

<GlobalQuotasTable />
</Paper>

<Paper
sx={(theme: Theme) => ({
marginTop: theme.spacingFunction(16),
})}
variant="outlined"
>
<Stack>
<Typography variant="h2">Object Storage</Typography>
<Typography variant="h2">Object Storage: per-endpoint</Typography>
<Box sx={{ display: 'flex' }}>
<Notice spacingTop={16} variant="info">
<Typography>
Expand Down Expand Up @@ -109,7 +122,12 @@ export const Quotas = () => {
</Link>
.
</Typography>
<Stack direction="column" spacing={2}>

<Stack
data-testid="endpoint-quotas-table-container"
direction="column"
spacing={2}
>
<QuotasTable
selectedLocation={selectedLocation}
selectedService={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { TableRowLoading } from 'src/components/TableRowLoading/TableRowLoading'
import { useFlags } from 'src/hooks/useFlags';
import { usePaginationV2 } from 'src/hooks/usePaginationV2';

import { QuotasIncreaseForm } from './QuotasIncreaseForm';
import { QuotasIncreaseForm } from '../QuotasIncreaseForm';
import { getQuotasFilters } from '../utils';
import { QuotasTableRow } from './QuotasTableRow';
import { getQuotasFilters } from './utils';

import type { Filter, Quota, QuotaType } from '@linode/api-v4';
import type { SelectOption } from '@linode/ui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { TableRow } from 'src/components/TableRow/TableRow';
import { useFlags } from 'src/hooks/useFlags';
import { useIsAkamaiAccount } from 'src/hooks/useIsAkamaiAccount';

import { convertResourceMetric, getQuotaError, pluralizeMetric } from './utils';
import {
convertResourceMetric,
getQuotaError,
pluralizeMetric,
} from '../utils';

import type { Quota, QuotaUsage } from '@linode/api-v4';
import type { UseQueryResult } from '@tanstack/react-query';
Expand Down
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) =>
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),
};
}
24 changes: 23 additions & 1 deletion packages/queries/src/quotas/keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getQuota, getQuotas, getQuotaUsage } from '@linode/api-v4';
import {
getGlobalQuotas,
getGlobalQuotaUsage,
getQuota,
getQuotas,
getQuotaUsage,
} from '@linode/api-v4';
import { createQueryKeys } from '@lukemorales/query-key-factory';

import { getAllQuotas } from './requests';
Expand Down Expand Up @@ -28,3 +34,19 @@ export const quotaQueries = createQueryKeys('quotas', {
queryKey: [type],
}),
});

export const globalQuotaQueries = createQueryKeys('global-quotas', {
service: (type: QuotaType) => ({
contextQueries: {
paginated: (params: Params = {}, filter: Filter = {}) => ({
queryFn: () => getGlobalQuotas(type, params, filter),
queryKey: [params, filter],
}),
usage: (id: string) => ({
queryFn: () => getGlobalQuotaUsage(type, id),
queryKey: [id],
}),
},
queryKey: [type],
}),
});
Loading