-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added COP dashboards to highlight of the month
- Loading branch information
Showing
5 changed files
with
186 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
import { embedDashboard } from "@superset-ui/embedded-sdk"; | ||
|
||
|
||
const supersetUrl = 'https://dwhanalytics.kenyahmis.org' | ||
const supersetApiUrl = supersetUrl + '/api/v1/security' | ||
const dashboardId = "7aa9c6c5-2904-4d6f-87e3-9a36a0b51e6e" | ||
|
||
async function getToken() { | ||
|
||
//calling login to get access token | ||
const login_body = { | ||
"password": "admin", | ||
"provider": "db", | ||
"refresh": true, | ||
"username": "admin" | ||
}; | ||
|
||
const login_headers = { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
|
||
// console.log(supersetApiUrl + '/login') | ||
const { data } = await axios.post(supersetApiUrl + '/login', login_body, login_headers) | ||
const access_token = data['access_token'] | ||
// console.log(access_token) | ||
|
||
|
||
// Calling guest token | ||
const guest_token_body = { | ||
"resources": [ | ||
{ | ||
"type": "dashboard", | ||
"id": dashboardId, | ||
} | ||
], | ||
"rls": [], | ||
"user": { | ||
"username": "report-viewer", | ||
"first_name": "report-viewer", | ||
"last_name": "report-viewer", | ||
} | ||
}; | ||
|
||
const guest_token_headers = { | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": 'Bearer ' + access_token | ||
} | ||
} | ||
|
||
|
||
// console.log(supersetApiUrl + '/guest_token/') | ||
// console.log(guest_token_body) | ||
// console.log(guest_token_headers) | ||
await axios.post(supersetApiUrl + '/guest_token/', guest_token_body, guest_token_headers).then(dt=>{ | ||
// console.log(dt.data['token']) | ||
embedDashboard({ | ||
id: dashboardId, // given by the Superset embedding UI | ||
supersetDomain: supersetUrl, | ||
mountPoint: document.getElementById("superset-container"), // html element in which iframe render | ||
fetchGuestToken: () => dt.data['token'], | ||
dashboardUiConfig: { | ||
hideTitle: false, | ||
hideChartControls: true, | ||
hideTab: true, | ||
filters: { | ||
expanded: true, | ||
}, | ||
} | ||
}); | ||
}) | ||
|
||
var iframe = document.querySelector("iframe") | ||
if (iframe) { | ||
iframe.style.width = '100%'; // Set the width as needed | ||
iframe.style.minHeight = '100vw'; // Set the height as needed | ||
} | ||
|
||
} | ||
|
||
const HighlightCOP = () => { | ||
getToken() | ||
|
||
return ( | ||
<> | ||
<div id="superset-container"></div> | ||
</> | ||
) | ||
} | ||
|
||
export default HighlightCOP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect, useState } from 'react'; | ||
import axios from 'axios'; | ||
import { DWH_API_URL } from '../../constants'; | ||
|
||
const HighlightInternal = () => { | ||
const [iframeUrl, setIframeUrl] = useState(''); | ||
|
||
useEffect(() => { | ||
axios.get(`${DWH_API_URL}self-service/monthly-highlight`) | ||
.then(res => { | ||
const url = res.data?.url; | ||
setIframeUrl(url); | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching iframe URL:', error); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<iframe | ||
src={iframeUrl} | ||
frameBorder={0} | ||
width={'100%'} | ||
height={800} | ||
allowTransparency | ||
/> | ||
); | ||
} | ||
|
||
export default HighlightInternal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap'; | ||
import classnames from 'classnames'; | ||
import React, { useState } from 'react'; | ||
import Loadable from 'react-loadable'; | ||
import Loading from '../Shared/Loading'; | ||
import { LOADING_DELAY } from '../../constants'; | ||
const HighlightInternal = Loadable({ loader: () => import('./HighlightInternal'), loading: Loading, delay: LOADING_DELAY }); | ||
const HighlightCOP = Loadable({ loader: () => import('./HighlightCOP'), loading: Loading, delay: LOADING_DELAY }); | ||
|
||
|
||
const HighlightTabs = () => { | ||
|
||
const [activeTab, setActiveTab] = useState('cop'); | ||
|
||
return( | ||
<> | ||
<Nav tabs> | ||
<NavItem> | ||
<NavLink | ||
className={classnames({ | ||
active: activeTab === 'cop', | ||
})} | ||
onClick={() => { | ||
setActiveTab('cop'); | ||
}} | ||
> | ||
COMMUNITY DASHBOARDS | ||
</NavLink> | ||
</NavItem> | ||
<NavItem> | ||
<NavLink | ||
className={classnames({ | ||
active: activeTab === 'metabase', | ||
})} | ||
onClick={() => { | ||
setActiveTab('metabase'); | ||
}} | ||
> | ||
KENYAHMIS DASHBOARDS | ||
</NavLink> | ||
</NavItem> | ||
</Nav> | ||
<TabContent activeTab={activeTab}> | ||
<TabPane tabId="cop"> | ||
<HighlightCOP /> | ||
</TabPane> | ||
<TabPane tabId="metabase"> | ||
<HighlightInternal /> | ||
</TabPane> | ||
</TabContent> | ||
</> | ||
) | ||
} | ||
|
||
|
||
export default HighlightTabs |