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

1544/ami overrides + unit form refactor #1706

Merged
merged 31 commits into from
Sep 15, 2021
Merged

Conversation

emilyjablonski
Copy link
Collaborator

@emilyjablonski emilyjablonski commented Aug 23, 2021

Pull Request Template

Issue

Addresses #1706

  • This change addresses the issue in full
  • This change addresses only certain aspects of the issue
  • This change is a dependency for another issue
  • This change has a dependency from another issue

Description

Adds the ability to create ami chart overrides in listings management, and also due to lots of state issues refactors the UnitForm component.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Prototype/POC (not to merge)
  • This change is a refactor/address technical debt
  • This change requires a documentation update
  • This change requires a SQL Script

How Can This Be Tested/Reviewed?

Create a new listing. Set an ami chart. Set an ami percentage from the dropdown (will pulls unique ami percentages from the selected dropdown). The table should populate with the ami chart values. Change one of the values (creating an override). Save the unit. Re-open the unit before saving the listing and ensure the override is still there. Change the percentage and the chart and ensure the override isn't sticky.

Save a listing with a unit with an overrides and view the details page for that unit and ensure the only value saved as an override is the one(s) that was overridden and that the default values aren't duplicated.

Ensure Copy and New works and brings overrides with it. Ensure Save and New and Save and Exit work as well.

Open an existing seeded listing to edit it and ensure the ami values populate.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have reviewed the changes in a desktop view
  • I have reviewed the changes in a mobile view
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have assigned reviewers
  • I have updated the changelog to include a description of my changes

@emilyjablonski emilyjablonski added the wip This PR is not ready for review, do not review it's a “Work In Progress” label Aug 23, 2021
@netlify
Copy link

netlify bot commented Aug 23, 2021

✔️ Deploy Preview for dev-partners-bloom ready!

🔨 Explore the source changes: b5b010e

🔍 Inspect the deploy log: https://app.netlify.com/sites/dev-partners-bloom/deploys/614222308dae9600070adac3

😎 Browse the preview: https://deploy-preview-1706--dev-partners-bloom.netlify.app

@netlify
Copy link

netlify bot commented Aug 23, 2021

❌ Deploy Preview for dev-storybook-bloom failed.

🔨 Explore the source changes: b5b010e

🔍 Inspect the deploy log: https://app.netlify.com/sites/dev-storybook-bloom/deploys/6142223029c0e90007a733cf

@netlify
Copy link

netlify bot commented Aug 23, 2021

✔️ Deploy Preview for dev-bloom ready!

🔨 Explore the source changes: b5b010e

🔍 Inspect the deploy log: https://app.netlify.com/sites/dev-bloom/deploys/61422230a9533b00075e81c0

😎 Browse the preview: https://deploy-preview-1706--dev-bloom.netlify.app

Base automatically changed from dev to master August 25, 2021 17:59
@emilyjablonski emilyjablonski changed the base branch from master to dev August 25, 2021 18:03
@seanmalbert
Copy link
Collaborator

#1575 , which has the backend ami override work, was merged.

@netlify
Copy link

netlify bot commented Aug 27, 2021

✔️ Deploy Preview for clever-edison-cd22c1 ready!

🔨 Explore the source changes: e0a65b8

🔍 Inspect the deploy log: https://app.netlify.com/sites/clever-edison-cd22c1/deploys/61394c7720f950000795f83c

😎 Browse the preview: https://deploy-preview-1706--clever-edison-cd22c1.netlify.app

@emilyjablonski emilyjablonski force-pushed the 1544/ami-overrides branch 2 times, most recently from af0b1a4 to db193e5 Compare September 10, 2021 15:35
Copy link
Collaborator

@seanmalbert seanmalbert left a comment

Choose a reason for hiding this comment

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

@emilyjablonski ,
This is definitely looking better than where it was and it's much easier to follow the event loop . I have a couple of question/consideration comments on the code.

