Is it possible to add a default viewer setting? I've implemented nav for some of my datatypes to provide additional metadata/docs, and it would be super nice to have them default to :portal.viewer/md
or :portal.viewer/hiccup
. I tried adding some metadata to the naved objects (`^{:portal.api/default-viewer ...} data`), but I got stuck looking through the portal code trying to figure out how to set the viewer when clicking a nav item.
I just made the changes and tested on my fork. It all passes CI, would you like a PR?
(I may need to run the formatted again before I make a PR. Seems like intellij borked it before I committed) https://github.com/djblue/portal/compare/master...JJ-Atkinson:master
I think the easiest thing to do would be to checkout from master all the formatting changes, otherwise a PR would be awesome!
👍. Will do in the am!
Made the pr
I'm very confused. I ran make fmt
before committing both times, and it still fails the check...
Thanks for the PR! When I checkout the PR make fmt
seems to fix the issue. What os are you running?
diff --git a/src/portal/ui/app.cljs b/src/portal/ui/app.cljs
index 11130a5..23a8561 100644
--- a/src/portal/ui/app.cljs
+++ b/src/portal/ui/app.cljs
@@ -155,11 +155,11 @@
viewers (cons default-viewer viewers)
compatible-viewers (filter #(when-let [pred (:predicate %)] (pred value)) viewers)]
{:compatible-viewers compatible-viewers
- :viewer
+ :viewer
(or
- (some #(when (= (:name %) selected-viewer) %)
- compatible-viewers)
- (first compatible-viewers))
+ (some #(when (= (:name %) selected-viewer) %)
+ compatible-viewers)
+ (first compatible-viewers))
:set-viewer!
(fn [viewer]
(set-settings! {:selected-viewer viewer}))}))
You can apply this diff if it doesn't seem to be working locally
I couldn't tell ya what changed, but it appears to have worked this time 🙂. I'm on Ubuntu 18 LTS btw.
Left some comments on the PR
Left a reply & a 2nd commit. Should resolve the issue if I understand it correctly
Looks good! I did notice your example doesn't seem to work.
I think you want the k and not the v in your nav fn
So, that example mirrors an example I have in my current code base. I have a graph data structure that I want to trace deps of. When I click keys in the map I'm trying to get a custom view to appear showing the dependency tree of that key. Unusual example, but I think it works.
Gotcha, didn't realize that was intentional 💯
Merged, thanks again!
I'm going to get one more feature in, hopefully this weekend 🤞 and then I'll release 0.7.0
Hi @jatkin, I've been thinking about adding this feature for a while. It should be a pretty self contained addition.
I think https://github.com/djblue/portal/blob/master/src/portal/ui/app.cljs#L154 is the place you are looking for. You have can grab the meta
from the value and use it when trying to figure out the viewer
I think I would like the key :portal.viewer/default
more, but not sure
Right. I got it to manually override, but it would prevent choosing alternate views
I think maybe you could (or selected-viewer default-viewer)
Oh
The problem is what if you picked an incompatible viewer
Yep
So you might want to check the compatible viewers first
Sure. I suppose making it self contained there is easy enough.
I think the easiest thing to do is sort the compatible-viewers
where the default viewer is at the top
That way if it isn't in the list, it is doesn't hurt
Ah, yeah. Ok, I’ll try that out tomorrow.