diff --git a/lib/music_library/collection.ex b/lib/music_library/collection.ex index 566c234e..0c8d91bd 100644 --- a/lib/music_library/collection.ex +++ b/lib/music_library/collection.ex @@ -77,7 +77,11 @@ defmodule MusicLibrary.Collection do where: fragment("records.purchased_at IS NOT NULL"), group_by: fragment("json_extract(?, '$.name')", r.value), order_by: [desc: fragment("count(1)")], - select: {fragment("json_extract(?, '$.name')", r.value), fragment("count(1)")}, + select: %{ + id: fragment("json_extract(?, '$.musicbrainz_id')", r.value), + name: fragment("json_extract(?, '$.name')", r.value), + count: fragment("count(1)") + }, limit: ^limit Repo.all(q) diff --git a/lib/music_library_web/live/stats_live/index.html.heex b/lib/music_library_web/live/stats_live/index.html.heex index 22758c8d..d18e1a15 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -79,11 +79,11 @@ width={600} height={35 * length(@records_by_artist)} bar_color="rgb(79, 70, 229)" - label_fn={fn {artist, _count} -> artist end} - value_fn={fn {_artist, count} -> count end} + label_fn={fn datum -> datum.name end} + value_fn={fn datum -> datum.count end} label_click={ - fn {artist, _count} -> - JS.navigate(~p"/collection?#{%{query: ~s(artist:"#{artist}")}}") + fn datum -> + JS.navigate(~p"/artists/#{datum.id}") end } class="w-full"