-
Notifications
You must be signed in to change notification settings - Fork 524
Sketch Lab: support version history #69984
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
Conversation
molly-moen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, one comment!
| if (onRestore) onRestore(startSources); | ||
| } else if (isLatest) { | ||
| dispatch(resetToCurrentVersion()); | ||
| if (onRestore) dispatch(resetToCurrentVersion({onRestore})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should onRestore be required here to call resetToCurrentVersion? As-is will this cause broken behavior in Web Lab 2/Python lab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes guessing it will, thanks for the callout. Think I was just trying to avoid TS errors. I will tidy and request review!
fisher-alice
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Just left a non-blocking comment/suggestion about using the term 'onRestore' in different contexts.
| } | ||
| if (viewingInitialVersion) { | ||
| dispatch(previewStartSources({startSources})); | ||
| dispatch(previewStartSources({startSources, onRestore})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if 'restore' now has a bit of an overloaded meaning. Currently, it seems like 'restore' means to save whichever version is being selected as the most current version. But here it's only used to switch views temporarily.
Could use something more generic like 'onLoadVersion`?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, will update!
molly-moen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
| (sources: ProjectSources, save: boolean = false) => { | ||
| setCurrentSources(sources); | ||
| if (save) { | ||
| if (save && !readonlyWorkspaceRef.current) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we can't use readonlyWorkspace directly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so...I was having issues with sources being saved unexpectedly as I switched into a read-only view (ie, viewing an old version). I think it was calling this function with an outdated value for the readonly state of the workspace, so it would save the old version and overwrite my latest project state.
Basically, I wanted to make sure I had the most recent version of "are we in a readonly state" whenever this function gets called, and I got complaints trying to call useAppSelector(isReadOnlyWorkspace) directly here because you can't use hooks unless they're at the top level.
My friend Claude helped me come up with this approach, and FWIW I was a bit skeptical. Maybe there's a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok, maybe just add a comment explaining it?
Adds version history to Sketch Lab. The approach here was to pass our handler that updates sources in
SourcesContainerto the version history component as a prop. Ideally, we'd like to unify these approaches to managing sources at some point in the future. More discussion in this Slack thread.Links
Testing story
Tested manually that I could view/restore intermediate versions, the initial version (with "start over" warning modal), and go back to the current version. Also tested that viewing a version made the canvas readonly and that changes were not saved if the page was reloaded after viewing (but not restoring) an old version.
Follow-up work
There's a UI to created named versions with a description, which relies on setting a bit of Redux state (
hasEdited) that Sketch Lab doesn't support yet. To simplify things, I'll do that as a follow-up.