Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 739fbf7

Browse files
author
Sean Dawson
committed
feat: add tooltips to all components/containers
Instead of only showing tooltips on changed components, this change shows the attributes on all components, evn in preview mode. fix #4
1 parent 72fc823 commit 739fbf7

File tree

8 files changed

+309
-798
lines changed

8 files changed

+309
-798
lines changed

public/css/plugin.css

+16-3
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,26 @@
142142
max-width: 90px;
143143
padding: 5px;
144144
position: relative;
145+
-webkit-transition: background-color 200ms linear;
146+
-moz-transition: background-color 200ms linear;
147+
-o-transition: background-color 200ms linear;
148+
-ms-transition: background-color 200ms linear;
149+
transition: background-color 200ms linear;
145150
}
146151

147152
.mp .component-container {
148153
position: relative;
154+
border-radius: 5px;
155+
-webkit-transition: background-color 200ms linear;
156+
-moz-transition: background-color 200ms linear;
157+
-o-transition: background-color 200ms linear;
158+
-ms-transition: background-color 200ms linear;
159+
transition: background-color 200ms linear;
160+
}
161+
162+
.mp .highlighted > .component-container,
163+
.mp .highlighted.container {
164+
background-color: #f3f3f3;
149165
}
150166

151167
.mp .component > .label {
@@ -198,17 +214,14 @@
198214
/* Diffing Styles */
199215
.mp .edited {
200216
border: 2px solid #eea236;
201-
border-radius: 5px;
202217
}
203218

204219
.mp .added {
205220
border: 2px solid #4cae4c;
206-
border-radius: 5px;
207221
}
208222

209223
.mp .removed {
210224
border: 2px solid #d43f3a;
211-
border-radius: 5px;
212225
}
213226

214227
.mp .container.edited {

src/main/mule_preview/client/components.cljs

+40-24
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969

7070
(defn delta-text [name [previous current]]
7171
(cond
72+
(= current previous) [:div
73+
{:key name} (str name ": ")
74+
[:span current]]
7275
(and (some? previous) (some? current)) [:div
7376
{:key name} (str name ": ")
7477
[:span {:class ["previous"]} previous]
@@ -87,55 +90,65 @@
8790
current
8891
" (Attribute Added)"]]))
8992

90-
(defn tooltip-item [{:keys [name delta]}]
93+
(defn tooltip-item [[name delta]]
9194
(if (#{"content-hash"} name)
9295
[:div
9396
{:key name}
9497
"Content Changed"]
9598
(delta-text name delta)))
9699

97-
(defn tooltip-edited [change-record]
100+
101+
(defn generate-tooltip-record [change-record attributes]
102+
(let [regular-attribute-map (into {} (for [[k v] attributes] [(name k) [v v]]))
103+
diff-attribute-map (into {} (for [{:keys [name delta]} change-record] [name delta]))]
104+
(merge regular-attribute-map diff-attribute-map)))
105+
106+
(defn tooltip-content [tooltip-record]
98107
[:div (->>
99-
change-record
100-
(remove #(#{"hash" "description"} (:name %)))
108+
(dissoc tooltip-record "hash" "description")
101109
(map tooltip-item))])
102110

111+
(defn tooltip-neutral [tooltip-record]
112+
[:div (tooltip-content tooltip-record)])
103113

104-
(defn tooltip-added []
105-
[:div "Element Added"])
114+
(defn tooltip-added [tooltip-record]
115+
[:div "Element Added"
116+
(tooltip-content tooltip-record)])
106117

107-
(defn tooltip-removed []
108-
[:div "Element Removed"])
118+
(defn tooltip-removed [tooltip-record]
119+
[:div "Element Removed"
120+
(tooltip-content tooltip-record)])
109121

110-
(defn tooltip [change-record labels location placement]
122+
(defn tooltip [tooltip-record labels location placement]
111123
[:div {:class ["mp-popover" placement]}
112124
[:h3 {:class "mp-popover-title"}
113125
(str "Line " (:line location) ", Column " (:column location))]
114126
[:div {:class "mp-popover-content"}
115127
(cond
116-
(:added labels) (tooltip-added)
117-
(:removed labels) (tooltip-removed)
118-
(:edited labels) (tooltip-edited change-record)
119-
:else nil)]])
128+
(:added labels) (tooltip-added tooltip-record)
129+
(:removed labels) (tooltip-removed tooltip-record)
130+
:else (tooltip-neutral tooltip-record))]])
120131

121-
(defn popper [change-record labels location showing-atom anchor-el]
122-
; TODO: Remove this dependency on react-dom
132+
(defn popper [tooltip-record labels location showing-atom anchor-el]
123133
(when @showing-atom
124134
[:div {:class "mp-popover-root"}
125135
[:> Popper {:placement "auto" :reference-element @anchor-el}
126136
(fn [props]
127137
(let [{:keys [ref style placement]} (js->clj props :keywordize-keys true)]
128138
(r/as-element [:div {:ref ref :style style :data-placement placement :class placement}
129-
(tooltip change-record labels location placement)])))]]))
139+
(tooltip tooltip-record labels location placement)])))]]))
130140

