-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(editor): fetch current not-owned projects, add project forking #525
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
base: master
Are you sure you want to change the base?
Conversation
Reuses `duplicateProject()`, with some adaptations to ensure the forked project is loaded so we can get its name
Add the current project to the $projects store. This will make the project's title appear in the projects dropdown
…gic to text utils
Mitcheljager
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.
| $: if ($currentProjectUUID && !$projects.some(({ uuid }) => uuid === $currentProjectUUID)) { | ||
| fetchProject($currentProjectUUID).then((currentProject) => { | ||
| $projects.push(currentProject) | ||
| }) | ||
| } |
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'd prefer $projects to not ever contain a project that is not owned by the user
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.
Would you be okay with at least renaming it $user/ownProjects? Its naming is a bit vague otherwise.
I also noticed a lot of checks for $currentProject?.is_owner, making it seem like we could have a project in $projects that could be owned by some other user ($currentProject derives from $projects).
| let ownProjects = [] | ||
| let filteredProjects = [] | ||
|
|
||
| $: ownProjects = $projects.filter(({ is_owner }) => is_owner) |
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 don't really want the state of projects that are not part of your project to be handled in the projects dropdown, I think it would make more sense somewhere else.
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 point.
Considering my comment above, what do you think about renaming $projects to $user/ownProjects, and having a $projects that contains a cache of all known projects (essentially what I do here with the current $projects)?
Then $user/ownProjects can derive from $projects, filtering out any projects that have is_owner set to false.
| <button class="w-auto text-base ml-1/8" on:click={() => duplicateProject(true)}> | ||
| Fork | ||
| </button> |
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.
The editor is meant as a bridge for users who aren't very familiar with programming just yet. The term "fork" is not exactly common outside of the programming world, so I'd prefer something else. Especially because this isn't a fork, it's just a copy. You aren't really forking off of some main branch.
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 was also thinking about that.
I decided to go with Fork anyway because we already use that terminology in workshop.codes itself for marking codes as forks of other projects. The term "fork" there also really means a project "being based off of" another project, so it doesn't quite line up with the way we use "fork" in the showbiz either.
I can rename this "Clone" or "Clone for myself" or something else that makes it clearer what this is about.
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.
Maybe in the future we could consider having a sort of real forking system though? Where a project is marked as being based-off another project, and there is a button to merge changes coming from upstream (the original project) into the other project?
Ehh, maybe its not that useful. At that point just why not go and replicate Git completely, right?
app/javascript/src/utils/text.ts
Outdated
| return string.toLowerCase().replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()) | ||
| } | ||
|
|
||
| export function trimmed(string: string, limit: number, ellipsis = "..."): string { |
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.
This is more commonly called truncate, but I think it might make more sense to do this via CSS so it's not screen width dependent.
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 like truncate better also 👍
| export function trimmed(string: string, limit: number, ellipsis = "..."): string { | |
| export function truncate(string: string, limit: number, ellipsis = "..."): string { |
Also 👍 to implementing this through CSS. I mostly just wanted to get rid of the inline logic in <ProjectsDropdown>, which came out of nowhere and was a bit of an eyesore to me 😅.
Moving that logic into a helper was the quickest solution.
| {#if $currentProject && !$currentProject.is_owner} | ||
| <small>(read-only)</small> | ||
| {/if} |
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.
It's not really read-only, you can still edit the project, just not save.
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 struggled to come up with a term that'd fit into the dropdown.
Maybe it'd be better if the title of a project not owned by the user is shown outside the projects dropdown, and the projects dropdown is left exclusively for navigating to your own projects.
|
@netux Sure! |
Makes an ellipsis appear on horizontal text overflow. Note that this should usually be combined with a static width for the overflow to trigger.
…jects endpoint Fixes projects not appearing in the projects dropdown.
Use `text-small` instead.
…ct" warning Simply removing `warning--orange` does the trick, since the default background color is also a darker shade of orange.
…cts not owned by the current user This is deceiving, because the projects _are_ editable, just not saveable. Besides, we already have the "You do not own this project" warning in <editor-actions>
|
@Mitcheljager what do you think of like this "Clone and Save" button in place of the "Fork" button? I like this more even because it triggers on the |
|
@netux I think that works! |
…ror" when a project fails to be created This is more in line with other helper methods in this file.
…ethod A little house-keeping. I noticed this was the only /projects API call which wasn't in utils/project.ts, since it really is only used once.
… projects that aren't owned by the user This replaces the previous "Fork" button. The new button is situated in place of the "Save" button that appears in projects owned by the user, and even shares the same component. This matches the behavior seen in other online IDEs/text editors, when attempting to save a file that isn't your own.
|
@Mitcheljager any opinions on the |
|
@netux I don't think it's a good idea to ever put any projects in there that are not your own. Ideally no store is needed for a project that is someone else's. |



When viewing other people's projects, show a "Fork" button in place of the "Edit" button that would be present for owned projects.
Also, ensure we have the name of the current project, even if not owned, by detecting when
$currentProjectUUIDis not present in$projects, then fetching and storing it.