portal

https://github.com/djblue/portal
JAtkins 2020-12-01T00:30:35.047200Z

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.

JAtkins 2020-12-02T22:25:04.053100Z

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

JAtkins 2020-12-02T22:27:03.053300Z

(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

djblue 2020-12-03T02:30:01.053500Z

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

JAtkins 2020-12-03T02:30:50.054200Z

👍. Will do in the am!

JAtkins 2020-12-03T19:14:45.054400Z

Made the pr

JAtkins 2020-12-03T20:11:18.054600Z

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

djblue 2020-12-03T21:31:17.054800Z

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

djblue 2020-12-03T21:32:24.055Z

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

djblue 2020-12-03T21:32:41.055200Z

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

JAtkins 2020-12-03T21:42:52.055400Z

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

💯 1
djblue 2020-12-03T22:38:53.055700Z

Left some comments on the PR

JAtkins 2020-12-03T22:47:35.055900Z

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

djblue 2020-12-03T23:55:42.056100Z

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

djblue 2020-12-03T23:56:00.056300Z

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

JAtkins 2020-12-04T00:02:28.056600Z

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.

djblue 2020-12-04T01:21:24.056800Z

Gotcha, didn't realize that was intentional 💯

djblue 2020-12-04T01:23:08.057Z

Merged, thanks again!

djblue 2020-12-04T01:24:08.057200Z

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

🎉 1
djblue 2020-12-01T02:41:47.047300Z

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

djblue 2020-12-01T02:42:36.047500Z

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

djblue 2020-12-01T02:42:57.048100Z

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

JAtkins 2020-12-01T02:43:24.048900Z

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

djblue 2020-12-01T02:44:25.049700Z

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

JAtkins 2020-12-01T02:44:35.050Z

Oh

djblue 2020-12-01T02:44:37.050200Z

The problem is what if you picked an incompatible viewer

JAtkins 2020-12-01T02:44:43.050500Z

Yep

djblue 2020-12-01T02:45:00.050700Z

So you might want to check the compatible viewers first

JAtkins 2020-12-01T02:45:43.051400Z

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

djblue 2020-12-01T02:46:54.051600Z

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

djblue 2020-12-01T02:47:11.051900Z

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

JAtkins 2020-12-01T02:47:39.052800Z

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

💯 1