131-
(defn mule-component-inner [{:keys [name description css-class content-root location change-record showing-atom labels mappings]}]
141+
(defn mule-component-inner [{:keys [name description css-class content-root
142+
location change-record showing-atom labels mappings
143+
attributes]}]
132144
(let [anchor-el (clojure.core/atom nil)
133145
img-url (name-to-img-url name false default-component-mapping mappings)
134146
diff-icon-url (labels-to-diff-icon-url labels)
135147
category-url (name-to-category-url name default-category-image mappings)
136-
should-show-tooltip (or change-record (:added labels) (:removed labels))]
148+
tooltip-record (generate-tooltip-record change-record attributes)
149+
should-show-tooltip (and (not= name "mule") (not-empty tooltip-record))]
137150
(fn []
138-
[:div {:ref #(reset! anchor-el %)}
151+
[:div {:ref #(reset! anchor-el %) :class (when @showing-atom "highlighted")}
139152
[:div {:class ["component-container" css-class]
140153
:on-mouse-over (m/handler-fn
141154
(when should-show-tooltip
@@ -148,23 +161,26 @@
148161
(image category-url "category-frame" content-root)
149162
(image img-url "icon" content-root)
150163
[:div {:class "label"} description]]]
151-
(popper change-record labels location showing-atom anchor-el)])))
164+
(popper tooltip-record labels location showing-atom anchor-el)])))
152165

153166
(defn mule-component [props]
154167
(let [showing-atom (r/atom false)]
155168
(fn [] (mule-component-inner (assoc props :showing-atom showing-atom)))))
156169

157-
(defn mule-container-inner [{:keys [name description children css-class content-root location change-record showing-atom labels mappings]}]
170+
(defn mule-container-inner [{:keys [name description children css-class content-root
171+
location change-record showing-atom labels mappings
172+
attributes]}]
158173
(let [anchor-el (clojure.core/atom nil)
159174
generated-css-class (name-to-css-class name)
160175
img-url (name-to-img-url name (some? children) nil mappings)
161176
category-url (name-to-category-url name default-category-image mappings)
162177
interposed-children (interpose (arrow content-root) children)
163178
child-container-component (child-container interposed-children)
164-
should-show-tooltip (or change-record (:added labels) (:removed labels))]
179+
tooltip-record (generate-tooltip-record change-record attributes)
180+
should-show-tooltip (and (not= name "mule") (not-empty tooltip-record))]
165181
(fn []
166182
[:div {:ref #(reset! anchor-el %)}
167-
[:div {:class ["container" generated-css-class css-class]
183+
[:div {:class ["container" generated-css-class css-class (when @showing-atom "highlighted")]
168184
:on-mouse-over (m/handler-fn
169185
(when should-show-tooltip
170186
(reset! showing-atom should-show-tooltip)
@@ -176,7 +192,7 @@
176192
(image category-url "category-frame" content-root)
177193
(image img-url "icon container-image" content-root)]
178194
child-container-component]]
179-
(popper change-record labels location showing-atom anchor-el)])))
195+
(popper tooltip-record labels location showing-atom anchor-el)])))
180196

181197
(defn mule-container [props]
182198
(let [showing-atom (r/atom false)]

src/main/mule_preview/client/diff_algorithms/diff_dom.cljs

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111
other-attributes (dissoc node :type-tag :content :type :labels :attributes :location)]
1212
{:nodeName tag-name
1313
:childNodes content
14-
:attributes (merge attributes other-attributes)
14+
:attributes attributes
15+
:other-attributes other-attributes
1516
:original-type type
1617
:original-labels labels
1718
:location location})
1819
node))
1920

