Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

slr71
Copy link
Member

@slr71 slr71 commented Jan 7, 2025

This PR adds support for addon rates to the subscription admin page in the DE. The screen will now look like this:

image

While this change was being made. The admin page was also updated to add support for the consumable flag in the resource type object. This addon update form hadn't been working since the consumable flag was added.

@@ -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)
Copy link
Member Author

@slr71 slr71 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch from lightFormat to format caused me a little bit of concern. As far as I can tell format is fully compatible with lightFormat but not vice versa. If anyone knows of a case (that applies to us) where this is not true, please let me know and I'll create a separate function for formatting ISO8601 dates.

@slr71
Copy link
Member Author

slr71 commented Jan 7, 2025

There's currently a field marked as being required in Terrain that shouldn't be in the case of an update. I'll fix that before merging this PR.

Copy link
Member

@psarando psarando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall 👍

I had a few minor suggestions, but I also think I found a couple of bugs with i18n messages and the addon rate UUIDs and keys.

"addons": "Add-ons",
"addonRates": "Add-on Rates",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was addons intentionally changed to addonRates?

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 reads addons instead of Add-ons (and if you view the browser console in storybook or dev mode, the i18n lib should report a warning that the addons messages key was not found).

So should addonRates just be a new key/message?

Comment on lines +62 to +64
onClick={() => {
onDelete(key);
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the key prop is accessible here, since it's just for React:

Note that your components won’t receive key as a prop. It’s only used as a hint by React itself. If your component needs an ID, you have to pass it as a separate prop: <Profile key={id} userId={id} />.

The onDelete prop can be updated below to use the index directly, then this can become:

Suggested change
onClick={() => {
onDelete(key);
}}
onClick={onDelete}

baseId={buildID(baseId, index)}
fieldName={`${fieldName}.${index}`}
key={index}
onDelete={onDelete}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onDelete={onDelete}
onDelete={() => onDelete(index)}

<TableContainer>
<Table>
<Typography component="caption">
{t("subscriptions:addonRates")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not required to namespace these subscriptions messages, since the i18n lib will look for these keys in the first namespace passed to useTranslation by default.

Suggested change
{t("subscriptions:addonRates")}
{t("addonRates")}

return {
uuid,
effectiveDate: addonRate.effective_date,
key: `addonRates.${index}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the key field is used, so it can be removed here.

@@ -30,6 +38,14 @@ function mapPropsToValues(addon) {
: default_amount,
defaultPaid: default_paid,
resourceType: resource_type.unit,
addonRates: addon_rates.map((addonRate, index) => {
return {
uuid,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uuid was destructured from the parent addon, so the addon's uuid is getting reused here.
This should probably be:

Suggested change
uuid,
uuid: addonRate.uuid,

@@ -60,6 +77,13 @@ function formatAddonSubmission(values, resourceTypes, update = false) {
resource_type: {
uuid: id,
},
addon_rates: addonRates.map((addonRate) => {
return {
uuid,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks like the addon's uuid (destructured from values above).

Suggested change
uuid,
uuid: addonRate.uuid,

addonRate={addonRate}
baseId={buildID(baseId, index)}
fieldName={`${fieldName}.${index}`}
key={index}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible using the index as a key may cause issues when addon rates get deleted in the form (though it should be tested since it might only cause issues when rates are deleted and inserted, or if they need to be rearranged in the future).

It might be better to use addonRate.uuid as the key, but then a new uuid would have to be created in the onAdd function with crypto.randomUUID().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants