Fork me on GitHub
#portal
<
2021-09-21
>
seancorfield03:09:51

I'm looking over the portal site and trying to find actual documentation... what am I missing?

djblue05:09:37

Yeah, sorry about that. Been meaning to put some docs together but haven't gotten around to it yet.

seancorfield03:09:12

If I tab to the >_ icon and get the popup, it looks like I can run arbitrary Clojure on the value? (which I can do with REBL and Reveal) But it says filtering stuff so maybe I can't run an arbitrary Clojure function on the value?

djblue05:09:11

The popup is more like a vs code command menu vs a real repl

seancorfield03:09:28

The first thing I tried was (tap> (System/getenv)) which produces something like a hash map with string keys but Portal doesn't seem to be able to do anything with it -- this is displayed as a table in Reveal and REBL because it's a hash map...

seancorfield03:09:45

Hmm, it seems if I do (tap> (into {} (System/getenv))) I get what I expect...

seancorfield03:09:41

Is there anything in Portal that will take a string that is a filepath and read it/parse it?

R.A. Porter03:09:18

You can open a file with <os specific control character>+O. Not sure if that would meet your needs.

seancorfield04:09:43

No, I don't want to open a general file. I want to resolve a string that is a filepath to the contents of the file.

djblue05:09:55

If your runtime is the jvm, I have slurp setup to work with files/urls. I guess I could also add arbitrary strings :thinking_face:

seancorfield05:09:19

It would be nice if Portal allowed arbitrary Clojure code, like REBL and Reveal.

seancorfield05:09:05

Then you could do (slurp ( %)) or something. In Reveal, *v means "current value". I think it's % in REBL

seancorfield05:09:41

The problem is, if you have a value/data structure that doesn't happen to conform to Portal's (limited) set of functions, you're kind of stuck.

seancorfield05:09:39

If you had arbitrary Clojure code manipulation of results, then (tap> (System/getenv)) which produces a "map-like" thing could be viewed by just doing (into {} %) to turn it into a real hash map in Portal.

djblue06:09:46

I've been reluctant to add arbitrary eval since it wouldn't work for cljs, but I could see enabling it for clj and not cljs

seancorfield06:09:48

I'm currently comparing Reveal and Portal, since the former has now sprouted a "Pro" paid version with features I don't need, so that's just the first thing I've bumped into.

seancorfield06:09:33

I don't know how easy it is to extend Portal (given the lack of docs) but I have some custom "table view" stuff for Reveal that I'd want to get running in Portal before I could switch.

djblue06:09:03

When I start needing complex manipulations, I tend to select the value I care about and manipulate if from my code editor

djblue06:09:31

If you deref the portal atom, it returns back the currently selected value

seancorfield06:09:46

That doesn't really work if you're tap>'ing values tho' -- you can't just explore the values, you have to go back into the code and rework the tap> calls.

djblue06:09:50

And for objects, the exact instance

djblue06:09:43

Since those values make it into the client, they are still selectable and can be derefed

seancorfield06:09:51

For the Portal-as-atom thing, can you get back prior values or just the current value?

djblue06:09:28

You can, as swap and reset push values into the client history

djblue06:09:04

And the semantics of deref are more like: give me the currently selected value in the ui, even if it isn't the root value

djblue06:09:53

That way you get your data back in the repl you are most comfortable with 👌

seancorfield06:09:29

OK, so I just did this:

(def p (p/open))
(tap> (System/getenv))
@p
and got nil -- shouldn't I get back the value of (System/getenv)?

djblue06:09:57

You have to select it in the ui first

djblue06:09:00

It use to auto-select the root value but that changed to support the node runtime

djblue06:09:47

What type of table customizations do you have setup for reveal? If you don't mind me asking

seancorfield06:09:37

If I have an element selected in the Portal view, how do I navigate to the >_ button via the keyboard? I tried tab but that seems to cycle through other selections before moving to the view drop-down and then the >_ button.

djblue06:09:12

You can do cmd + shift + p or ctrl + j for firefox

seancorfield06:09:41

Thanks! Yes, ctrl + j works for google-chrome on WSL2 as well.

seancorfield06:09:19

Definitely need more options in that command list!

seancorfield06:09:39

Can I register additional functions for that?

djblue06:09:17

Not yet because no one has asked for it yet

seancorfield06:09:33

Really? I'm shocked! 😐

djblue06:09:42

The one thing I haven't figured out is how to allow for custom menus like for select-keys and get-in

djblue06:09:52

Also, I think for a custom table view, I think leveraging the hiccup viewer could work

seancorfield06:09:37

I tried to alter-var-root that private var to add 'keywordize #(update-keys % keyword) and when I invoked it I got an NPE. What does it expect the value of those map elements to be? It looks like they can be function values...

