Skip to content
Snippets Groups Projects
Unverified Commit c8f79fd2 authored by Jerry Huang's avatar Jerry Huang Committed by GitHub
Browse files

Render markdown in card and dashboard descriptions (#30398)

* initial changes

* fix linter

* update test

* remove dbg

* revert messages

* update subject

* add test

* fix test

* remove space

* fix spacing

* re-add position

* fix spacing
parent 59fc8f1f
Branches
Tags
No related merge requests found
......@@ -97,7 +97,7 @@
<td>&#8202;</td>
<td>
<div class="description" style="color: {{colorTextDark}}; font-size: 14px">
{{dashboardDescription}}
{{{dashboardDescription}}}
</div>
</td>
</tr>
......
......@@ -383,7 +383,7 @@
(let [email-recipients (filterv u/email? (map :email recipients))
query-results (filter :card results)
timezone (-> query-results first :card defaulted-timezone)
dashboard (t2/select-one Dashboard :id dashboard-id)]
dashboard (update (t2/select-one Dashboard :id dashboard-id) :description markdown/process-markdown :html)]
{:subject (subject pulse)
:recipients email-recipients
:message-type :attachments
......
......@@ -2,6 +2,7 @@
(:require
[hiccup.core :refer [h]]
[metabase.models.dashboard-card :as dashboard-card]
[metabase.pulse.markdown :as markdown]
[metabase.pulse.render.body :as body]
[metabase.pulse.render.common :as common]
[metabase.pulse.render.image-bundle :as image-bundle]
......@@ -57,7 +58,7 @@
:content [:div {:style (style/style {:color style/color-text-medium
:font-size :12px
:margin-bottom :8px})}
description]})))
(markdown/process-markdown description :html)]})))
(defn detect-pulse-chart-type
"Determine the pulse (visualization) type of a `card`, e.g. `:scalar` or `:bar`."
......
......@@ -141,11 +141,18 @@
DashboardCard [dc1 {:dashboard_id (:id dashboard) :card_id (:id card)
:visualization_settings {:card.description "Visualization description"}}]]
(binding [render/*include-description* true]
(is (= "Visualization description" (last (:content (#'render/make-description-if-needed dc1 card))))))))
(is (= "<p>Visualization description</p>\n" (last (:content (#'render/make-description-if-needed dc1 card))))))))
(testing "Fallback to Card's description if Visualization Settings's description not exists"
(mt/with-temp* [Card [card {:description "Card description"}]
Dashboard [dashboard]
DashboardCard [dc1 {:dashboard_id (:id dashboard) :card_id (:id card)}]]
(binding [render/*include-description* true]
(is (= "Card description" (last (:content (#'render/make-description-if-needed dc1 card)))))))))
(is (= "<p>Card description</p>\n" (last (:content (#'render/make-description-if-needed dc1 card))))))))
(testing "Test markdown converts to html"
(mt/with-temp* [Card [card {:description "# Card description"}]
Dashboard [dashboard]
DashboardCard [dc1 {:dashboard_id (:id dashboard) :card_id (:id card)}]]
(binding [render/*include-description* true]
(is (= "<h1>Card description</h1>\n" (last (:content (#'render/make-description-if-needed dc1 card)))))))))
......@@ -8,6 +8,8 @@
[metabase.integrations.slack :as slack]
[metabase.models
:refer [Card Collection Pulse PulseCard PulseChannel PulseChannelRecipient]]
[metabase.models.dashboard :refer [Dashboard]]
[metabase.models.dashboard-card :refer [DashboardCard]]
[metabase.models.permissions :as perms]
[metabase.models.permissions-group :as perms-group]
[metabase.models.pulse :as pulse]
......@@ -680,6 +682,26 @@
[test-card-result pulse.test-util/png-attachment pulse.test-util/png-attachment])
(mt/summarize-multipart-email test-card-regex))))))))
(deftest dashboard-description-markdown-test
(testing "Dashboard description renders markdown"
(mt/with-temp* [Card [{card-id :id} {:name "Test card"}]
Dashboard [{dashboard-id :id} {:description "# dashboard description"}]
DashboardCard [{dashboard-card-id :id} {:dashboard_id dashboard-id
:card_id card-id}]
Pulse [{pulse-id :id} {:name "Pulse Name"
:dashboard_id dashboard-id}]
PulseCard [_ {:pulse_id pulse-id
:card_id card-id
:dashboard_card_id dashboard-card-id}]
PulseChannel [{pc-id :id} {:pulse_id pulse-id}]
PulseChannelRecipient [_ {:user_id (pulse.test-util/rasta-id)
:pulse_channel_id pc-id}]]
(pulse.test-util/email-test-setup
(metabase.pulse/send-pulse! (pulse/retrieve-notification pulse-id))
(is (= (mt/email-to :rasta {:subject "Pulse Name"
:body {"<h1>dashboard description</h1>" true}})
(mt/regex-email-bodies #"<h1>dashboard description</h1>")))))))
(deftest basic-slack-test-2
(testing "Basic slack test, 2 cards, 1 recipient channel"
(mt/with-temp* [Card [{card-id-1 :id} (pulse.test-util/checkins-query-card {:breakout [!day.date]})]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment