uptick / react-keyed-file-browser

Folder based file browser given a flat keyed list of objects, powered by React.
MIT License
301 stars 144 forks source link

onCreateFolder is not called if onRenameFolder is not provided #107

Closed ziaulrehman40 closed 4 years ago

ziaulrehman40 commented 4 years ago

This took quiet some time to debug, but it seems onCreateFolder is not called if onRenameFolder is not defined, we want to enable new folder creation but we don't want to allow renaming of the folder. This is making it impossible.

Trying to find the root cause to avoid it with some sort of monkey patching.

It seems it returns from:

  handleRenameSubmit = (event) => {
    event.preventDefault()
    if (!this.props.browserProps.renameFolder) {
      return
    }

this if in base-folder.js

ziaulrehman40 commented 4 years ago

For now, i had to use local copy of the whole thing to change this one line of if to:

  handleRenameSubmit = (event) => {
    event.preventDefault()
    if (!this.props.browserProps.renameFolder && !this.props.browserProps.createFolder) {
      return
    }

Not even sure if this is correct way to do it, but it works. And we are not using rename so should be fine

scaredcat commented 4 years ago

The issue is when you create a folder, it immediately wants you to rename this newly created folder.

I think your fix is correct. You could also have used && !this.props.isDraft instead which would enable you to set the name of draft (newly created) folders. Happy to accept a PR for this fix if you want to raise one.

ziaulrehman40 commented 4 years ago

@scaredcat PR is up