The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
feat: card deep links in pulses (#61794)
Edward Pagetc2bea1ca8a93
diff --git a/src/metabase/channel/impl/slack.clj b/src/metabase/channel/impl/slack.cljindex 8fe963006cf..d8a11e9d07a 100644--- a/src/metabase/channel/impl/slack.clj+++ b/src/metabase/channel/impl/slack.clj@@ -86,42 +86,47 @@(defn- part->sections!"Converts a notification part directly into Slack Block Kit blocks."- [part]- (let [part (channel.shared/maybe-realize-data-rows part)]- (case (:type part)- :card- (let [{:keys [card dashcard result]} part- {card-id :id card-name :name :as card} card- title (or (-> dashcard :visualization_settings :card.title)- card-name)- rendered-info (channel.render/render-pulse-card :inline (channel.render/defaulted-timezone card) card dashcard result)- title-link (when-not (= :table-editable (:display card))- (urls/card-url card-id))]- (conj (maybe-append-params-block- [{:type "section"- :text {:type "mrkdwn"- :text (mkdwn-link-text title-link title)- :verbatim true}}]- (-> dashcard :visualization_settings :inline_parameters))- (if (:render/text rendered-info)- {:type "section"- :text {:type "plain_text"- :text (:render/text rendered-info)}}- {:type "image"- :slack_file {:id (-> rendered-info- (channel.render/png-from-render-info slack-width)- (slack/upload-file! (format "%s.png" title))- :id)}- :alt_text title})))-- :heading- [(maybe-append-params-block (text->markdown-section (format "## %s" (:text part))) (:inline_parameters part))]-- :text- [(maybe-append-params-block (text->markdown-section (:text part)) (:inline_parameters part))]-- :tab-title- [(text->markdown-section (format "# %s" (:text part)))])))+ ([part]+ (part->sections! {} part))+ ([all-params part]+ (let [part (channel.shared/maybe-realize-data-rows part)]+ (case (:type part)+ :card+ (binding [urls/*dashcard-parameters* all-params]+ (let [{:keys [card dashcard result]} part+ {card-id :id card-name :name :as card} card+ title (or (-> dashcard :visualization_settings :card.title)+ card-name)+ rendered-info (channel.render/render-pulse-card :inline (channel.render/defaulted-timezone card) card dashcard result)+ title-link (if dashcard+ (urls/dashcard-url dashcard)+ (when-not (= :table-editable (:display card))+ (urls/card-url card-id)))]+ (conj (maybe-append-params-block+ [{:type "section"+ :text {:type "mrkdwn"+ :text (mkdwn-link-text title-link title)+ :verbatim true}}]+ (-> dashcard :visualization_settings :inline_parameters))+ (if (:render/text rendered-info)+ {:type "section"+ :text {:type "plain_text"+ :text (:render/text rendered-info)}}+ {:type "image"+ :slack_file {:id (-> rendered-info+ (channel.render/png-from-render-info slack-width)+ (slack/upload-file! (format "%s.png" title))+ :id)}+ :alt_text title}))))++ :heading+ [(maybe-append-params-block (text->markdown-section (format "## %s" (:text part))) (:inline_parameters part))]++ :text+ [(maybe-append-params-block (text->markdown-section (:text part)) (:inline_parameters part))]++ :tab-title+ [(text->markdown-section (format "# %s" (:text part)))]))))(def ^:private SlackMessage[:map {:closed true}@@ -190,7 +195,7 @@top-level-params (impl.util/remove-inline-parameters all-params (:dashboard_parts payload))dashboard (:dashboard payload)blocks (->> [(slack-dashboard-header dashboard (:common_name creator) all-params top-level-params)- (mapcat part->sections! (:dashboard_parts payload))]+ (mapcat (partial part->sections! all-params) (:dashboard_parts payload))]flatten(remove nil?))](for [channel-id (map notification-recipient->channel recipients)]diff --git a/src/metabase/channel/render/card.clj b/src/metabase/channel/render/card.cljindex 7068caea770..12d6aba8d11 100644--- a/src/metabase/channel/render/card.clj+++ b/src/metabase/channel/render/card.clj@@ -31,11 +31,6 @@[card](h (urls/card-url (u/the-id card))))-(defn- visualizer-dashcard-href- "Build deep linking href for visualizer dashcards"- [dashcard]- (h (str (urls/dashboard-url (:dashboard_id dashcard)) "#scrollTo=" (:id dashcard))))-(mu/defn- make-title-if-needed :- [:maybe ::body/RenderedPartCard][render-type card dashcard options :- [:maybe ::options]](when (:channel.render/include-title? options)@@ -44,8 +39,8 @@(-> card :name))image-bundle (when (:channel.render/include-buttons? options)(image-bundle/external-link-image-bundle render-type))- title-href (if (render.util/is-visualizer-dashcard? dashcard)- (visualizer-dashcard-href dashcard)+ title-href (if dashcard+ (urls/dashcard-url dashcard)(card-href card))]{:attachments (when image-bundle(image-bundle/image-bundle->attachment image-bundle))@@ -188,8 +183,8 @@{pulse-body :contentbody-attachments :attachmentstext :render/text} (render-pulse-card-body render-type timezone-id card dashcard results)- attachment-href (if (render.util/is-visualizer-dashcard? dashcard)- (visualizer-dashcard-href dashcard)+ attachment-href (if dashcard+ (urls/dashcard-url dashcard)(card-href card))inline-parameters (when (:channel.render/include-inline-parameters? options)(-> dashcard :visualization_settings :inline_parameters))]diff --git a/src/metabase/channel/urls.clj b/src/metabase/channel/urls.cljindex 8d1d21d7f4d..cfaa03d4227 100644--- a/src/metabase/channel/urls.clj+++ b/src/metabase/channel/urls.clj@@ -29,18 +29,18 @@(dashboard-url 10) -> \"http://localhost:3000/dashboard/10\""([^Integer id](format "%s/dashboard/%d" (site-url) id))- ([^Integer id parameters]+ ([^Integer id parameters & [tab-id]](let [base-url (dashboard-url id)- url-params (flatten- (for [param parameters- :let [values (shared.params/param-val-or-default param)]]- (for [value (if ((some-fn sequential? set? nil?) values)- values- [values])]- (str (codec/url-encode (:slug param))- "="- (codec/url-encode value)))))]-+ url-params (cond-> (flatten+ (for [param parameters+ :let [values (shared.params/param-val-or-default param)]]+ (for [value (if ((some-fn sequential? set? nil?) values)+ values+ [values])]+ (str (codec/url-encode (:slug param))+ "="+ (codec/url-encode value)))))+ tab-id (conj (str "tab=" tab-id)))](str base-url (when (seq url-params)(str "?" (str/join "&" url-params)))))))@@ -51,6 +51,16 @@[^Integer id](format "%s/question/%d" (site-url) id))+(def ^:dynamic *dashcard-parameters*+ "Bind dashboard parameters for dashcard deeplinked urls"+ {})++(defn dashcard-url+ "Build deep linking href for visualizer dashcards"+ [{:keys [dashboard_id id dashboard_tab_id]}]+ (str (dashboard-url dashboard_id *dashcard-parameters* dashboard_tab_id)+ "#scrollTo=" id))+(defn legacy-pulse-url"Return an appropriate URL for a legacy `Pulse` with ID.diff --git a/test/metabase/channel/impl/email_test.clj b/test/metabase/channel/impl/email_test.cljindex 9694771cddd..46507ec3d35 100644--- a/test/metabase/channel/impl/email_test.clj+++ b/test/metabase/channel/impl/email_test.clj@@ -1,10 +1,12 @@(ns metabase.channel.impl.email-test(:require+ [clojure.string :as str][clojure.test :refer :all][metabase.channel.core :as channel][metabase.channel.email :as email][metabase.channel.impl.email :as email.impl][metabase.channel.render.util :as render.util]+ [metabase.channel.urls :as urls][metabase.test :as mt]))(deftest bcc-enabled-test@@ -56,3 +58,38 @@"Should include CSV attachment setting using the fallback match")(is (true? (-> result first :card :format_rows))"Should include format_rows setting using the fallback match")))))++(deftest dashboard-notification-dashcard-links-test+ (testing "Dashboard notification renders dashcard links with parameters like Slack implementation"+ (let [dashboard-id 42+ card-id 123+ dashcard-id 456+ dashboard-params [{:name "State"+ :slug "state"+ :id "63e719d0"+ :default ["CA" "NY" "NJ"]+ :type "string/="+ :sectionId "location"}]+ notification {:payload_type :notification/dashboard+ :payload {:dashboard {:id dashboard-id+ :name "Test Dashboard"}+ :parameters dashboard-params+ :dashboard_parts [{:type :card+ :card {:id card-id+ :name "Test Card"}+ :dashcard {:id dashcard-id+ :dashboard_id dashboard-id}}]+ :dashboard_subscription {:id 789+ :dashboard_subscription_dashcards []}}}+ recipients [{:type :notification-recipient/user+ :user {:email "[email protected]"}}]]+ (mt/with-temporary-setting-values [site-url "http://example.com"]+ (binding [urls/*dashcard-parameters* dashboard-params]+ (let [result (channel/render-notification :channel/email notification {:recipients recipients})+ rendered-content (-> result first :message first :content)]++ (testing "Dashboard parameters are bound during rendering"+ (is (some? result))+ (is (= 1 (count result)))+ (is (string? rendered-content))+ (is (str/includes? rendered-content "http://example.com/dashboard/42?state=CA&state=NY&state=NJ#scrollTo=456")))))))))diff --git a/test/metabase/channel/impl/slack_test.clj b/test/metabase/channel/impl/slack_test.cljindex 034a82b0973..2a95747c38f 100644--- a/test/metabase/channel/impl/slack_test.clj+++ b/test/metabase/channel/impl/slack_test.clj@@ -114,3 +114,29 @@(testing "When whitelabeling is disabled, branding content should be included"(let [links (render-dashboard-links false)](is (= 2 (count links)))))))++(deftest dashboard-card-links-include-parameters-test+ (let [dashboard-id 42+ card-id 123+ dashboard-params [{:name "State",+ :slug "state",+ :id "63e719d0",+ :default ["CA", "NY", "NJ"],+ :type "string/=",+ :sectionId "location"}]+ notification {:payload_type :notification/dashboard+ :payload {:dashboard {:id dashboard-id :name "Test Dashboard"}+ :parameters dashboard-params+ :dashboard_parts [{:type :card+ :card {:id card-id :name "Test Card"}+ :dashcard {:id 456 :dashboard_id dashboard-id}}]}+ :creator {:common_name "Test User"}}+ recipient {:type :notification-recipient/raw-value+ :details {:value "#test-channel"}}]+ (with-redefs [slack/upload-file! (fn [_ _] {:id "uploaded-file-id"})]+ (mt/with-temporary-setting-values [site-url "http://example.com"]+ (let [processed (channel/render-notification :channel/slack notification {:recipients [recipient]})+ card-section (-> processed first :blocks (nth 3))]+ (is (= "section" (:type card-section)))+ (is (= "<http://example.com/dashboard/42?state=CA&state=NY&state=NJ#scrollTo=456|Test Card>"+ (-> card-section :text :text))))))))diff --git a/test/metabase/channel/render/card_test.clj b/test/metabase/channel/render/card_test.cljindex 40c21627fdb..2d95b9a39da 100644--- a/test/metabase/channel/render/card_test.clj+++ b/test/metabase/channel/render/card_test.clj@@ -296,7 +296,21 @@(is (some? (lib.util.match/match-one rendered-card-content[:a (_ :guard #(= (format "https://mb.com/question/%d" (:id card)) (:href %))) "A Card"]))))))))-(deftest visualizer-href-includes-scroll+(deftest href-includes-scroll+ (testing "the title and body hrefs for cards in dashboards should be of the form '.../dashboard/<DASHBOARD_ID>#scrollTo=<DASHBOARD_CARD_ID>'"+ (mt/with-temp [:model/Card card {:name "A Card"+ :dataset_query (mt/mbql-query venues {:limit 1})}+ :model/Dashboard dashboard {}+ :model/DashboardCard dc1 {:dashboard_id (:id dashboard) :card_id (:id card)}]+ (mt/with-temp-env-var-value! [mb-site-url "https://mb.com"]+ (let [rendered-card-content (:content (channel.render/render-pulse-card :inline+ (channel.render/defaulted-timezone card)+ card+ dc1+ (qp/process-query (:dataset_query card))+ {:channel.render/include-title? true}))+ expected-href (format "https://mb.com/dashboard/%d#scrollTo=%d" (:dashboard_id dc1) (:id dc1))]+ (is (every? true? (map #(= (:href %) expected-href) (lib.util.match/match rendered-card-content {:href _}))))))))(testing "the title and body hrefs for visualizer cards should be of the form '.../dashboard/<DASHBOARD_ID>#scrollTo=<DASHBOARD_CARD_ID>'"(mt/with-temp [:model/Card card {:name "A Card":dataset_query (mt/mbql-query venues {:limit 1})}diff --git a/test/metabase/channel/urls_test.clj b/test/metabase/channel/urls_test.cljindex 98e0940eea8..b7ba0f819f5 100644--- a/test/metabase/channel/urls_test.clj+++ b/test/metabase/channel/urls_test.clj@@ -37,3 +37,39 @@(testing "Filters slugs and values are encoded properly for the URL"(is (= "https://metabase.com/dashboard/1?%26=contains%3F"(urls/dashboard-url 1 [{:value "contains?", :slug "&"}]))))))++(deftest dashcard-url-test+ (mt/with-temporary-setting-values [site-url "https://metabase.com"]+ (testing "A valid dashcard URL can be generated without parameters"+ (is (= "https://metabase.com/dashboard/1#scrollTo=123"+ (urls/dashcard-url {:dashboard_id 1 :id 123}))))++ (testing "A valid dashcard URL can be generated with parameters"+ (binding [urls/*dashcard-parameters* [{:name "State"+ :slug "state"+ :id "63e719d0"+ :default ["CA" "NY"]+ :type "string/="+ :sectionId "location"}+ {:name "Quarter"+ :slug "quarter"+ :id "a6db3d8b"+ :default "Q1-2021"+ :type "date/quarter-year"+ :sectionId "date"}]]+ (is (= "https://metabase.com/dashboard/1?state=CA&state=NY&quarter=Q1-2021#scrollTo=123"+ (urls/dashcard-url {:dashboard_id 1 :id 123})))))++ (testing "A valid dashcard URL can be generated with tab ID"+ (is (= "https://metabase.com/dashboard/1?tab=5#scrollTo=123"+ (urls/dashcard-url {:dashboard_id 1 :id 123 :dashboard_tab_id 5}))))++ (testing "A valid dashcard URL can be generated with both parameters and tab ID"+ (binding [urls/*dashcard-parameters* [{:name "Category"+ :slug "category"+ :id "abc123"+ :default "Electronics"+ :type "string/="+ :sectionId "product"}]]+ (is (= "https://metabase.com/dashboard/1?tab=5&category=Electronics#scrollTo=123"+ (urls/dashcard-url {:dashboard_id 1 :id 123 :dashboard_tab_id 5})))))))diff --git a/test/metabase/pulse/dashboard_subscription_test.clj b/test/metabase/pulse/dashboard_subscription_test.cljindex bab2273b4b1..27a1c91b20b 100644--- a/test/metabase/pulse/dashboard_subscription_test.clj+++ b/test/metabase/pulse/dashboard_subscription_test.clj@@ -236,9 +236,14 @@slack-branding-text]}](apply concat(for [card-id card-ids]- [{:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "image" :slack_file {:id (format "%s.png" pulse.test-util/card-name)} :alt_text pulse.test-util/card-name}]))))+ (let [id (t2/select-one-pk :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ [{:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "image" :slack_file {:id (format "%s.png" pulse.test-util/card-name)} :alt_text pulse.test-util/card-name}])))));;; +----------------------------------------------------------------------------------------------------------------+;;; | Tests |@@ -392,18 +397,23 @@:slack(fn [{:keys [card-id dashboard-id]} [pulse-results]]- (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown is+ (let [id (t2/select-one-pk :model/DashboardCard :card_id card-id :dashboard_id dashboard-id)]+ (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown isconverted to mrkdwn (Slack markup language)"- (is (= {:channel "#general"- :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}- {:type "section"- :fields [{:type "mrkdwn" :text (format "<https://testmb.com/dashboard/%d|*Sent from Metabase Test by Rasta Toucan*>" dashboard-id)}- slack-branding-text]}- {:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "section" :text {:type "plain_text" :text "1,000"}}- {:type "section" :text {:type "mrkdwn" :text "*header*"}}]}- pulse-results))))}}))+ (is (= {:channel "#general"+ :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}+ {:type "section"+ :fields [{:type "mrkdwn" :text (format "<https://testmb.com/dashboard/%d|*Sent from Metabase Test by Rasta Toucan*>" dashboard-id)}+ slack-branding-text]}+ {:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "section" :text {:type "plain_text" :text "1,000"}}+ {:type "section" :text {:type "mrkdwn" :text "*header*"}}]}+ pulse-results)))))}}))(deftest virtual-card-heading-test(tests!@@ -431,18 +441,23 @@:slack(fn [{:keys [card-id dashboard-id]} [pulse-results]]- (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown isn't+ (let [id (t2/select-one-pk :model/DashboardCard :card_id card-id :dashboard_id dashboard-id)]+ (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown isn'tconverted to mrkdwn (Slack markup language)"- (is (= {:channel "#general"- :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}- {:type "section"- :fields [{:type "mrkdwn" :text (format "<https://testmb.com/dashboard/%d|*Sent from Metabase Test by Rasta Toucan*>" dashboard-id)}- slack-branding-text]}- {:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "section" :text {:type "plain_text" :text "1,000"}}- {:type "section" :text {:type "mrkdwn" :text "*# header, quote isn't escaped*"}}]}- pulse-results))))}}))+ (is (= {:channel "#general"+ :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}+ {:type "section"+ :fields [{:type "mrkdwn" :text (format "<https://testmb.com/dashboard/%d|*Sent from Metabase Test by Rasta Toucan*>" dashboard-id)}+ slack-branding-text]}+ {:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "section" :text {:type "plain_text" :text "1,000"}}+ {:type "section" :text {:type "mrkdwn" :text "*# header, quote isn't escaped*"}}]}+ pulse-results)))))}}))(deftest dashboard-filter-test(with-redefs [channel.slack/attachment-text-length-limit 15]@@ -468,23 +483,28 @@:slack(fn [{:keys [card-id dashboard-id]} [message]]- (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown is+ (let [{:keys [id]} (t2/select-one :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ (testing "Markdown cards are included in attachments list as :blocks sublists, and markdown isconverted to mrkdwn (Slack markup language) and truncated appropriately"- (is (= {:channel "#general"- :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}- {:type "section"- :fields [{:type "mrkdwn" :text "*State*\nCA, NY…"} {:type "mrkdwn" :text "*Quarter and Y…"}]}- {:type "section"- :fields- [{:type "mrkdwn"- :text- (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>"- dashboard-id)}- slack-branding-text]}- {:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "section" :text {:type "plain_text" :text "1,000"}}]}- message))))}})))+ (is (= {:channel "#general"+ :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}+ {:type "section"+ :fields [{:type "mrkdwn" :text "*State*\nCA, NY…"} {:type "mrkdwn" :text "*Quarter and Y…"}]}+ {:type "section"+ :fields+ [{:type "mrkdwn"+ :text+ (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>"+ dashboard-id)}+ slack-branding-text]}+ {:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "section" :text {:type "plain_text" :text "1,000"}}]}+ message)))))}})))(deftest dashboard-with-header-filters-test(tests!@@ -514,24 +534,29 @@:slack(fn [{:keys [card-id dashboard-id]} [message]]- (testing "Header card with inline parameters includes parameter values below header"- (is (= {:channel "#general"- :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}- {:type "section",- :fields [{:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}- {:type "section",- :fields [{:type "mrkdwn",- :text (str "<https://testmb.com/dashboard/"- dashboard-id- "?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>")}- slack-branding-text]}- {:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "section", :text {:type "plain_text", :text "1,000"}}- {:type "section",- :text {:type "mrkdwn", :text "*## Dashboard Header*"},- :fields [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}]}]}- message))))}}))+ (let [{:keys [id]} (t2/select-one :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ (testing "Header card with inline parameters includes parameter values below header"+ (is (= {:channel "#general"+ :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}+ {:type "section",+ :fields [{:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}+ {:type "section",+ :fields [{:type "mrkdwn",+ :text (str "<https://testmb.com/dashboard/"+ dashboard-id+ "?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>")}+ slack-branding-text]}+ {:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "section", :text {:type "plain_text", :text "1,000"}}+ {:type "section",+ :text {:type "mrkdwn", :text "*## Dashboard Header*"},+ :fields [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}]}]}+ message)))))}}))(deftest dashboard-with-dashcard-filters-test(tests!@@ -556,22 +581,27 @@:slack(fn [{:keys [card-id dashboard-id]} [message]]- (testing "Dashcard with inline parameters shows State parameter in dashboard fields"- (is (= {:channel "#general"- :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}- {:type "section",- :fields [{:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}- {:type "section",- :fields [{:type "mrkdwn",- :text (str "<https://testmb.com/dashboard/"- dashboard-id- "?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>")}- slack-branding-text]}- {:type "section",- :text {:type "mrkdwn", :text (format "<https://testmb.com/question/%d|Test card>" card-id), :verbatim true}}- {:type "section", :fields [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}]}- {:type "section", :text {:type "plain_text", :text "1,000"}}]}- message))))}}))+ (let [id (t2/select-one-pk :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ (testing "Dashcard with inline parameters shows State parameter in dashboard fields"+ (is (= {:channel "#general"+ :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}+ {:type "section",+ :fields [{:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}+ {:type "section",+ :fields [{:type "mrkdwn",+ :text (str "<https://testmb.com/dashboard/"+ dashboard-id+ "?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>")}+ slack-branding-text]}+ {:type "section",+ :text {:type "mrkdwn",+ :text (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021#scrollTo=%d|Test card>"+ dashboard-id+ id),+ :verbatim true}}+ {:type "section", :fields [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}]}+ {:type "section", :text {:type "plain_text", :text "1,000"}}]}+ message)))))}}))(deftest dashboard-with-link-card-test(tests!@@ -621,41 +651,47 @@vals)))):slack- (fn [_ [message]]- (is (=? {:channel "#general",- :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}- {:type "section",- :fields- [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}- {:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}- {:type "section", :fields [{:type "mrkdwn"- :text #"<https://testmb\.com/dashboard/\d+\?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021\|\*Sent from Metabase Test by Rasta Toucan\*>"}- slack-branding-text]}- {:type "section"- :text {:type "mrkdwn" :text #"<https://testmb\.com/question/\d+\|Test card>" :verbatim true}}- {:type "section", :text {:type "plain_text", :text "1,000"}}- {:type "section",- :text- {:type "mrkdwn",- :text #"\*<https://testmb\.com/collection/\d+\|Linked collection name>\*\nLinked collection desc"}}- {:type "section",- :text- {:type "mrkdwn", :text #"\*<https://testmb\.com/browse/\d+\|Linked database name>\*\nLinked database desc"}}- {:type "section",- :text- {:type "mrkdwn",- :text #"\*<https://testmb\.com/question\?db=\d+&table=\d+\|Linked table dname>\*\nLinked table desc"}}- {:type "section",- :text- {:type "mrkdwn",- :text #"\*<https://testmb\.com/dashboard/\d+\|Linked Dashboard name>\*\nLinked Dashboard desc"}}- {:type "section",- :text {:type "mrkdwn", :text #"\*<https://testmb\.com/question/\d+\|Linked card name>\*\nLinked card desc"}}- {:type "section",- :text- {:type "mrkdwn", :text #"\*<https://testmb\.com/question/\d+\|Linked model name>\*\nLinked model desc"}}- {:type "section", :text {:type "mrkdwn", :text "*<https://metabase.com|https://metabase.com>*"}}]}- message)))}}))+ (fn [{:keys [dashboard-id card-id]} [message]]+ (let [id (t2/select-one-pk :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ (is (=? {:channel "#general",+ :blocks [{:type "header", :text {:type "plain_text", :text "Aviary KPIs", :emoji true}}+ {:type "section",+ :fields+ [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}+ {:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}+ {:type "section", :fields [{:type "mrkdwn"+ :text #"<https://testmb\.com/dashboard/\d+\?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021\|\*Sent from Metabase Test by Rasta Toucan\*>"}+ slack-branding-text]}+ {:type "section"+ :text {:type "mrkdwn"++ :text (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021#scrollTo=%d|Test card>"+ dashboard-id+ id)+ :verbatim true}}+ {:type "section", :text {:type "plain_text", :text "1,000"}}+ {:type "section",+ :text+ {:type "mrkdwn",+ :text #"\*<https://testmb\.com/collection/\d+\|Linked collection name>\*\nLinked collection desc"}}+ {:type "section",+ :text+ {:type "mrkdwn", :text #"\*<https://testmb\.com/browse/\d+\|Linked database name>\*\nLinked database desc"}}+ {:type "section",+ :text+ {:type "mrkdwn",+ :text #"\*<https://testmb\.com/question\?db=\d+&table=\d+\|Linked table dname>\*\nLinked table desc"}}+ {:type "section",+ :text+ {:type "mrkdwn",+ :text #"\*<https://testmb\.com/dashboard/\d+\|Linked Dashboard name>\*\nLinked Dashboard desc"}}+ {:type "section",+ :text {:type "mrkdwn", :text #"\*<https://testmb\.com/question/\d+\|Linked card name>\*\nLinked card desc"}}+ {:type "section",+ :text+ {:type "mrkdwn", :text #"\*<https://testmb\.com/question/\d+\|Linked model name>\*\nLinked model desc"}}+ {:type "section", :text {:type "mrkdwn", :text "*<https://metabase.com|https://metabase.com>*"}}]}+ message))))}}))(deftest mrkdwn-length-limit-test(with-redefs [channel.slack/block-text-length-limit 10]@@ -1020,29 +1056,35 @@:slack(fn [{:keys [dashboard-id card-id]} [pulse-results]]- (is (=? {:channel "#general"- :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}- {:type "section"- :fields- [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}- {:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}- {:type "section"- :fields- [{:type "mrkdwn"- :text- (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>"- dashboard-id)}- slack-branding-text]}- {:type "section" :text {:type "mrkdwn" :text "*The first tab*"}}- {:type "section"- :text {:type "mrkdwn" :text (format "<https://testmb.com/question/%d|Test card>" card-id) :verbatim true}}- {:type "section" :text {:type "plain_text" :text "1,000"}}- {:type "section" :text {:type "mrkdwn" :text "Card 1 tab-1"}}- {:type "section" :text {:type "mrkdwn" :text "Card 2 tab-1"}}- {:type "section" :text {:type "mrkdwn" :text "*The second tab*"}}- {:type "section" :text {:type "mrkdwn" :text "Card 1 tab-2"}}- {:type "section" :text {:type "mrkdwn" :text "Card 2 tab-2"}}]}- (pulse.test-util/thunk->boolean pulse-results))))}}))+ (let [{:keys [dashboard_tab_id id]} (t2/select-one :model/DashboardCard :dashboard_id dashboard-id :card_id card-id)]+ (is (=? {:channel "#general"+ :blocks [{:type "header" :text {:type "plain_text" :text "Aviary KPIs" :emoji true}}+ {:type "section"+ :fields+ [{:type "mrkdwn", :text "*State*\nCA, NY, and NJ"}+ {:type "mrkdwn", :text "*Quarter and Year*\nQ1, 2021"}]}+ {:type "section"+ :fields+ [{:type "mrkdwn"+ :text+ (format "<https://testmb.com/dashboard/%d?state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021|*Sent from Metabase Test by Rasta Toucan*>"+ dashboard-id)}+ slack-branding-text]}+ {:type "section" :text {:type "mrkdwn" :text "*The first tab*"}}+ {:type "section"+ :text {:type "mrkdwn"+ :text (format "<https://testmb.com/dashboard/%d?tab=%d&state=CA&state=NY&state=NJ&quarter_and_year=Q1-2021#scrollTo=%d|Test card>"+ dashboard-id+ dashboard_tab_id+ id)+ :verbatim true}}+ {:type "section" :text {:type "plain_text" :text "1,000"}}+ {:type "section" :text {:type "mrkdwn" :text "Card 1 tab-1"}}+ {:type "section" :text {:type "mrkdwn" :text "Card 2 tab-1"}}+ {:type "section" :text {:type "mrkdwn" :text "*The second tab*"}}+ {:type "section" :text {:type "mrkdwn" :text "Card 1 tab-2"}}+ {:type "section" :text {:type "mrkdwn" :text "Card 2 tab-2"}}]}+ (pulse.test-util/thunk->boolean pulse-results)))))}}))(defn- result-attachment![part]