Skip to content

Commit

Permalink
updated redis costs
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-porru committed Nov 29, 2024
1 parent eddbdb9 commit d4e7987
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 7 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import calculateAdditionalCosts from './calculateAdditionalCosts';

test('total costs', () => {
const redis = 74;

const additionalCosts = calculateAdditionalCosts({ redis });

expect(additionalCosts).toBe(74);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface Props {
redis: number;
}

export default function calculateAdditionalCosts(props: Props): number {
const { redis } = props;

return (
redis
);
}
10 changes: 7 additions & 3 deletions src/calculatorFunctions/totalCosts/calculateTotalCosts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import calculateBaseConfigCosts from '../baseConfigCosts/calculateBaseConfigCosts';
import calculateStorageCosts from '../storageCosts/calculateStorageCosts';
import calculateAdditionalCosts from '../additionalConfig/calculateAdditionalCosts';
import calculateTotalCosts from './calculateTotalCosts';

test('total costs', () => {
Expand All @@ -11,9 +12,10 @@ test('total costs', () => {
// Storage
const GBQuantity = 1024;
const premiumGBQuantity = 1024;
// Additional config
const redis = 74;

const conversionRatio = 0.35;
const additionalCosts = 1;

const baseConfigCosts = calculateBaseConfigCosts({
timeConsumption,
Expand All @@ -27,13 +29,15 @@ test('total costs', () => {
timeConsumption,
});

const additionalCosts = calculateAdditionalCosts({redis});

const totalCosts = calculateTotalCosts({
baseConfigCosts,
storageCosts,
additionalCosts,
conversionRatio,
});

expect(totalCosts.CU).toBe(3701);
expect(totalCosts.CC).toBe(1295.35);
expect(totalCosts.CU).toBe(3774);
expect(totalCosts.CC.toFixed(2)).toBe('1320.90');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import config from '../../../../config.json';
import { Option, Select, Title } from '@ui5/webcomponents-react';
import { RedisSize, redisState } from '../../../../state/additionalConfig/redisState';
import { useSetRecoilState } from 'recoil';

export default function RedisSelect() {
const redisConfigOptions = config.RedisCosts.Tiers;
const setVmSize = useSetRecoilState<RedisSize>(redisState);

const onChange = (event: any) => {
const selection = event.detail.selectedOption.dataset;
setVmSize({
value: +selection.value,
tsize: selection.key
});
};

return (
<>
<Title className="wizard-subheader" level="H5">
Cloud-managed Redis cache
</Title>
<Select onChange={onChange}>
{redisConfigOptions.map((item) => (
<Option
key={item.key}
data-key={item.key}
data-value={item.value}
>
{item.key}
</Option>
))}
</Select>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function VMsizeSelect() {

return (
<>
<Title className="wizard-subheader" level="H5" size="H5">
<Title className="wizard-subheader" level="H5" >
Machine Type
</Title>
<Select onChange={onChange}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function VMsizeSelect() {

return (
<>
<Title className="wizard-subheader" level="H5" size="H5">
<Title className="wizard-subheader" level="H5" >
Virtual Machine Size
</Title>
<Select onChange={onChange}>
Expand Down
11 changes: 9 additions & 2 deletions src/components/CostWizard/WizardSteps/AdditionalConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,31 @@ import ApplyConversionRate from '../UserInputs/additionalConfig/applyConversionR
import { useCostCalculator } from '../../../context/CostCalculatorContext';
import { useRecoilValue } from 'recoil';
import { applyConversionRateState } from '../../../state/additionalConfig/applyConversionRateState';
import { RedisSize, redisState } from '../../../state/additionalConfig/redisState';
import Redis from '../UserInputs/additionalConfig/RedisSelect';
import calculateAdditionalCosts from '../../../calculatorFunctions/additionalConfig/calculateAdditionalCosts';

export default function NodeStep() {
const conversionRatio = useRecoilValue<number>(applyConversionRateState);
const redis = useRecoilValue<RedisSize>(redisState);

const { setConversionRatio } = useCostCalculator();
const { setAdditionalCosts } = useCostCalculator();

useEffect(() => {
setConversionRatio(conversionRatio);
}, [setConversionRatio, conversionRatio]);
setAdditionalCosts(calculateAdditionalCosts({redis: redis.value}));
}, [setConversionRatio, setAdditionalCosts, conversionRatio, redis]);

return (
<WizardStep disabled titleText="Additional Configuration">
<Title wrappingType="Normal" level="H2" size="H2">
<Title wrappingType="Normal" level="H2" >
3. Additional Configuration
</Title>
<div className="StepContent">
<InfoField info="The 'conversion rate' will help you to calculate eventual discounts." />
<ApplyConversionRate />
<Redis />
</div>
<div className="ButtonContainer">
<PreviousStepButton />
Expand Down
34 changes: 34 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,39 @@
"PricePerUnit": 39,
"PricePerUnitDivider": 32,
"PricePerUnitDivider2": 720
},
"RedisCosts":{
"Tiers":[
{"key": "None",
"value": 0},
{"key": "Standard1",
"value": 74},
{"key": "Standard2",
"value": 148},
{"key": "Standard3",
"value": 387},
{"key": "Standard4",
"value": 778},
{"key": "Standard5",
"value": 1541},
{"key": "Standard6",
"value": 3084},
{"key": "Standard7",
"value": 6167},
{"key": "Standard8",
"value": 12331},
{"key": "Premium1",
"value": 773},
{"key": "Premium2",
"value": 1555},
{"key": "Premium3",
"value": 3082},
{"key": "Premium4",
"value": 6167},
{"key": "Premium5",
"value": 12335},
{"key": "Premium6",
"value": 24661}
]
}
}
14 changes: 14 additions & 0 deletions src/state/additionalConfig/redisState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { atom, RecoilState } from 'recoil';
import config from '../../config.json';

export interface RedisSize {
tsize: string;
value: number;
}

export const redisState: RecoilState<RedisSize> = atom<RedisSize>({
key: 'redisState',
default: {
tsize: config.RedisCosts.Tiers[0].key,
value: config.RedisCosts.Tiers[0].value}
});

0 comments on commit d4e7987

Please sign in to comment.