seancorfield06:09:32

The NPE was from the (apply f args) so presumably f was nil?

djblue06:09:57

I forgot, there are two maps one for public fns and another for private + public fns

djblue06:09:17

Update that one too and it works 😆

djblue06:09:33

What would an api for this look like to you?

seancorfield06:09:40

Is there a trick for working with a local copy of Portal? I cloned it and started a REPL pointing to the local root version and got that main.js error:

user=> (def p (p/open))
#'user/p
user=> Mon Sep 20 23:36:09 PDT 2021 [worker-2] ERROR - GET /main.js
java.lang.IllegalArgumentException: Cannot open <nil> as a Reader.
	at $fn__11544.invokeStatic(io.clj:288)
	at $fn__11544.invoke(io.clj:288)
	at $fn__11446$G__11422__11453.invoke(io.clj:69)
	at $reader.invokeStatic(io.clj:102)
	at $reader.doInvoke(io.clj:86)
	at clojure.lang.RestFn.invoke(RestFn.java:410)
	at clojure.lang.AFn.applyToHelper(AFn.java:154)
	at clojure.lang.RestFn.applyTo(RestFn.java:132)
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$slurp.invokeStatic(core.clj:6944)
	at clojure.core$slurp.doInvoke(core.clj:6944)
	at clojure.lang.RestFn.invoke(RestFn.java:410)
	at portal.runtime.jvm.server$main_js.invokeStatic(server.clj:87)

djblue06:09:08

I would do bb dev

djblue06:09:56

You need a shadow-cljs dev server to build the client cljs

seancorfield06:09:44

Ugh! I don't do any cljs and don't have bb or node or anything installed.

seancorfield06:09:27

BTW, I added a function to the fns map and it didn't even show up in the ctrl + j menu...

djblue06:09:03

Yeah, I think it needs to be added to both since the first map is about which fns are public and the second map is the merge of that and all the private ones which is used for the dispatch

seancorfield06:09:40

OK, yeah, that worked.

seancorfield06:09:34

And that does let me turn the (System/getenv) into a regular hash map with keywords for keys.

seancorfield06:09:04

(although (partial into {}) is really all I need there)

seancorfield06:09:32

OK, I'm heading to bed. I may well play with this some more tomorrow, but without arbitrary eval it's a bit limited (although I don't use that in REBL/Reveal all that often so maybe I can live without it). I'll take a look at the Hiccup view thing to create custom views -- there's no docs for that, right?

djblue06:09:10

No docs, but I would explore the demo data to see what's possible 👌

seancorfield06:09:12

Knowing how to manipulate the runtime vars to add functions to the menu is a big step forward so thank you for that.

djblue06:09:47

I'm hoping to put together an api for that and also keyboard shortcuts so you can bind arbitrary fns to keystrokes 💯

seancorfield06:09:48

I much prefer written documentation to grubbing through a demo (or, worse, watching a video) but I'm kinda old school.

👍 2
seancorfield06:09:43

I'll probably switch my :dev/repl alias over to Portal tomorrow and see how I get on with my day tap>'ing values into it. Expect complaints and suggestions 🙂

💯 2
seancorfield06:09:02

Your TZ looks West Coast, like me. Where are you at?

👍 2
djblue06:09:31

For now, Phoenix AZ is weird like that 😆

seancorfield06:09:32

Ah, OK. I have in-laws there (and Tucson) and one of my former colleagues moved there from the Bay Area. "It's a dry heat!" 🙂

😆 2
seancorfield06:09:07

OK Chris, well, thanks for all your help!

djblue07:09:42

Please let me know all the bad things and I'll see about those docs

seancorfield07:09:15

(and starting my REPL like this: SOCKET_REPL_PORT=5000 clojure -Sforce -M:rebel:portal:everything:dev:test:runner:build:dev/repl)

seancorfield07:09:26

I'll let you know how it goes!

seancorfield17:09:19

Is there a way to display a URL's web page in Portal -- more directly than ctrl-j slurp v html? Can a function that processes values tell Portal how to then display the result?

djblue17:09:32

I think something like this might work :thinking_face:

(defn doc [url]
  (with-meta
    [:div
     {:style {:background :white}}
     [:portal.viewer/html (slurp url)]]
    {:portal.viewer/default :portal.viewer/hiccup}))

djblue17:09:17

And then add that as the command you call instead

seancorfield17:09:29

Oh nice! I can provide metadata that instructs Portal how to display things! Awesome! That's not in the docs, right? I didn't just completely miss it, did I?

djblue17:09:14

It's partially documented in the demo, but you are correct, no direct documentation 😢

djblue17:09:25

The https://github.com/djblue/portal/blob/master/CHANGELOG.md might be the best source of documentation currently

seancorfield17:09:16

I don't do well with video "documentation", sorry. I haven't actually watched it yet, so maybe I'll do that and make notes and, hey, maybe I'll contribute some documentation back! 🙂

seancorfield17:09:25

And that doc function works perfectly! Thank you!!

💯 2
seancorfield17:09:58

Ah, I played with that site/demo but it didn't tell me anything about the API and it was initially very hard to figure out how to navigate the UI (I didn't realize I needed to TAB around to get focus on the value panel so that I could use the other nav commands).

