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 13 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.

public/static/locales/en/subscriptions.json Show resolved Hide resolved
src/components/subscriptions/addons/edit/formatters.js Outdated Show resolved Hide resolved
src/components/subscriptions/addons/edit/formatters.js Outdated Show resolved Hide resolved
src/components/subscriptions/addons/edit/formatters.js Outdated Show resolved Hide resolved
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().

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the UUID as the key makes more sense to me than using the index. I'll update it. Thanks for the suggestion!

@psarando
Copy link
Member

Also, I don't see any Chromatic builds associated with this PR, so you probably still need to set up a Chromatic token for your fork.

@slr71
Copy link
Member Author

slr71 commented Jan 15, 2025 via email

import ids from "../../ids";

function AddonRateEditorRow(props) {
const { baseId, fieldName, key, onDelete } = props;
Copy link
Member

Choose a reason for hiding this comment

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

Note that the GitHub Action is now reporting a warning here (which should also be reported if you run npm run check locally):

'key' is assigned a value but never used

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, thanks. I think I have that fixed locally, but I haven't pushed that change yet because I ran into some errors during testing after making some recent changes.

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