Default viewer for values based on key for associative structures
MrEbbinghaus opened this issue · comments
It would be great to be able to assign default viewers to values of associative structures like maps, without using metadata, which often is a pain.
Example:
I use µlog for logging and tracing, a log value may look like this:
{:user-agent nil,
:mulog/duration 2173538,
:mulog/namespace "my.namespace",
:mulog/outcome :ok,
:mulog/parent-trace nil,
:http-status 200,
:mulog/root-trace #mulog/flake "4t1B0IuXNLj7lPIClpVFiSU-MwnVGYs1",
:mulog/timestamp 1698011013823,
:uri "/",
:mulog/trace-id #mulog/flake "4t1B0IuXNLj7lPIClpVFiSU-MwnVGYs1",
:request-method :get,
:mulog/event-name :my.namespace/http-request}
It would be great if you could add a key → viewer config to portal, that declares the default viewer for the value of a key.
{:mulog/duration :portal.viewer/duration-ns
:mulog/timestamp :portal.viewer/relative-time
; maybe even a custom view function...
:mulog/outcome (fn [value] [:span {:style {:color (if (#{:ok} value) "green" "red")}} value])}
I have code that solves this for me, but I think this could be a feature that would be really handy to have in portal itself, as it allows for simple customization, without the hassle of adding metadata to everything.
I would like feedback before I decide if this is something I even could contribute on my own. 🙂
@MrEbbinghaus Gotcha, I think this is mostly already supported in Portal via :portal.viewer/for {}
in metadata. For example, here is how it's used for portal.nrepl.