2021
(defn dom-to-node [node]
2122
(if (:nodeName node)
22-
(let [{:keys [nodeName childNodes attributes original-type original-labels location]} node]
23+
(let [{:keys [nodeName childNodes attributes original-type original-labels location other-attributes]} node]
2324
(merge {:tag-name nodeName
2425
:content childNodes
2526
:type (keyword original-type)
2627
:labels original-labels
27-
:location location} attributes))
28+
:location location
29+
:attributes attributes} other-attributes))
2830
node))
2931

3032
(defn mast->dom [mast]

src/main/mule_preview/client/react.cljs

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
(clojure.string/join " " (map name labels)))
1212

1313
(defn- create-mule-component [node mappings content-root]
14-
(let [{:keys [tag-name description labels location change-record]} node]
14+
(let [{:keys [tag-name description labels location change-record attributes]} node]
1515
[(mule-component {:name tag-name
1616
:description description
1717
:css-class (labels-to-css labels)
1818
:content-root content-root
1919
:location location
2020
:change-record change-record
2121
:labels labels
22-
:mappings mappings})]))
22+
:mappings mappings
23+
:attributes attributes})]))
2324

2425
(defn- create-mule-container-component [node mappings content-root]
25-
(let [{:keys [tag-name description content labels location change-record]} node]
26+
(let [{:keys [tag-name description content labels location change-record attributes]} node]
2627
[(mule-container {:name tag-name
2728
:description description
2829
:children content
@@ -31,7 +32,8 @@
3132
:location location
3233
:change-record change-record
3334
:labels labels
34-
:mappings mappings})]))
35+
:mappings mappings
36+
:attributes attributes})]))
3537

3638
(defn- transform-tag [mappings content-root node]
3739
(let [type (:type node)]

src/test/mule_preview/client/__snapshots__/components.spec.js.snap

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`when rendering a Mule component when the component has mapping renders correctly 1`] = `
4-
<div>
4+
<div
5+
className={null}
6+
>
57
<div
68
className="component-container some-css-class"
79
onMouseOut={[Function]}
@@ -29,7 +31,9 @@ exports[`when rendering a Mule component when the component has mapping renders
2931
`;
3032

3133
exports[`when rendering a Mule component when the component is unknown renders correctly 1`] = `
32-
<div>
34+
<div
35+
className={null}
36+
>
3337
<div
3438
className="component-container some-css-class"
3539
onMouseOut={[Function]}
@@ -78,11 +82,17 @@ exports[`when rendering a Mule container when it has children renders correctly
7882
className="category-frame"
7983
src="/img/icons/org.mule.tooling.ui.modules.core.miscellaneous.large.png"
8084
/>
85+
<img
86+
className="icon container-image"
87+
src="/img/icons/UnknownNode-48x32.png"
88+
/>
8189
</div>
8290
<div
8391
className="container-children"
8492
>
85-
<div>
93+
<div
94+
className={null}
95+
>
8696
<div
8797
className="component-container some-css-class"
8898
onMouseOut={[Function]}
@@ -115,7 +125,9 @@ exports[`when rendering a Mule container when it has children renders correctly
115125
className="flow-arrow"
116126
src="/img/arrow-right-2x.png"
117127
/>
118-
<div>
128+
<div
129+
className={null}
130+
>
119131
<div
120132
className="component-container some-css-class"
121133
onMouseOut={[Function]}
@@ -148,7 +160,9 @@ exports[`when rendering a Mule container when it has children renders correctly
148160
className="flow-arrow"
149161
src="/img/arrow-right-2x.png"
150162
/>
151-
<div>
163+
<div
164+
className={null}
165+
>
152166
<div
153167
className="component-container some-css-class"
154168
onMouseOut={[Function]}
@@ -205,6 +219,10 @@ exports[`when rendering a Mule container when it has no children renders correct
205219
className="category-frame"
206220
src="/img/icons/org.mule.tooling.ui.modules.core.miscellaneous.large.png"
207221
/>
222+
<img
223+
className="icon container-image"
224+
src="/img/icons/UnknownNode-48x32.png"
225+
/>
208226
</div>
209227
<div
210228
className="container-children"

0 commit comments

Comments
 (0)