Fork me on GitHub
#portal
<
2020-12-01
>
JAtkins00:12:35

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.

djblue02:12:47

Hi @U5P29DSUS, I've been thinking about adding this feature for a while. It should be a pretty self contained addition.

djblue02:12:36

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

djblue02:12:57

I think I would like the key :portal.viewer/default more, but not sure

JAtkins02:12:24

Right. I got it to manually override, but it would prevent choosing alternate views

djblue02:12:25

I think maybe you could (or selected-viewer default-viewer)

djblue02:12:37

The problem is what if you picked an incompatible viewer

djblue02:12:00

So you might want to check the compatible viewers first

JAtkins02:12:43

Sure. I suppose making it self contained there is easy enough.

djblue02:12:54

I think the easiest thing to do is sort the compatible-viewers where the default viewer is at the top

djblue02:12:11

That way if it isn't in the list, it is doesn't hurt

JAtkins02:12:39

Ah, yeah. Ok, I’ll try that out tomorrow.

💯 3
JAtkins22:12:04

I just made the changes and tested on my fork. It all passes CI, would you like a PR?

JAtkins22:12:03

(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

djblue02:12:01

I think the easiest thing to do would be to checkout from master all the formatting changes, otherwise a PR would be awesome!

JAtkins02:12:50

👍. Will do in the am!

JAtkins19:12:45

Made the pr

JAtkins20:12:18

I'm very confused. I ran make fmt before committing both times, and it still fails the check...

djblue21:12:17

Thanks for the PR! When I checkout the PR make fmt seems to fix the issue. What os are you running?

djblue21:12:24

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}))}))

djblue21:12:41

You can apply this diff if it doesn't seem to be working locally

JAtkins21:12:52

I couldn't tell ya what changed, but it appears to have worked this time 🙂. I'm on Ubuntu 18 LTS btw.

💯 3
djblue22:12:53

Left some comments on the PR

JAtkins22:12:35

Left a reply & a 2nd commit. Should resolve the issue if I understand it correctly

djblue23:12:42

Looks good! I did notice your example doesn't seem to work.

djblue23:12:00

I think you want the k and not the v in your nav fn

JAtkins00:12:28

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.

djblue01:12:24

Gotcha, didn't realize that was intentional 💯

djblue01:12:08

Merged, thanks again!

djblue01:12:08

I'm going to get one more feature in, hopefully this weekend 🤞 and then I'll release 0.7.0

🎉 3