Skip to content
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

chore: media library to expose path and URL #3627

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/avo/media_library/list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def controller = Avo::Current.view_context.controller
def query
ActiveStorage::Blob.includes(:attachments)
# ignore blobs who are just a variant to avoid "n+1" blob creation
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").pluck(:blob_id))
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").select(:blob_id))
.order(created_at: :desc)
end

Expand Down
3 changes: 2 additions & 1 deletion app/components/avo/media_library/list_item_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def data
component: component_name,
blob_id: blob.id,
media_library_blob_param: blob.as_json,
media_library_path_param: helpers.main_app.url_for(blob),
media_library_path_param: helpers.main_app.rails_blob_path(blob),
media_library_url_param: helpers.main_app.url_for(blob),
media_library_attaching_param: @attaching,
media_library_multiple_param: @multiple,
media_library_selected_item: params[:controller_selector],
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/js/controllers/media_library_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class extends Controller {
insertAttachments(attachments, event) {
// show an error if the controller is not found
if (!this.otherController) {
console.error('[Avo->] The Media Library failed to find any field outlets to inject the asset.')
console.error(`[Avo->] The Media Library failed to find any field outlets to inject the asset. Tried selector: ${this.controllerSelectorValue} and name: ${this.controllerNameValue}`)

return
}
Expand All @@ -82,7 +82,8 @@ export default class extends Controller {
#extractMetadataFromItem(item) {
const blob = JSON.parse(item.dataset.mediaLibraryBlobParam)
const path = item.dataset.mediaLibraryPathParam
const url = item.dataset.mediaLibraryUrlParam

return { blob, path }
return { blob, path, url }
}
}
Loading