-
Notifications
You must be signed in to change notification settings - Fork 16
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
CORE2016: add support for addon rates. #613
base: main
Are you sure you want to change the base?
Changes from all commits
ceffc5e
f8e4f16
63ca8f5
325d5de
f8fdbe2
6c21780
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,127 @@ | ||||||||||
/** | ||||||||||
* Form fields for adding, editing, and deleting app addon rates. | ||||||||||
* | ||||||||||
* @author sarahr | ||||||||||
*/ | ||||||||||
|
||||||||||
import React from "react"; | ||||||||||
import { useTranslation } from "i18n"; | ||||||||||
import { | ||||||||||
Button, | ||||||||||
TableContainer, | ||||||||||
Table, | ||||||||||
TableHead, | ||||||||||
TableRow, | ||||||||||
TableCell, | ||||||||||
TableBody, | ||||||||||
Typography, | ||||||||||
} from "@mui/material"; | ||||||||||
import { | ||||||||||
FormNumberField, | ||||||||||
FormTimestampField, | ||||||||||
} from "components/forms/FormField"; | ||||||||||
import buildID from "components/utils/DebugIDUtil"; | ||||||||||
import { minValue, nonEmptyField } from "components/utils/validations"; | ||||||||||
import { Field } from "formik"; | ||||||||||
import { Add, Delete } from "@mui/icons-material"; | ||||||||||
|
||||||||||
import ids from "../../ids"; | ||||||||||
|
||||||||||
function AddonRateEditorRow(props) { | ||||||||||
const { baseId, fieldName, key, onDelete } = props; | ||||||||||
const { t: i18nUtil } = useTranslation("util"); | ||||||||||
const { t } = useTranslation(["common"]); | ||||||||||
|
||||||||||
return ( | ||||||||||
<TableRow> | ||||||||||
<TableCell> | ||||||||||
<Field | ||||||||||
component={FormNumberField} | ||||||||||
id={buildID(baseId, ids.ADDONS_DLG.ADDON_RATE.RATE)} | ||||||||||
name={`${fieldName}.rate`} | ||||||||||
required | ||||||||||
validate={(value) => minValue(value, i18nUtil)} | ||||||||||
/> | ||||||||||
</TableCell> | ||||||||||
<TableCell> | ||||||||||
<Field | ||||||||||
component={FormTimestampField} | ||||||||||
id={buildID( | ||||||||||
baseId, | ||||||||||
ids.ADDONS_DLG.ADDON_RATE.EFFECTIVE_DATE | ||||||||||
)} | ||||||||||
name={`${fieldName}.effectiveDate`} | ||||||||||
required | ||||||||||
validate={(value) => nonEmptyField(value, i18nUtil)} | ||||||||||
/> | ||||||||||
</TableCell> | ||||||||||
<TableCell passing="none"> | ||||||||||
<Button | ||||||||||
id={buildID(baseId, ids.DELETE_BUTTON)} | ||||||||||
aria-label={t("common:delete")} | ||||||||||
onClick={() => { | ||||||||||
onDelete(key); | ||||||||||
}} | ||||||||||
Comment on lines
+62
to
+64
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. I don't think the
The
Suggested change
|
||||||||||
> | ||||||||||
<Delete /> | ||||||||||
</Button> | ||||||||||
</TableCell> | ||||||||||
</TableRow> | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
function AddonRatesEditor(props) { | ||||||||||
const { addonRates, baseId, fieldName, onAdd, onDelete } = props; | ||||||||||
|
||||||||||
const { t } = useTranslation(["subscriptions", "common"]); | ||||||||||
|
||||||||||
return ( | ||||||||||
<> | ||||||||||
<TableContainer> | ||||||||||
<Table> | ||||||||||
<Typography component="caption"> | ||||||||||
{t("subscriptions:addonRates")} | ||||||||||
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 not required to namespace these
Suggested change
|
||||||||||
</Typography> | ||||||||||
<TableHead> | ||||||||||
<TableRow> | ||||||||||
<TableCell> | ||||||||||
<Typography> | ||||||||||
{t("subscriptions:rate")} | ||||||||||
</Typography> | ||||||||||
</TableCell> | ||||||||||
<TableCell> | ||||||||||
<Typography> | ||||||||||
{t("subscriptions:effectiveDate")} | ||||||||||
</Typography> | ||||||||||
</TableCell> | ||||||||||
<TableCell> | ||||||||||
<Button | ||||||||||
id={buildID(baseId, ids.ADD_BUTTON)} | ||||||||||
color="primary" | ||||||||||
variant="outlined" | ||||||||||
startIcon={<Add />} | ||||||||||
onClick={onAdd} | ||||||||||
> | ||||||||||
{t("common:add")} | ||||||||||
</Button> | ||||||||||
</TableCell> | ||||||||||
</TableRow> | ||||||||||
</TableHead> | ||||||||||
<TableBody> | ||||||||||
{addonRates?.map((addonRate, index) => ( | ||||||||||
<AddonRateEditorRow | ||||||||||
addonRate={addonRate} | ||||||||||
baseId={buildID(baseId, index)} | ||||||||||
fieldName={`${fieldName}.${index}`} | ||||||||||
key={index} | ||||||||||
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 possible using the It might be better to use |
||||||||||
onDelete={onDelete} | ||||||||||
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.
Suggested change
|
||||||||||
/> | ||||||||||
))} | ||||||||||
</TableBody> | ||||||||||
</Table> | ||||||||||
</TableContainer> | ||||||||||
</> | ||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
export default AddonRatesEditor; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,19 @@ | ||||||
import dateConstants from "components/utils/dateConstants"; | ||||||
import { formatDateObject } from "components/utils/DateFormatter"; | ||||||
import { bytesInGiB, bytesToGiB } from "../../utils"; | ||||||
|
||||||
function formatEffectiveDate(effectiveDate) { | ||||||
return formatDateObject(new Date(effectiveDate), dateConstants.ISO_8601); | ||||||
} | ||||||
|
||||||
function mapPropsToValues(addon) { | ||||||
let values = { | ||||||
addonName: "", | ||||||
description: "", | ||||||
defaultAmount: 0, | ||||||
defaultPaid: true, | ||||||
resourceType: "", | ||||||
addonRates: [], | ||||||
}; | ||||||
|
||||||
if (addon) { | ||||||
|
@@ -17,6 +24,7 @@ function mapPropsToValues(addon) { | |||||
default_amount, | ||||||
default_paid, | ||||||
resource_type, | ||||||
addon_rates, | ||||||
} = addon; | ||||||
|
||||||
values = { | ||||||
|
@@ -30,6 +38,14 @@ function mapPropsToValues(addon) { | |||||
: default_amount, | ||||||
defaultPaid: default_paid, | ||||||
resourceType: resource_type.unit, | ||||||
addonRates: addon_rates.map((addonRate, index) => { | ||||||
return { | ||||||
uuid, | ||||||
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. This
Suggested change
|
||||||
effectiveDate: addonRate.effective_date, | ||||||
key: `addonRates.${index}`, | ||||||
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. I don't think the |
||||||
rate: addonRate.rate, | ||||||
}; | ||||||
}), | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -44,13 +60,14 @@ function formatAddonSubmission(values, resourceTypes, update = false) { | |||||
defaultAmount, | ||||||
defaultPaid, | ||||||
resourceType, | ||||||
addonRates, | ||||||
} = values; | ||||||
|
||||||
const resourceObj = resourceTypes.find( | ||||||
(resource) => resourceType === resource.unit | ||||||
); | ||||||
|
||||||
const { id, unit, name } = resourceObj; | ||||||
const { id, unit, name, consumable } = resourceObj; | ||||||
|
||||||
const submission = { | ||||||
name: addonName, | ||||||
|
@@ -60,6 +77,13 @@ function formatAddonSubmission(values, resourceTypes, update = false) { | |||||
resource_type: { | ||||||
uuid: id, | ||||||
}, | ||||||
addon_rates: addonRates.map((addonRate) => { | ||||||
return { | ||||||
uuid, | ||||||
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. This also looks like the addon's
Suggested change
|
||||||
effective_date: formatEffectiveDate(addonRate.effectiveDate), | ||||||
rate: addonRate.rate, | ||||||
}; | ||||||
}), | ||||||
}; | ||||||
|
||||||
// Include the submission's UUID if an update is requested | ||||||
|
@@ -70,6 +94,7 @@ function formatAddonSubmission(values, resourceTypes, update = false) { | |||||
...submission.resource_type, | ||||||
unit, | ||||||
name, | ||||||
consumable, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
@author sriram | ||
*/ | ||
|
||
import lightFormat from "date-fns/lightFormat"; | ||
import format from "date-fns/format"; | ||
import toDate from "date-fns/toDate"; | ||
import dateConstants from "./dateConstants"; | ||
import { formatDistance, fromUnixTime } from "date-fns"; | ||
|
@@ -16,7 +16,7 @@ import { formatDistance, fromUnixTime } from "date-fns"; | |
function formatDate(longDate, dateFormat = dateConstants.LONG_DATE_FORMAT) { | ||
const longDateInt = parseInt(longDate, 10); | ||
return longDateInt | ||
? lightFormat(toDate(new Date(longDateInt)), dateFormat) | ||
? format(toDate(new Date(longDateInt)), dateFormat) | ||
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. The switch from |
||
: dateConstants.EMPTY_DATE; | ||
} | ||
|
||
|
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.
Was
addons
intentionally changed toaddonRates
?It looks like the
addons
label is still in use, since in the screenshot of these updates, the tab in the/admin/subscriptions
page now readsaddons
instead ofAdd-ons
(and if you view the browser console in storybook or dev mode, the i18n lib should report a warning that theaddons
messages key was not found).So should
addonRates
just be a new key/message?