-
Notifications
You must be signed in to change notification settings - Fork 366
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
feat: [M3-6971] Add dynamic pricing model to Volume creation flows #9569
Changes from 9 commits
65a6c3c
0ca779d
2892188
36cd9ca
65d6edc
64b15fc
e987d76
1ababb2
c7057fb
330c6cd
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/manager": Changed | ||
--- | ||
|
||
Allow volumes to feature the dynamic pricing model ([#9569](https://github.com/linode/manager/pull/9569)) |
abailly-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { Typography } from 'src/components/Typography'; | |
import { MAX_VOLUME_SIZE } from 'src/constants'; | ||
import EUAgreementCheckbox from 'src/features/Account/Agreements/EUAgreementCheckbox'; | ||
import { LinodeSelect } from 'src/features/Linodes/LinodeSelect/LinodeSelect'; | ||
import { useFlags } from 'src/hooks/useFlags'; | ||
import { | ||
reportAgreementSigningError, | ||
useAccountAgreements, | ||
|
@@ -44,6 +45,8 @@ import LabelField from '../VolumeDrawer/LabelField'; | |
import NoticePanel from '../VolumeDrawer/NoticePanel'; | ||
import SizeField from '../VolumeDrawer/SizeField'; | ||
|
||
export const SIZE_FIELD_WIDTH = 160; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
agreement: { | ||
maxWidth: '70%', | ||
|
@@ -90,7 +93,8 @@ const useStyles = makeStyles((theme: Theme) => ({ | |
width: 320, | ||
}, | ||
size: { | ||
width: 160, | ||
position: 'relative', | ||
width: SIZE_FIELD_WIDTH, | ||
}, | ||
tooltip: { | ||
'& .MuiTooltip-tooltip': { | ||
|
@@ -114,6 +118,8 @@ type CombinedProps = Props & StateProps; | |
const CreateVolumeForm: React.FC<CombinedProps> = (props) => { | ||
const theme = useTheme(); | ||
const classes = useStyles(); | ||
const flags = useFlags(); | ||
const { dcSpecificPricing } = flags; | ||
const { history, onSuccess, origin } = props; | ||
|
||
const { data: profile } = useProfile(); | ||
|
@@ -273,9 +279,20 @@ const CreateVolumeForm: React.FC<CombinedProps> = (props) => { | |
data-qa-volume-size-help | ||
variant="body1" | ||
> | ||
A single Volume can range from 10 to {MAX_VOLUME_SIZE} GB in | ||
size and costs $0.10/GB per month. <br /> | ||
Up to eight volumes can be attached to a single Linode. | ||
{dcSpecificPricing ? ( | ||
<span> | ||
A single Volume can range from 10 to 10240 GB in size. Up | ||
to eight Volumes can be attached to a single Linode. | ||
Select a Region to see cost per GB | ||
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.
|
||
</span> | ||
) : ( | ||
<span> | ||
A single Volume can range from 10 to {MAX_VOLUME_SIZE} GB | ||
in size and costs $0.10/GB per month. <br /> | ||
Up to eight volumes can be attached to a single Linode. | ||
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. |
||
</span> | ||
)} | ||
. | ||
</Typography> | ||
<LabelField | ||
tooltipText="Use only ASCII letters, numbers, | ||
|
@@ -290,17 +307,6 @@ const CreateVolumeForm: React.FC<CombinedProps> = (props) => { | |
tooltipPosition="right" | ||
value={values.label} | ||
/> | ||
<Box alignItems="flex-end" display="flex"> | ||
<SizeField | ||
disabled={doesNotHavePermission} | ||
error={touched.size ? errors.size : undefined} | ||
name="size" | ||
onBlur={handleBlur} | ||
onChange={handleChange} | ||
textFieldStyles={classes.size} | ||
value={values.size} | ||
/> | ||
</Box> | ||
<Box alignItems="flex-end" display="flex"> | ||
<RegionSelect | ||
handleSelection={(value) => { | ||
|
@@ -377,6 +383,20 @@ const CreateVolumeForm: React.FC<CombinedProps> = (props) => { | |
width={320} | ||
/> | ||
</Box> | ||
<Box alignItems="flex-end" display="flex" position="relative"> | ||
<SizeField | ||
disabled={doesNotHavePermission} | ||
error={touched.size ? errors.size : undefined} | ||
flags={flags} | ||
hasSelectedRegion={!isNilOrEmpty(values.region)} | ||
name="size" | ||
onBlur={handleBlur} | ||
onChange={handleChange} | ||
regionId={values.region} | ||
textFieldStyles={classes.size} | ||
value={values.size} | ||
/> | ||
</Box> | ||
<Box | ||
alignItems="center" | ||
className={classes.buttonGroup} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,40 @@ import * as React from 'react'; | |
import { Box } from 'src/components/Box'; | ||
import { DisplayPrice } from 'src/components/DisplayPrice'; | ||
import { MAX_VOLUME_SIZE } from 'src/constants'; | ||
import { getDynamicVolumePrice } from 'src/utilities/pricing/dynamicVolumePrice'; | ||
|
||
const getPrice = (size: number) => { | ||
return size * 0.1; | ||
}; | ||
|
||
const getClampedPrice = (newSize: number, currentSize: number) => | ||
newSize >= currentSize | ||
? newSize <= MAX_VOLUME_SIZE | ||
? getPrice(newSize) | ||
: getPrice(MAX_VOLUME_SIZE) | ||
: getPrice(currentSize); | ||
import type { FlagSet } from 'src/featureFlags'; | ||
|
||
interface Props { | ||
currentSize: number; | ||
flags: FlagSet; | ||
regionId: string; | ||
value: number; | ||
} | ||
|
||
export const PricePanel = ({ currentSize, value }: Props) => { | ||
export const PricePanel = ({ currentSize, flags, regionId, value }: Props) => { | ||
const getPrice = (size: number) => { | ||
return getDynamicVolumePrice({ | ||
flags, | ||
regionId, | ||
size, | ||
}); | ||
}; | ||
|
||
const getClampedPrice = ( | ||
newSize: number, | ||
currentSize: Props['currentSize'] | ||
) => | ||
newSize >= currentSize | ||
? newSize <= MAX_VOLUME_SIZE | ||
? getPrice(newSize) | ||
: getPrice(MAX_VOLUME_SIZE) | ||
: getPrice(currentSize); | ||
const price = getClampedPrice(value, currentSize); | ||
|
||
return ( | ||
<Box marginTop={4}> | ||
<DisplayPrice interval="mo" price={price} /> | ||
<DisplayPrice interval="mo" price={Number(price)} /> | ||
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. There's inconsistencies in the way price is passed to children resulting in some expecting a string and others a number, such as |
||
</Box> | ||
); | ||
}; |
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.