Skip to content

Commit

Permalink
add visual indicator for nav values
Browse files Browse the repository at this point in the history
no clue how to actually display, so using italic for now.
somehow want to show that a nav actually resulted in a different
value
  • Loading branch information
thheller committed May 20, 2024
1 parent 34a56a3 commit 2c45593
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/main/shadow/cljs/ui/components/inspect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
:tab-index (if active? 0 -1)}
label]))

(defc ui-object-crumb [{:keys [nav-idx nav-from oid] :as stack-item} panel-idx active?]
(defc ui-object-crumb [{:keys [nav? nav-idx nav-from oid] :as stack-item} panel-idx active?]
(bind object
(sg/kv-lookup ::m/object (or nav-from oid)))

Expand All @@ -256,6 +256,7 @@
(render
(<< [:div {:class (css :border-r :p-2 :cursor-pointer :truncate {:max-width "160px"})
:style/font-weight (if active? "600" "400")
:style/font-style (if nav? "italic" "normal")
:on-click {:e ::m/inspect-set-current! :idx panel-idx}}
label])))

Expand Down
3 changes: 2 additions & 1 deletion src/main/shadow/cljs/ui/db/inspect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
(assoc-in [::m/inspect :current] (inc panel-idx))))))

:obj-result-ref
(let [{:keys [oid ref-oid from summary]}
(let [{:keys [oid nav? ref-oid from summary]}
call-result

obj
Expand All @@ -418,6 +418,7 @@
(-> (subvec stack 0 (inc panel-idx))
(conj {:type :object-panel
:oid ref-oid
:nav? nav?
:nav-from oid
:nav-idx idx}))]

Expand Down
4 changes: 3 additions & 1 deletion src/main/shadow/cljs/ui/db/relay_ws.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
(str (str/replace js/self.location.protocol "http" "ws")
"//" js/self.location.host
"/api/remote-relay"
"?server-token=" server-token))
"?id=shadow-cljs-ui"
"&server-token=" server-token
))
ws-ref (atom socket)]

(swap! rt-ref assoc
Expand Down
24 changes: 16 additions & 8 deletions src/main/shadow/remote/runtime/obj_support.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
:cljs [[cljs.repl :refer (error->str)]]))
#?(:clj (:import [java.util UUID])))

(defrecord Reference [obj])
(defrecord Reference [obj extra])

(defn obj-ref [obj]
(when (some? obj)
(Reference. obj)))
(defn obj-ref
([obj]
(obj-ref obj nil))
([obj extra]
(when (some? obj)
(Reference. obj extra))))

(defn obj-ref? [result]
(instance? Reference result))
Expand Down Expand Up @@ -170,7 +173,10 @@
(cond->
;; only send new-obj :summary when requested
(:summary msg)
(assoc :summary (obj-describe* this new-oid))))]
(assoc :summary (obj-describe* this new-oid))

(:extra result)
(merge (:extra result))))]
(shared/reply runtime msg reply-msg))))

(catch #?(:clj Exception :cljs :default) e
Expand Down Expand Up @@ -314,20 +320,22 @@
(or (vector? data) (list? data))
(let [val (nth data idx)
nav (d/nav data idx val)]
(obj-ref nav))
;; using not= since the value might not be identical but equal
;; nav may attach more metadata without altering actual value
(obj-ref nav {:nav? (not= val nav)}))

(map? data)
(let [view-order (cache-view-order state-ref entry (keys data))
key (nth view-order idx)
val (get data key)
nav (d/nav data key val)]
(obj-ref nav))
(obj-ref nav {:nav? (not= val nav)}))

(set? data)
(let [view-order (cache-view-order state-ref entry data)
val (nth view-order idx)
nav (d/nav data idx val)]
(obj-ref nav))
(obj-ref nav {:nav? (not= val nav)}))

:else
(throw (ex-info "nav not supported?" entry))))))
Expand Down

0 comments on commit 2c45593

Please sign in to comment.