-
Notifications
You must be signed in to change notification settings - Fork 365
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 16 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)) |
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. All of these constants are old and can be cleaned up. They were leftovers from earlier stages of the project, pre-full GA. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,3 +172,49 @@ export const volumeTypeFactory = Factory.Sync.makeFactory<PriceType>({ | |
], | ||
transfer: 0, | ||
}); | ||
|
||
export const objectStorageTypeFactory = Factory.Sync.makeFactory<PriceType>({ | ||
id: 'objectstorage', | ||
label: 'Object Storage', | ||
price: { | ||
hourly: 0.0075, | ||
monthly: 5.0, | ||
}, | ||
region_prices: [ | ||
{ | ||
hourly: 0.0075, | ||
id: 'id-cgk', | ||
monthly: 5.0, | ||
}, | ||
{ | ||
hourly: 0.0075, | ||
id: 'br-gru', | ||
monthly: 5.0, | ||
}, | ||
], | ||
transfer: 1000, | ||
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. Not specific to your work, just curious to know what 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. It's the 1TB transfer quota (added to the global network transfer pool) that comes with enabling Object Storage. (Docs) |
||
}); | ||
|
||
export const objectStorageOverageTypeFactory = Factory.Sync.makeFactory<PriceType>( | ||
{ | ||
id: 'objectstorage-overage', | ||
label: 'Object Storage Overage', | ||
price: { | ||
hourly: 0.02, | ||
monthly: null, | ||
}, | ||
region_prices: [ | ||
{ | ||
hourly: 0.024, | ||
id: 'id-cgk', | ||
monthly: null, | ||
}, | ||
{ | ||
hourly: 0.028, | ||
id: 'br-gru', | ||
monthly: null, | ||
}, | ||
], | ||
transfer: 0, | ||
} | ||
); |
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.
None of the other object-storage endpoint files seemed like a good fit for this, so I created a new file,
prices.ts
. I didn't name ittypes.ts
, since that's another file. This seemed like the most straight-forward way to add the new endpoint.