Fix Datatables error in Media Manager#5296
Conversation
…edia" utility, triggered when setting the ordering for media object in "Local files" or "External files", and then switching to "Unused files"
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5296 +/- ##
============================================
- Coverage 35.20% 35.20% -0.01%
- Complexity 11236 11237 +1
============================================
Files 1159 1159
Lines 48108 48114 +6
============================================
Hits 16937 16937
- Misses 31171 31177 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
To answer my own question: perhaps related, but certainly not the very same issue! |
|
I confirm that this is directly related to #5198. It appears to me that the previous fix (intended to provide unique IDs for tables to prevent state sharing) does not fully resolve the issue in this context. The ID for the media admin table remains wt-datatables-admin-media regardless of whether one is browsing local, external, or unused files. Because the state is shared, DataTables attempts to apply a sort index from a previous view (e.g., Column 2) to the "Unused" view, which lacks that key. This PR provides a more robust solution by:
|
|
This appears to be a good solution. But is 'state sharing' really of any value on this table? Perhaps more effective to simply not apply it here. |
|
I agree that state sharing between these specific views is problematic (that is why I run into the error!), but I find state saving quite valuable. Disabling it would cause the Media Manager to behave differently than other tables in webtrees. For example, users would lose their current page, search filters, and display length whenever the page refreshes - which isn't ideal for UX. While we could use unique IDs for each view to prevent state "bleeding" between them, that adds more complexity to the frontend/handler logic. The proposed solution is a much simpler way to make the backend robust enough to handle the shared state gracefully without sacrificing the benefits of stateSave. If useful, this is the documentation on state saving for datatables: https://datatables.net/examples/basic_init/state_save.html |
Fix Datatables error "Undefined array key 2" when using the "Manage media" utility.
To reproduce the error: