Skip to content

Commit 674c9ee

Browse files
simensma-freshsimensma-fresh
andauthored
[MDS-5402] Fixed metabase embeds not showing up on homepage (#2667)
[MDS-5402] Fix embed of dashboard metabase questions Co-authored-by: simensma-fresh <[email protected]>
1 parent 16eede4 commit 674c9ee

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

services/core-api/app/api/reporting/namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
api = Namespace('reporting', description='Authenticated reports')
66

7-
api.add_resource(MetabaseDashboardResource, '/dashboard/<int:id>')
7+
api.add_resource(MetabaseDashboardResource, '/<string:type>/<int:id>')

services/core-api/app/api/reporting/resources/metabase.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,28 @@
88
from app.api.utils.resources_mixins import UserMixin
99
from app.api.utils.search import search_targets, append_result, execute_search, SearchResult
1010
from app.api.search.response_models import SEARCH_RESULT_RETURN_MODEL
11-
11+
from werkzeug.exceptions import BadRequest
1212

1313
class MetabaseDashboardResource(Resource, UserMixin):
14-
def get(self, id):
15-
payload = {"resource": {"dashboard": id}, "params": {}}
14+
15+
@api.doc(
16+
description='Generates an embeddable link to a Metabase dashboard or question',
17+
params={
18+
'type': 'Type of resource to embed (dashboard/question)',
19+
'id': 'Metabase id of resource to embed'
20+
}
21+
)
22+
def get(self, type, id):
23+
if type not in ('dashboard', 'question'):
24+
raise BadRequest('Type must be dashboard or question')
25+
26+
payload = {"resource": {}, "params": {}}
27+
payload["resource"][type] = id
28+
1629
token = jwt.encode(payload,
1730
current_app.config['METABASE_EMBEDDING_SECRET_KEY'],
1831
algorithm="HS256")
1932

2033
dashboard_url = current_app.config[
21-
'METABASE_SITE_URL'] + "/embed/dashboard/" + token.decode("utf8")
34+
'METABASE_SITE_URL'] + f'/embed/{type}/' + token.decode("utf8")
2235
return {'dashboard_url': dashboard_url}

services/core-web/common/actionCreators/reportingActionCreator.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { createRequestHeader } from "../utils/RequestHeaders";
66
import CustomAxios from "../customAxios";
77

88
// This file is anticipated to have multiple exports
9-
// eslint-disable-next-line import/prefer-default-export
10-
export const fetchMetabaseDashboard = (dashboardId) =>
9+
export const fetchMetabaseDashboard = (dashboardId, type = "dashboard") =>
1110
CustomAxios({ errorToastMessage: "Unable to fetch dashboard." })
12-
.get(`${ENVIRONMENT.apiUrl + API.DASHBOARD(dashboardId)}`, createRequestHeader())
11+
.get(`${ENVIRONMENT.apiUrl + API.DASHBOARD(dashboardId, type)}`, createRequestHeader())
1312
.then((response) => {
1413
const { dashboard_url } = response.data || {};
1514
return dashboard_url;

services/core-web/common/constants/API.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const SEARCH_OPTIONS = "/search/options";
110110
export const SIMPLE_SEARCH = "/search/simple";
111111

112112
// Reporting
113-
export const DASHBOARD = (dashboardId) => `/reporting/dashboard/${dashboardId}`;
113+
export const DASHBOARD = (dashboardId, type = "dashboard") => `/reporting/${type}/${dashboardId}`;
114114

115115
// Variances
116116
export const COMPLIANCE_CODES = "/compliance/codes";

services/core-web/src/components/homepage/HomeInfographs.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const HomeInfographs = () => {
1010

1111
useEffect(() => {
1212
(async () => {
13-
const newGraphUrls = await Promise.all(graphIds.map((id) => fetchMetabaseDashboard(id)));
13+
const newGraphUrls = await Promise.all(
14+
graphIds.map((id) => fetchMetabaseDashboard(id, "question"))
15+
);
1416
setInfographUrls(newGraphUrls);
1517
})();
1618
}, []);

services/minespace-web/common/actionCreators/reportingActionCreator.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { createRequestHeader } from "../utils/RequestHeaders";
66
import CustomAxios from "../customAxios";
77

88
// This file is anticipated to have multiple exports
9-
// eslint-disable-next-line import/prefer-default-export
10-
export const fetchMetabaseDashboard = (dashboardId) =>
9+
export const fetchMetabaseDashboard = (dashboardId, type = "dashboard") =>
1110
CustomAxios({ errorToastMessage: "Unable to fetch dashboard." })
12-
.get(`${ENVIRONMENT.apiUrl + API.DASHBOARD(dashboardId)}`, createRequestHeader())
11+
.get(`${ENVIRONMENT.apiUrl + API.DASHBOARD(dashboardId, type)}`, createRequestHeader())
1312
.then((response) => {
1413
const { dashboard_url } = response.data || {};
1514
return dashboard_url;

services/minespace-web/common/constants/API.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const SEARCH_OPTIONS = "/search/options";
110110
export const SIMPLE_SEARCH = "/search/simple";
111111

112112
// Reporting
113-
export const DASHBOARD = (dashboardId) => `/reporting/dashboard/${dashboardId}`;
113+
export const DASHBOARD = (dashboardId, type = "dashboard") => `/reporting/${type}/${dashboardId}`;
114114

115115
// Variances
116116
export const COMPLIANCE_CODES = "/compliance/codes";

0 commit comments

Comments
 (0)