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

Create census banner to show to teachers with nces school ids #19559

Merged
merged 27 commits into from
Jan 11, 2018

Conversation

drewsamnick
Copy link
Contributor

This creates a new simplified version of the census form that will be shown to teachers associated with an NCES school id.

Initial display:
screen shot 2017-12-08 at 3 30 35 pm

With "yes" selected:
screen shot 2017-12-08 at 3 30 44 pm

With "not yet":
screen shot 2017-12-08 at 3 30 54 pm

When you opt to update school info:
screen shot 2017-12-08 at 3 31 05 pm

@drewsamnick
Copy link
Contributor Author

Teacher pop-up

<div style={styles.message}>
<SchoolInfoInputs
ref={this.bindSchoolInfoInputs}
onCountryChange={this.onCountryChange.bind(this)}
Copy link
Contributor

Choose a reason for hiding this comment

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

note: you can avoid these explicit bindings by defining the callbacks with arrow functions. See above

onCountryChange(_, event) {
const newCountry = event ? event.value : '';
this.setState({country: newCountry});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

note: you can define these callbacks as arrow functions to automatically bind this and remove the need to do it explicitly later. E.g.

onCountryChange = (_, event) => {
  const newCountry = event ? event.value : '';
  this.setState({country: newCountry});
}

Also, nit: I prefer the callback supplied to an onVerb handler to be called handleVerb (rather than again onVerb), like in the react examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change this.

url: "/users.json",
type: "post",
dataType: "json",
data: $("#census-school-info-form").serialize()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is all in React now, don't we have (or can construct) all the state in one place in the parent object and submit that? Why construct all these hidden fields (starting on line 276) and serializing the actual html form data? Is there something else we're gaining by doing that? This would be simpler, and more React-y, to maintain and submit state from a component, not render anything hidden (unless it's needed elsewhere), and not rely on finding an element by id. If we were to look for an element by id, using ref is generally preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to change this to construct the POST from the component's state. I did it this way simply because all of the other forms I've touched have worked like this and I didn't consider doing it differently. I agree that we don't need an actual form here.

<div style={styles.main}>
<form id="census-teacher-banner-form">
<input type="hidden" name="nces_school_s" value={schoolId}/>
<input type="hidden" name="school_year" value={this.props.schoolYear}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these needed? See above

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose if this is simpler as a form with uncontrolled elements so we don't need a bunch of state management then it makes sense. In that case, please move the whole form into a different component (or at the very least a function), and use ref to find that DOM element.

This render method is getting a bit long and unwieldy, hard to keep track of the branches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree about long and unwieldy. I'll break it up to be more readable.

showSchoolInfoUnknownError: false,
});
this.loadSchoolName(this.props.ncesSchoolId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Will the dismissal also unmount the component? If we unmount the component on @DiSmiSSaL, and set default state (line 84) when it's new, then do we need to clear it on the way out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is needed. This is handling the case where the user dismissed the "update your school" view, not the entire banner. In that case, there may have been partial state about the school changed. We do not want to use that partial state in the census submission so we need to reset to the previous values. I'll add a comment to make this clearer.

@drewsamnick
Copy link
Contributor Author

Updated based on PR comments from Friday.

schoolLocation: '',
showSchoolInfoErrors: false,
showSchoolInfoUnknownError: false,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be the same as the initial state on line 79, plus the last 2 showSchoolInfo* fields. This raises a couple questions:

  1. Should those 2 also be initialized on line 79?
  2. If the 2 state objects are identical, then why don't we wrap these into a single static property, e.g. initialState and set both the initial state and this setState to that value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, those should be the same. I changed it to reference a common definition of that state.

@drewsamnick drewsamnick changed the base branch from staging-next to staging December 12, 2017 14:09
Drew Samnick and others added 2 commits December 12, 2017 16:22
@drewsamnick
Copy link
Contributor Author

I've been asked to hold off merging this until Jan.

@drewsamnick drewsamnick merged commit 6911899 into staging Jan 11, 2018
@drewsamnick drewsamnick deleted the census-teacher-banner branch January 11, 2018 15:08
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