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

Fix/infinite loop #1234

Merged
merged 8 commits into from
May 24, 2021
Merged

Fix/infinite loop #1234

merged 8 commits into from
May 24, 2021

Conversation

dominikx96
Copy link
Collaborator

@dominikx96 dominikx96 commented May 12, 2021

Issue

It's not covered by any issue.

Addresses # (issue)

  • 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

This PR solves 2 problems:

A language from the choose-language step is not saved by a conductor. I also refactored autofill to do not reset context (language is selecting in the first step and autofill is a secondary step - so we need to know what language the user selected)

url: http://localhost:3000/applications/start/choose-language without listingId parameter occurs infinity loop with GET /listings call to the API.

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)
  • This change requires a documentation update
  • This change requires a SQL Script

How Can This Be Tested/Reviewed?

  1. Log in
  2. Choose language different than EN (it was default previously so we want to test different case)
  3. Submit application
  4. Open public app in a new card (to reset context)
  5. Log in
  6. Post application with different language
  7. See on the partners if an application includes selected language
  • Desktop View
  • Mobile View

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

@dominikx96 dominikx96 requested a review from pbn4 May 12, 2021 15:18
@dominikx96 dominikx96 self-assigned this May 12, 2021
@netlify
Copy link

netlify bot commented May 12, 2021

Deploy Preview for clever-edison-cd22c1 ready!

Built with commit dcb8998

https://deploy-preview-1234--clever-edison-cd22c1.netlify.app

@dominikx96 dominikx96 requested a review from jaredcwhite May 12, 2021 15:43
@dominikx96
Copy link
Collaborator Author

@jaredcwhite I also noticed, ApplicationForms test doesn't have any sense after infinite loop fix. I need to figure out how to open this step with a correct listingId, then update the test. I think for now we can test all except this - I'll prepare fix soon

@dominikx96 dominikx96 changed the title Fix/infinity loop Fix/infinite loop May 12, 2021
Copy link
Collaborator

@jaredcwhite jaredcwhite left a comment

Choose a reason for hiding this comment

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

Hi @dominikx96, good catch on the application language not being saved. (I think there might have been a problem before where we never actually saved it.)

I have some concerns about this PR altering subtle behavior I fixed previously after discovering bugs. Can we basically just include the

     conductor.currentStep.save({
       language,
     })

change, and then for Autofill step just pass a language code directly as the second argument to the constructor?

Regarding the missing listing ID param issue, it looks like the fix in this PR is sort of broken:
https://deploy-preview-1234--clever-edison-cd22c1.netlify.app/applications/start/choose-language

I know in the past we had sort of hack in place which just pulled the first listing out of the result set. Maybe what we should just do instead is redirect to the home page if there's no listing ID param?

@dominikx96
Copy link
Collaborator Author

Hi @dominikx96, good catch on the application language not being saved. (I think there might have been a problem before where we never actually saved it.)

I have some concerns about this PR altering subtle behavior I fixed previously after discovering bugs. Can we basically just include the

     conductor.currentStep.save({
       language,
     })

change, and then for Autofill step just pass a language code directly as the second argument to the constructor?

Regarding the missing listing ID param issue, it looks like the fix in this PR is sort of broken:
https://deploy-preview-1234--clever-edison-cd22c1.netlify.app/applications/start/choose-language

I know in the past we had sort of hack in place which just pulled the first listing out of the result set. Maybe what we should just do instead is redirect to the home page if there's no listing ID param?

@jaredcwhite agree I updated PR to just redirect the user to the /.

Unfortunately, I don't understand the first problem, could you explain it more with code samples?
Currently, I decided to pass a current application from the context as a second AutofillCleaner parameter in the constructor - it gives us more flexibility.

@pbn4 pbn4 requested review from jaredcwhite and removed request for pbn4 May 17, 2021 15:02
Copy link
Collaborator

@jaredcwhite jaredcwhite left a comment

Choose a reason for hiding this comment

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

OK, I think there was just one specific place where a bug might have crept in again. Otherwise looks good to me—although will need a update for Next v10. Should we get that merged in and then this? Or merge this first?

@@ -37,9 +36,8 @@ export default () => {
setSubmitted(true)
if (previousApplication && useDetails) {
conductor.application = previousApplication
} else {
conductor.application = blankApplication()
Copy link
Collaborator

@jaredcwhite jaredcwhite May 17, 2021

Choose a reason for hiding this comment

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

I had this here so if somebody went back in their browser history and changed to not autofilling the application, it'd be rewritten as a blank application. Otherwise they could never undo their choice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jaredcwhite , how close do you think we are to being able to merge the Next branch? If you're thinking next week, then can we get this in first? We're in a tough spot of not wanting to delay the Next updates any longer, but we also don't want to stack up a lot of dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@seanmalbert Oh I want to get Next v10 ready to merge today, so I think this could follow suit.

@dominikx96
Copy link
Collaborator Author

@jaredcwhite I realized we can just create a new application object in the autofill step, even if autofill is available - the first step is choose-language, so it works as expected in both situations. Could you check it again? :)

@dominikx96 dominikx96 requested a review from jaredcwhite May 20, 2021 16:24
Copy link
Collaborator

@jaredcwhite jaredcwhite left a comment

Choose a reason for hiding this comment

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

@dominikx96 Approach looks good to me! 👍

} from "@bloom-housing/backend-core/types"
import { blankApplication } from "@bloom-housing/ui-components"

class AutofillCleaner {
application: Application = null

// provide context value to override current application language choosen by user on the first step
// eslint-disable-next-line @typescript-eslint/no-explicit-any
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 see anything untyped here…do we still need the disable comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice catch! Removing it...

@dominikx96 dominikx96 merged commit eba88db into master May 24, 2021
willrlin referenced this pull request in CityOfDetroit/bloom Jun 9, 2021
* Prevent infinity loop when listingId is not defined

* Override language from the context

* Updated test

* Redirect to the homepage when there is no listingId

* Updated cypress test

* Updated autofill to do not override selected language

* Cleanup

Co-authored-by: dominikx96 <dominik@airnauts.com>
willrlin referenced this pull request in CityOfDetroit/bloom Jun 9, 2021
willrlin referenced this pull request in CityOfDetroit/bloom Jun 9, 2021
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.

3 participants