Don't lose data in Tray on state update

refs ADMIN-752

Test plan
- Open the update tray while the planner is
  still loading opportunities
- (Very quickly) type something in the title
  field
- Wait a few seconds for everything to finish
  loading and ensure the title is not lost
  and ensure the date field doesn't error
- Focus is still being lost at final planner
  render, further ticket needed

Change-Id: I8366d13959e1285b930e5ee434d616575a8b3daa
Reviewed-on: https://gerrit.instructure.com/140377
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins
QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com>
Product-Review: Mysti Sadler <mysti@instructure.com>
This commit is contained in:
Mysti Sadler 2018-02-07 15:52:13 -07:00
parent 3dc7434cd6
commit c83f195bb5
2 changed files with 11 additions and 2 deletions

View File

@ -43,6 +43,13 @@ it('renders the item to update if provided', () => {
expect(wrapper).toMatchSnapshot();
});
it("doesn't re-render unless new item is provided", () => {
const wrapper = shallow(<UpdateItemTray {...defaultProps} />)
const newProps = {...defaultProps, locale: 'fr'}
wrapper.setProps(newProps)
expect(wrapper.find('DateInput').props()['messages'].length).toBe(0)
})
it('renders Add To Do header when creating a new to do', () => {
const wrapper = mount(
<UpdateItemTray {...defaultProps} />

View File

@ -60,8 +60,10 @@ export class UpdateItemTray extends Component {
}
componentWillReceiveProps (nextProps) {
const updates = this.getNoteUpdates(nextProps);
this.setState({updates}, this.updateMessages);
if (nextProps.noteItem) {
const updates = this.getNoteUpdates(nextProps);
this.setState({updates}, this.updateMessages);
}
}
getNoteUpdates (props) {