-
Notifications
You must be signed in to change notification settings - Fork 370
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
refactor: [M3-7382] - Use object-storage/types
endpoint for pricing data
#10468
Changes from all commits
216b200
78d8142
fa8e243
91c1b2b
d9e2701
c1d423a
e504163
9f3a6ed
4ba4291
27e2ef5
87925d7
519f687
702f2ce
e7ec121
2517731
5ad54d8
224d943
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,5 @@ | ||
--- | ||
"@linode/api-v4": Added | ||
--- | ||
|
||
New endpoint for `object-storage/types` ([#10468](https://github.com/linode/manager/pull/10468)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Params, PriceType, ResourcePage } from 'src/types'; | ||
import { API_ROOT } from '../constants'; | ||
import Request, { setMethod, setParams, setURL } from '../request'; | ||
|
||
/** | ||
* getObjectStorageTypes | ||
* | ||
* Return a paginated list of available Object Storage types; used for pricing. | ||
* This endpoint does not require authentication. | ||
*/ | ||
export const getObjectStorageTypes = (params?: Params) => | ||
Request<ResourcePage<PriceType>>( | ||
setURL(`${API_ROOT}/object-storage/types`), | ||
setMethod('GET'), | ||
setParams(params) | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Changed | ||
--- | ||
|
||
Use dynamic pricing with `object-storage/types` endpoint ([#10468](https://github.com/linode/manager/pull/10468)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,15 @@ import { | |
useCreateBucketMutation, | ||
useObjectStorageBuckets, | ||
useObjectStorageClusters, | ||
useObjectStorageTypesQuery, | ||
} from 'src/queries/objectStorage'; | ||
import { useProfile } from 'src/queries/profile'; | ||
import { useRegionsQuery } from 'src/queries/regions/regions'; | ||
import { isFeatureEnabled } from 'src/utilities/accountCapabilities'; | ||
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. Just noticed this, 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. True. Out of scope of this PR, though. |
||
import { sendCreateBucketEvent } from 'src/utilities/analytics'; | ||
import { getErrorMap } from 'src/utilities/errorUtils'; | ||
import { getGDPRDetails } from 'src/utilities/formatRegion'; | ||
import { PRICES_RELOAD_ERROR_NOTICE_TEXT } from 'src/utilities/pricing/constants'; | ||
|
||
import { EnableObjectStorageModal } from '../EnableObjectStorageModal'; | ||
import ClusterSelect from './ClusterSelect'; | ||
|
@@ -74,6 +76,14 @@ export const CreateBucketDrawer = (props: Props) => { | |
: undefined, | ||
}); | ||
|
||
const { | ||
data: types, | ||
isError: isErrorTypes, | ||
isLoading: isLoadingTypes, | ||
} = useObjectStorageTypesQuery(isOpen); | ||
|
||
const isInvalidPrice = !types || isErrorTypes; | ||
|
||
const { | ||
error, | ||
isLoading, | ||
|
@@ -199,9 +209,15 @@ export const CreateBucketDrawer = (props: Props) => { | |
'data-testid': 'create-bucket-button', | ||
disabled: | ||
!formik.values.cluster || | ||
(showGDPRCheckbox && !hasSignedAgreement), | ||
(showGDPRCheckbox && !hasSignedAgreement) || | ||
isErrorTypes, | ||
label: 'Create Bucket', | ||
loading: isLoading, | ||
loading: | ||
isLoading || Boolean(clusterRegion?.[0]?.id && isLoadingTypes), | ||
tooltipText: | ||
!isLoadingTypes && isInvalidPrice | ||
? PRICES_RELOAD_ERROR_NOTICE_TEXT | ||
: '', | ||
type: 'submit', | ||
}} | ||
secondaryButtonProps={{ label: 'Cancel', onClick: onClose }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,18 @@ import { Region } from '@linode/api-v4'; | |
import { styled } from '@mui/material/styles'; | ||
import React from 'react'; | ||
|
||
import { CircularProgress } from 'src/components/CircularProgress'; | ||
import { TextTooltip } from 'src/components/TextTooltip'; | ||
import { Typography } from 'src/components/Typography'; | ||
import { OBJ_STORAGE_PRICE } from 'src/utilities/pricing/constants'; | ||
import { objectStoragePriceIncreaseMap } from 'src/utilities/pricing/dynamicPricing'; | ||
import { useObjectStorageTypesQuery } from 'src/queries/objectStorage'; | ||
import { | ||
OBJ_STORAGE_PRICE, | ||
UNKNOWN_PRICE, | ||
} from 'src/utilities/pricing/constants'; | ||
import { | ||
getDCSpecificPriceByType, | ||
objectStoragePriceIncreaseMap, | ||
} from 'src/utilities/pricing/dynamicPricing'; | ||
|
||
interface Props { | ||
regionId: Region['id']; | ||
|
@@ -18,23 +26,40 @@ export const GLOBAL_TRANSFER_POOL_TOOLTIP_TEXT = | |
|
||
export const OveragePricing = (props: Props) => { | ||
const { regionId } = props; | ||
|
||
const { data: types, isError, isLoading } = useObjectStorageTypesQuery(); | ||
|
||
const overageType = types?.find( | ||
(type) => type.id === 'objectstorage-overage' | ||
); | ||
|
||
const storageOveragePrice = getDCSpecificPriceByType({ | ||
decimalPrecision: 3, | ||
interval: 'hourly', | ||
regionId, | ||
type: overageType, | ||
}); | ||
|
||
const isDcSpecificPricingRegion = objectStoragePriceIncreaseMap.hasOwnProperty( | ||
regionId | ||
); | ||
|
||
return ( | ||
return isLoading ? ( | ||
<CircularProgress size={16} sx={{ marginTop: 2 }} /> | ||
) : ( | ||
<> | ||
<StyledTypography> | ||
For this region, additional storage costs{' '} | ||
<strong> | ||
$ | ||
{isDcSpecificPricingRegion | ||
? objectStoragePriceIncreaseMap[regionId].storage_overage | ||
: OBJ_STORAGE_PRICE.storage_overage}{' '} | ||
{storageOveragePrice && !isError | ||
? parseFloat(storageOveragePrice) | ||
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. Using |
||
: UNKNOWN_PRICE}{' '} | ||
per GB | ||
</strong> | ||
. | ||
</StyledTypography> | ||
|
||
<StyledTypography> | ||
Outbound transfer will cost{' '} | ||
<strong> | ||
|
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.
Not specific to your work, just curious to know what
transfer
represents in the payload?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.
It's the 1TB transfer quota (added to the global network transfer pool) that comes with enabling Object Storage. (Docs)