Skip to content

Conversation

@benjiwheeler
Copy link
Contributor

@benjiwheeler benjiwheeler commented Sep 12, 2019

Resolves

Should resolve #3433 and scratchfoundation/scratch-desktop#71 ;

Note that it does not seem to resolve the related #4759 .

Proposed Changes

Repurpose TitledHOC so that it:

  • no longer maintains projectTitle state
  • no longer passes projectTitle down to children
  • no longer sets canEditTitle to true on children
  • has responsibility for setting redux projectTitle when parent passes a changed projectTitle prop (previously this functionality was in containers/gui.jsx)
  • notices when the project-state changes to isShowingWithoutId, uses the translated default project name to set the redux projectTitle, and also calls the parent'sonUpdateProjectTitle prop function

GUI's playground/standalone versions previously used TitledHOC, so they need to explicitly pass canEditTitle to children.

scratch-desktop will need to no longer wrap itself with TitledHOC, and instead maintain its own projectTitle state.

Related

If this is merged, we will need to merge scratchfoundation/scratch-desktop#74 as well so that scratch-desktop is in line with these changes.

Reason for Changes

  1. in standalone, project title persists after upload; isn't set to default when File->New #3433 and File>New makes leaves the name of the previous project in the title field scratch-desktop#71 were bugs
  2. we want to localize the default project name

cwillisf
cwillisf previously approved these changes Sep 16, 2019
Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

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

I feel a bit out of my depth but this seems to make sense to me. Thanks for working on this!

isLoading: PropTypes.bool,
isScratchDesktop: PropTypes.bool,
isShowingProject: PropTypes.bool,
isShowingWithoutId: PropTypes.bool,
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 added intentionally? It looks unrelated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

this.props.onUpdateProjectTitle(defaultProjectTitle);
}
}
titleWithDefault (title) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a function that takes a title argument? It looks like it's only called in one place, without an argument.

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 think I meant to refactor setReduxTitle further... doing this now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

<WrappedComponent
canEditTitle
projectTitle={this.state.projectTitle}
onUpdateProjectTitle={this.handleUpdateProjectTitle}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we expect children to receive the title from redux, I think we should we also expect them to set it through redux.

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 made this change, now testing it...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested well

if (this.props.projectTitle !== prevProps.projectTitle) {
this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle));
}
// if the projectTitle hasn't changed, but the reduxProjectTitle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this addition... here is where the change to redux title gets echoed up to the enclosing context (i.e., www)

@benjiwheeler benjiwheeler changed the title on showing project without id, tell owner of GUI to set title to default Refactor title handling Oct 16, 2019
@benjiwheeler benjiwheeler force-pushed the clear-title-on-default-project branch from ced7ee7 to 68780ae Compare October 17, 2019 17:26
}
});

class ProjectTitleInput extends React.Component {
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 should change this back to how it was before

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine to do since your handler is coming from Redux now. I just think the name of the prop should change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

projectTitle: null
};
componentDidMount () {
this.props.updateReduxProjectTitle(this.titleWithDefault(this.props.projectTitle));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can combine these calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@rschamp rschamp left a comment

Choose a reason for hiding this comment

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

I have a few nits, but I think this is looking good overall. Especially that we don't need to consider projectId as a part of this.


ProjectTitleInput.propTypes = {
className: PropTypes.string,
handleUpdateReduxProjectTitle: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised the linter didn't catch this, because I think it used to. Prop names for events should be onX like onUpdateReduxProjectTitle. The name of the event handler itself should be handleX. The distinction is that the prop describes that the component might receive an event. The name of the handler describes that something should happen when that event is received.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I'm used to the linter insisting on is that this form be followed:

onXXXX={this.handleXXXX}

In my experience it doesn't like

onXXXX={this.onXXXX}

but it's ok with

onXXXX={this.props.whateverNameIsOK}

onUpdateProjectTitle: PropTypes.func,
projectChanged: PropTypes.bool,
requestProjectUpload: PropTypes.func,
updateReduxProjectTitle: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about event props. onUpdateReduxProjectTitle would be more consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
});

class ProjectTitleInput extends React.Component {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine to do since your handler is coming from Redux now. I just think the name of the prop should change.

@rschamp rschamp removed their assignment Oct 18, 2019
Copy link
Contributor

@rschamp rschamp left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in standalone, project title persists after upload; isn't set to default when File->New

3 participants