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

Site Data Refactor to make similar to CustomerData and InventoryData #83

Merged
merged 4 commits into from
Apr 10, 2021

Conversation

julianrkung
Copy link
Collaborator

What's new in this PR

Customer Data and Inventory Data have a nice redux structure that allows for selector use and entity adapters. This PR refactors siteData so that it has the same structure. This was done now because we will begin implement functionality around objects that live in SiteData such as Financial Summaries and Tariff Plans.

Changelog

  1. Made siteData structure identical to inventoryData and customerData
  2. siteData now has 2 entity adapters per site: 1 for Financial Summaries and 1 for tariff plans
  3. Removed all instances of currentSite and switched them to use the selector selectCurrentSite

How to review

  1. Make sure changing sites still work
  2. Make sure all pages that used to use currentSite are still reachable
  • Home, Customer Profile, Financial Summary (though not used right now), Confirm Payment
  1. Pointers on any of the refactored code would be nice as well

Relevant Links

Online sources

Related PRs

Next steps

  1. Selectors for SiteData to get Tariff Plans based on meter type

Screenshots

Evidence of no more currentSite
image

CC: @julianrkung

@julianrkung julianrkung requested a review from wangannie April 9, 2021 18:25
Copy link
Member

@wangannie wangannie left a comment

Choose a reason for hiding this comment

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

I'm a little confused about the new structure with full TariffPlan objects under individual sites since AFAIK a tariff plan can still be shared across multiple sites right? Wouldn't this lead to conflicts with editing tariff plans? I thought we landed on the original plan with sites only tracking tariff plan ids and referencing a shared list of tariff plans that we keep as the single source of truth.

Besides that, I left some nitpicks + renaming suggestions. Everything else looks good!

(siteId, state) => state.siteData.sites[siteId].siteInformation)

// Returns all SiteRecord[] information
export const selectAllSites = (state: RootState) : SiteRecord[] => Object.values(state.siteData.sites).map(site => site.siteInformation);
Copy link
Member

Choose a reason for hiding this comment

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

Also rename to selectAllSitesInformation?

Also, why did you access state.siteData.sites directly? It seems like our pattern so far has been to use the entity adapter's getSelectors and build custom selectors off of those, so I'm curious why you did this instead

Copy link
Collaborator Author

@julianrkung julianrkung Apr 10, 2021

Choose a reason for hiding this comment

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

Will rename to that. I originally had it at that name, but thought I might be breaking convention since others are like selectAllCustomers etc

I didn't know a better way to do it. state.siteData.sites.siteInformation (only tariffPlans and financialSummaries) isn't an adapter, so there aren't pre-given selectors for it.

export const getTariffPlan = (customer: CustomerRecord, currentSite: SiteRecord): TariffPlanRecord | undefined => {
const tariffPlanId = customer.tariffPlanId;
return currentSite.tariffPlans.find((plan: TariffPlanRecord) => plan.id === tariffPlanId);
export const getTariffPlan = (customer: CustomerRecord): TariffPlanRecord | undefined => {
Copy link
Member

Choose a reason for hiding this comment

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

Rename to something like getTariffPlanByCustomer? You could also just turn this into a selector similar to selectProductByInventoryId.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a better name, thanks. Will do getTariffPlanByCustomer first. Might be good to change it to a selector once the CustomerProfile PR is finished (don't wanna cause more conflicts than necessary)

@julianrkung
Copy link
Collaborator Author

I'm a little confused about the new structure with full TariffPlan objects under individual sites since AFAIK a tariff plan can still be shared across multiple sites right? Wouldn't this lead to conflicts with editing tariff plans? I thought we landed on the original plan with sites only tracking tariff plan ids and referencing a shared list of tariff plans that we keep as the single source of truth.

Discussed on slack. Confirmed with NPO that tariff plans are bound to only a single site. We both agreed that adapters are a good solution with this constraint

@julianrkung julianrkung requested a review from wangannie April 10, 2021 01:37
Copy link
Member

@wangannie wangannie left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing all of my notes.

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