Other than that, I have a general question of how should we handle a user entering in a percentage that is not in the chart? Let's say that a user selects a chart and then adds 50, which has a match in the chart, but then changes it to 45, which doesn't. On the form now, the fields don't clear out, but if I edit an entry, save it and reopen, I will only see the value I added. I think we should either clear out the fields if they add a percentage that isn't in the chart, or we update the percentage field to be a select based off of the available, unique percentages in the chart.

Comment on lines 123 to 137
const thisAmiChart = await amiChartsService.retrieve({
amiChartId: defaultChartID ?? amiChartID,
})
const amiChartData = thisAmiChart.items
.filter((item) => item.percentOfAmi === parseInt(defaultAmiPercentage ?? amiPercentage))
.sort(function (a, b) {
return a.householdSize - b.householdSize
})
setCurrentAmiChart(amiChartData)
amiChartData.forEach((amiValue, index) => {
setValue(`maxIncomeHouseholdSize${index + 1}`, amiValue.income.toString())
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to decouple the fetching of the ami chart from setting the ami chart values? I know we want to fetch the chart on chart change, do we need to do that on ami percentage change too? Since this shouldn't be something that's getting changed too much, I'd rather stay on the side of simplicity, so if pulling those two pieces apart complicates the flow, then let's keep as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, I changed amiPercentage to be a select based on the available percentages in the selected chart and am only fetching new charts on chart change

Comment on lines 192 to 194
const existingId = units.filter((unit) => unit.tempId === defaultUnit?.tempId)[0]?.tempId
const nextId = units.length + 1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it simplify things to pass defaultUnit.tempId as the id we expect it to be already? And if that's the case, then could we also pass in a new prop for nextId to use in the case where the user is doing a & new action?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Passing two new props for the IDs and removed units as a prop

Comment on lines 427 to 460
<table>
<thead>
<tr>
<th>{t("listings.householdSize")}</th>
<th>{t("listings.maxAnnualIncome")}</th>
</tr>
</thead>
<tbody>{getAmiChartTableData()}</tbody>
</table>
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you set the same classes on these fields here as what MinimalTable/StandardTable set, I think we can probably get it pretty close to what they gives us.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added styles to make it match

@emilyjablonski emilyjablonski marked this pull request as ready for review September 14, 2021 18:27
@emilyjablonski emilyjablonski added ready for review and removed wip This PR is not ready for review, do not review it's a “Work In Progress” labels Sep 14, 2021
@emilyjablonski emilyjablonski changed the title 1544/ami overrides 1544/ami overrides + unit form refactor Sep 14, 2021
Comment on lines 208 to 209
.filter((item: AmiChartItem) => item.householdSize === index + 1)
.filter((item: AmiChartItem) => item.percentOfAmi === parseInt(amiPercentage))[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't notice this before, but can you make this a single filter?

Copy link
Collaborator

@seanmalbert seanmalbert left a comment

Choose a reason for hiding this comment

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

@emilyjablonski ,
This looks good and seems to be working well. There's some minor cleanup and then I think you can merge.

@@ -33,6 +33,7 @@ import {
PaperApplication,
PaperApplicationCreate,
ListingReviewOrder,
UnitAmiChartOverrideCreate,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is used now.

void resetDefaultValues()
}, [])

const fetchAmiChart = async (defaultChartID?: string, defaultAmiPercentage?: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

defaultAmiPercentage isn't used

setValue("priorityType.id", defaultUnit.priorityType?.id)
setValue("unitType.id", defaultUnit.unitType?.id)
}
}, [options])
Copy link
Collaborator

Choose a reason for hiding this comment

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

The linter is complaining about the dependency arrays for this and two others. Does updating them cause issues?

@emilyjablonski emilyjablonski merged commit d594b12 into dev Sep 15, 2021
@emilyjablonski emilyjablonski deleted the 1544/ami-overrides branch September 15, 2021 17:53
seanmalbert pushed a commit to CityOfDetroit/bloom that referenced this pull request Jun 23, 2022
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.

None yet

3 participants