Skip to content

Fixes #681 - File name update triggers editor change detection #1372

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

Merged
merged 15 commits into from
Apr 16, 2020
Merged

Fixes #681 - File name update triggers editor change detection #1372

merged 15 commits into from
Apr 16, 2020

Conversation

ghalestrilo
Copy link
Collaborator

@ghalestrilo ghalestrilo commented Apr 7, 2020

Problem (#681)

Editor would not detect filename changes as project changes. This is a minor issue since usually filenames will be referred to by other files, which require changing said files, therefore triggering a change in the project. Still, it's a nice detail to have.

Solution

Detecting these changes require comparing the original filename to the new one, so a new updatedName field was created in the files reducer. The updatedFileName action should detect if they are different before triggering changes, requiring the ability to dispatch more than one action at once, so it was refactored to a thunk. Finally, the saveProject action must commit these name changes, and clear their updatedNames, so this was added right before sending the request.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • is from a uniquely-named feature branch and has been rebased on top of the latest master. (If I was asked to make more changes, I have made sure to rebase onto master then too)
  • is descriptively named and links to an issue number, i.e. Fixes #123

@welcome
Copy link

welcome bot commented Apr 7, 2020

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

@catarak
Copy link
Member

catarak commented Apr 9, 2020

Thanks for working on this! While this approach works, I'm not sure it's the best one. I think it can be super confusing when to store the state in React vs. Redux, and this is a case in which I think it makes sense to store it in React.

I would suggest taking a similar approach, but storing updatedName in the state of client/modules/IDE/components/FileNode.jsx, and then only calling this.props.updateFileName if state.updatedName !== props.name. Then the action updateFileName can always dispatch(setUnsavedChanges(true));.

@ghalestrilo
Copy link
Collaborator Author

@catarak Agreed, thanks for the input. I followed your suggestion, and it's a bit clearer now

@ghalestrilo
Copy link
Collaborator Author

I chose to write a quick test for that filename check, hope that's ok
This is an important component to test - I want to write more cases on a new branch

@catarak
Copy link
Member

catarak commented Apr 16, 2020

I couldn't help myself and ended up hijacking this PR 🤦 Ended up with a great refactor though!

@catarak catarak merged commit 33db5fb into processing:master Apr 16, 2020
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.

2 participants