Skip to content

Commit 10610fb

Browse files
authored
chore: media library to expose path and URL (#3627)
1 parent ec77a11 commit 10610fb

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

app/components/avo/media_library/list_component.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def controller = Avo::Current.view_context.controller
1818
def query
1919
ActiveStorage::Blob.includes(:attachments)
2020
# ignore blobs who are just a variant to avoid "n+1" blob creation
21-
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").pluck(:blob_id))
21+
.where.not(id: ActiveStorage::Attachment.where(record_type: "ActiveStorage::VariantRecord").select(:blob_id))
2222
.order(created_at: :desc)
2323
end
2424

app/components/avo/media_library/list_item_component.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def data
1515
component: component_name,
1616
blob_id: blob.id,
1717
media_library_blob_param: blob.as_json,
18-
media_library_path_param: helpers.main_app.url_for(blob),
18+
media_library_path_param: helpers.main_app.rails_blob_path(blob),
19+
media_library_url_param: helpers.main_app.url_for(blob),
1920
media_library_attaching_param: @attaching,
2021
media_library_multiple_param: @multiple,
2122
media_library_selected_item: params[:controller_selector],

app/javascript/js/controllers/media_library_controller.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class extends Controller {
6767
insertAttachments(attachments, event) {
6868
// show an error if the controller is not found
6969
if (!this.otherController) {
70-
console.error('[Avo->] The Media Library failed to find any field outlets to inject the asset.')
70+
console.error(`[Avo->] The Media Library failed to find any field outlets to inject the asset. Tried selector: ${this.controllerSelectorValue} and name: ${this.controllerNameValue}`)
7171

7272
return
7373
}
@@ -82,7 +82,8 @@ export default class extends Controller {
8282
#extractMetadataFromItem(item) {
8383
const blob = JSON.parse(item.dataset.mediaLibraryBlobParam)
8484
const path = item.dataset.mediaLibraryPathParam
85+
const url = item.dataset.mediaLibraryUrlParam
8586

86-
return { blob, path }
87+
return { blob, path, url }
8788
}
8889
}

0 commit comments

Comments
 (0)