-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: add files via file tree #314
feat: add files via file tree #314
Conversation
Run & review this pull request in StackBlitz Codeflow. |
88e4815
to
a3944c3
Compare
187d285
to
589629a
Compare
abebc6f
to
380126f
Compare
2a4a839
to
a9219d0
Compare
|
||
interface FileChangeEvent { | ||
type: 'FILE' | 'FOLDER'; | ||
method: 'ADD' | 'REMOVE' | 'RENAME'; |
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.
Added the REMOVE
and RENAME
here even though they are not yet implemented. This kind of API allows us to extend the functionality later without causing breaking changes.
a9219d0
to
2fe5950
Compare
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.
Did a first pass, good work on this!! 💪
|
||
// or configure file tree with options | ||
z.strictObject({ | ||
allowEdits: z |
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 we want something more fine grained where you specify in which scope you want to allow files and folder to be added.
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.
Sounds good! Though this is something that could be implemented after this first PR without breaking the API too, so that true
would mean "allow everything".
But I can also take a look at this once I've addressed other review findings. 👍
@Nemikolh ready for review round 2! 🔔 Added support for identifying files and folders from each other - we no longer require files to have extensions. However there's still an edge case that causes issues. As we are using filepath as map key here, there's no way for us to have file and folder with same name in the tree.
So for example this will fail: test('empty directories are removed when new content is added', () => {
const store = new EditorStore();
store.setDocuments({
example: 'should not be confused as directory',
});
store.addFileOrFolder({ path: 'example', type: 'FOLDER' });
store.addFileOrFolder({ path: 'example/another', type: 'FOLDER' });
expect(store.files.get().map(toFilename)).toMatchInlineSnapshot(`
[
"example/another",
"example",
]
`);
}); Is this really an issue that users could run into? Maybe not. |
@AriPerkkio I'm not up to date with every file systems that exists out there, but AFAIK, in most of them you cannot have a file and a folder named the same. If you think about it, that make sense with the Linux In our case, what matter is what the WebContainer fs does and it does not allow multiple files given a single path. So this is completely fine 👍 |
Oh that's right! It does make sense, when you think from the file system's perspective! I guess I was looking at this too much from FileTree's visual representation and didn't realize it's not possible on fs. 💯 |
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.
Second pass done! I hope I didn't miss anything. I'll probably do another pass tomorrow 🙏
docs/tutorialkit.dev/src/components/react-examples/ExampleFileTree.tsx
Outdated
Show resolved
Hide resolved
position?: 'before' | 'after'; | ||
|
||
/** Localized texts for menu. */ | ||
i18n?: Pick<I18n, 'fileTreeCreateFileText' | 'fileTreeCreateFolderText'>; |
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.
Oh this is a cool way to only require what we use, I wonder if we should use Pick
for i18n
in other places. I suppose this can be done later. Curious to hear your thoughts on 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.
Yep we should! I saw that there's quite much duplication in couple of places. When we can derive props from their orignal source, we should always do it.
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.
Incredible job on this @AriPerkkio! 🥳 🥳
I'm starting to think we could merge this PR first, and then change the API in a follow-up PR to be:
type GlobPattern = string;
interface P {
allowEdits?: boolean | GlobPattern | GlobPattern[]
}
That way it wouldn't be a breaking change, we would still support the boolean version with the default value being false
.
I got a feeling that some will still want to use true
anyway.
What I think we should do in the follow-up PR is to clarify in the docs that only allowing certain patterns (or even a single path) should be preferred.
I would even reference the talk from Rich Harris: FullStack Documentation as a suggestion to why this should be preferred.
I agree on all points! I'll continue on that next. |
FileTree
I noticed plenty of issues with it and created ReplaceFileTree
with accessible third party treeview component #326 as follow-up.BREAKING CHANGES
@tutorialkit/react
package directly, without TutorialKit need to update<FileTree>
component'sprops.files
typeDescription
Adds new metadata option that can be used to enable file and folder creation in the file tree. By default this feature is disabled.
tk-filetree-example.webm