statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.03k stars 530 forks source link

Issue with dynamic assets folder and renaming #10943

Closed aerni closed 3 weeks ago

aerni commented 3 weeks ago

Bug description

I ran into an issue with dynamic assets folder and the rename folder feature.

Renaming a folder works as expected. However, if you later remove all the assets from the fieldtype, the folder name will be reset to whatever was set in the fieldtype config, like id or slug. The fieldtype doesn't retain the name of the previously renamed folder. This leads to previously uplouded assets not being selectable anymore.

Quick demo

https://github.com/user-attachments/assets/dcbacb1a-2966-4cd0-88c1-05896237bbee

How to reproduce

  1. Add this field to your blueprint:
handle: assets
field:
  container: assets
  type: assets
  dynamic: id
  1. Upload some assets
  2. Rename the folder
  3. Remove the assets from the fieldtype
  4. Try selecting previously uploaded assets

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.27.2
PHP Version: 8.3.12
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: photography.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Livewire
Livewire: v3.5.9

Statamic
Addons: 5
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.30.0 Solo

Statamic Addons
aerni/zipper: 2.4.0
jacksleight/statamic-bard-texstyle: 3.3.0
jonassiewertsen/statamic-livewire: 3.8.1
spatie/statamic-responsive-images: 5.0.1
stillat/antlers-components: 2.3.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

jasonvarga commented 3 weeks ago

This is a pretty weird edge case IMO. I'm not sure how we'd handle this.

Once you rename the folder away from how you've configured the dynamic folder, we are only maintaining the now-out-of-sync folder as a courtesy so selected assets don't break.

aerni commented 3 weeks ago

I don't think I fully understand. What's the point of the renaming folder feature if the fieldtype doesn't retain the new name? I understand what you're getting at, but the UX is super confusing right now.

jasonvarga commented 3 weeks ago

It'll retain the name by looking at what assets you have selected in that field. If you don't have anything selected it has no idea that folder a is the one that should be linked to that entry, so it'll go back to using whatever you've configured in the dynamic setting.

In what situation are you uploading ~18 assets to a folder dedicated to a single entry, then choosing none of them?

aerni commented 3 weeks ago

Ah, I see. It's definitely an edge case, and I was only running into it when tinkering.

But the UX/UI is confusing right now. When first creating an entry, I'm under the impression that the dynamic folder has already been created. But the folder is only created once you upload the first asset. That's not inherently obvious because …

… The "Browse" button is present and allows you to browse a non-existing folder. … The "Rename Folder" action is present, making you believe that a folder already exists.

If you run the "Rename Folder" action, it would not actually "rename" but "create" a folder. And once you upload your first asset, it will be put into a folder with the name of whatever you've configured in the dynamic setting. Leaving you with an empty folder from the initial renaming.

I'm not 100% sure what the best solution would be. Maybe hide the "Rename Folder" action from the UI until an asset has been uploaded and the folder created would suffice.