👍 2
seancorfield18:09:15

On the plus side, I'm really liking it so far 🙂

seancorfield18:09:03

One thing I'd like is a shortcut to navigate back to the "top" -- if I've been drilling into data and then switch back to the editor and eval (tap) some new value, I don't see it in Portal because it doesn't shift focus when new data is tapped -- which I can see pros and cons with, but a quick hotkey to get all the back up to the top would save a bunch of cmd-left

djblue18:09:02

I think cmd-shift-left will take you all the way back to the tap list, is that what you mean?

seancorfield18:09:55

Oh, let me try that...

seancorfield18:09:05

Hah, yes, it does!

djblue18:09:25

cmd-shift-right will also take you all the way back 👌

djblue18:09:06

Also, if you don't want to nav, but just expand a value, you can do e

seancorfield18:09:48

Yup, found that in the docs.

seancorfield18:09:32

It would be nice if there was a key to jump up into the filter box - / maybe (since that seems to be a shortcut on a lot of web apps).

👍 2
seancorfield18:09:06

Ah, I see why I didn't spot cmd-shift-left in the popup: the "left" part had rendered as just an empty box character...

djblue18:09:18

Weird, those should be normal unicode characters :thinking_face:

seancorfield18:09:06

Let me restart the REPL in case some of the experimentation I've been doing has borked it...

seancorfield18:09:48

Nope, still little square boxes.

djblue18:09:31

I'll probably just switch from unicode arrows to svg graphics then 👌

seancorfield18:09:24

<div class=" G__54">⭢</div>
That's what I get from Google Chrome inspector.

djblue18:09:35

weird that it works in the chrome inspector but not in the ui

seancorfield17:09:45

(with Reveal I have a have a hotkey to eval some code that, given a Java object/type, produces a URL into Oracle's docs, which Reveal can then auto-display inline as a web page with an extra bit of code)

seancorfield17:09:01

Also, it might be nice for the HTML viewer to set the default background to white regardless of the theme -- I prefer a dark them overall but displaying web pages inline can be unreadable if the web page assumes a light background (which a lot do).

seancorfield17:09:30

Compare these two screenshots (viewing Java docs inline):

seancorfield18:09:51

(fyi @djblue gave me a code snippet to solve this -- see long thread above! -- thank you!)

seancorfield18:09:25

I'm curious, why is portal.api/tap deprecated?

djblue18:09:49

I think it's better if people do (add-tap #'p/submit) because then it obvious how to stop pushing values to portal, (remove-tap #'p/submit) .

djblue18:09:58

I guess better composition

djblue18:09:09

Should probably include that info in the doc string

djblue18:09:52

Also, you have the ability to wrap submit with custom logic, like attaching date/time and any other customizations you'd like 👌

seancorfield18:09:10

Fair enough. That was how I'd started using Portal but then I saw (p/tap) in the example code somewhere...

seancorfield18:09:21

Ah, there's two mentions of that in the figwheel-main example folder.

seancorfield18:09:30

I thought I'd read it somewhere else too...

djblue18:09:19

(defn ->date [value]
  ^{:portal.viewer/default :portal.viewer/hiccup}
  [:portal.viewer/relative-time value])

(defn my-submit [value]
  (p/submit
   (cond
     (date? value)
     (->date value)
     :else value)))

(add-tap #'my-submit)

djblue18:09:30

That's the kind of customization I was after 👌

djblue18:09:09

This is very useful for values that don't support metadata directly but where you still want to customize display

djblue18:09:52

Really need that :as-alias for these 😆

seancorfield19:09:23

The relative time viewer is really nice!

❤️ 2
seancorfield18:09:51

(fyi @djblue gave me a code snippet to solve this -- see long thread above! -- thank you!)

seancorfield19:09:32

I've updated my dot-clojure repo to make Portal a "first class citizen" and I'm going to use it at work (instead of Reveal) for at least the rest of this week -- and may permanently switch if it works well for me 🙂

djblue19:09:20

Awesome! Looking forward to more feedback. Already have ideas to make things better based on your existing feedback :thumbsup: