|
69 | 69 |
|
70 | 70 | (defn delta-text [name [previous current]]
|
71 | 71 | (cond
|
| 72 | + (= current previous) [:div |
| 73 | + {:key name} (str name ": ") |
| 74 | + [:span current]] |
72 | 75 | (and (some? previous) (some? current)) [:div
|
73 | 76 | {:key name} (str name ": ")
|
74 | 77 | [:span {:class ["previous"]} previous]
|
|
87 | 90 | current
|
88 | 91 | " (Attribute Added)"]]))
|
89 | 92 |
|
90 |
| -(defn tooltip-item [{:keys [name delta]}] |
| 93 | +(defn tooltip-item [[name delta]] |
91 | 94 | (if (#{"content-hash"} name)
|
92 | 95 | [:div
|
93 | 96 | {:key name}
|
94 | 97 | "Content Changed"]
|
95 | 98 | (delta-text name delta)))
|
96 | 99 |
|
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] |
98 | 107 | [:div (->>
|
99 |
| - change-record |
100 |
| - (remove #(#{"hash" "description"} (:name %))) |
| 108 | + (dissoc tooltip-record "hash" "description") |
101 | 109 | (map tooltip-item))])
|
102 | 110 |
|
| 111 | +(defn tooltip-neutral [tooltip-record] |
| 112 | + [:div (tooltip-content tooltip-record)]) |
103 | 113 |
|
104 |
| -(defn tooltip-added [] |
105 |
| - [:div "Element Added"]) |
| 114 | +(defn tooltip-added [tooltip-record] |
| 115 | + [:div "Element Added" |
| 116 | + (tooltip-content tooltip-record)]) |
106 | 117 |
|
107 |
| -(defn tooltip-removed [] |
108 |
| - [:div "Element Removed"]) |
| 118 | +(defn tooltip-removed [tooltip-record] |
| 119 | + [:div "Element Removed" |
| 120 | + (tooltip-content tooltip-record)]) |
109 | 121 |
|
110 |
| -(defn tooltip [change-record labels location placement] |
| 122 | +(defn tooltip [tooltip-record labels location placement] |
111 | 123 | [:div {:class ["mp-popover" placement]}
|
112 | 124 | [:h3 {:class "mp-popover-title"}
|
113 | 125 | (str "Line " (:line location) ", Column " (:column location))]
|
114 | 126 | [:div {:class "mp-popover-content"}
|
115 | 127 | (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))]]) |
120 | 131 |
|
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] |
123 | 133 | (when @showing-atom
|
124 | 134 | [:div {:class "mp-popover-root"}
|
125 | 135 | [:> Popper {:placement "auto" :reference-element @anchor-el}
|
126 | 136 | (fn [props]
|
127 | 137 | (let [{:keys [ref style placement]} (js->clj props :keywordize-keys true)]
|
128 | 138 | (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)])))]])) |
130 | 140 |
|
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]}] |
132 | 144 | (let [anchor-el (clojure.core/atom nil)
|
133 | 145 | img-url (name-to-img-url name false default-component-mapping mappings)
|
134 | 146 | diff-icon-url (labels-to-diff-icon-url labels)
|
135 | 147 | 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))] |
137 | 150 | (fn []
|
138 |
| - [:div {:ref #(reset! anchor-el %)} |
| 151 | + [:div {:ref #(reset! anchor-el %) :class (when @showing-atom "highlighted")} |
139 | 152 | [:div {:class ["component-container" css-class]
|
140 | 153 | :on-mouse-over (m/handler-fn
|
141 | 154 | (when should-show-tooltip
|
|
148 | 161 | (image category-url "category-frame" content-root)
|
149 | 162 | (image img-url "icon" content-root)
|
150 | 163 | [:div {:class "label"} description]]]
|
151 |
| - (popper change-record labels location showing-atom anchor-el)]))) |
| 164 | + (popper tooltip-record labels location showing-atom anchor-el)]))) |
152 | 165 |
|
153 | 166 | (defn mule-component [props]
|
154 | 167 | (let [showing-atom (r/atom false)]
|
155 | 168 | (fn [] (mule-component-inner (assoc props :showing-atom showing-atom)))))
|
156 | 169 |
|
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]}] |
158 | 173 | (let [anchor-el (clojure.core/atom nil)
|
159 | 174 | generated-css-class (name-to-css-class name)
|
160 | 175 | img-url (name-to-img-url name (some? children) nil mappings)
|
161 | 176 | category-url (name-to-category-url name default-category-image mappings)
|
162 | 177 | interposed-children (interpose (arrow content-root) children)
|
163 | 178 | 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))] |
165 | 181 | (fn []
|
166 | 182 | [: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")] |
168 | 184 | :on-mouse-over (m/handler-fn
|
169 | 185 | (when should-show-tooltip
|
170 | 186 | (reset! showing-atom should-show-tooltip)
|
|
176 | 192 | (image category-url "category-frame" content-root)
|
177 | 193 | (image img-url "icon container-image" content-root)]
|
178 | 194 | child-container-component]]
|
179 |
| - (popper change-record labels location showing-atom anchor-el)]))) |
| 195 | + (popper tooltip-record labels location showing-atom anchor-el)]))) |
180 | 196 |
|
181 | 197 | (defn mule-container [props]
|
182 | 198 | (let [showing-atom (r/atom false)]
|
|
0 commit comments