-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3863 from appirio-tech/feature/user_level_reports
Initial working draft for user level reports
- Loading branch information
Showing
9 changed files
with
251 additions
and
1 deletion.
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
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,34 @@ | ||
import { | ||
LOAD_USER_REPORTS, | ||
SET_LOOKER_SESSION_EXPIRED, | ||
} from '../../../config/constants' | ||
import { | ||
getUserReportUrl, | ||
} from '../../../api/projectReports' | ||
|
||
/** | ||
* Redux action to start fetching the signed URL for embeding the given report | ||
* @param {*} reportName unique name of the report | ||
*/ | ||
export function loadUserReportsUrls(reportName) { | ||
return (dispatch) => { | ||
return dispatch({ | ||
type: LOAD_USER_REPORTS, | ||
payload: getUserReportUrl(reportName), | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Redux action set the flag `lookerSessionExpired` | ||
* | ||
* @param {Boolean} isExpired true to indicate that looker session is expired | ||
*/ | ||
export function setLookerSessionExpired(isExpired) { | ||
return (dispatch) => { | ||
return dispatch({ | ||
type: SET_LOOKER_SESSION_EXPIRED, | ||
payload: { lookerSessionExpired: isExpired } | ||
}) | ||
} | ||
} |
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,125 @@ | ||
import React, { Component } from 'react' | ||
import MediaQuery from 'react-responsive' | ||
import Modal from 'react-modal' | ||
import Sticky from 'react-stickynode' | ||
import { connect } from 'react-redux' | ||
import { withRouter } from 'react-router-dom' | ||
import { loadUserReportsUrls, setLookerSessionExpired } from '../actions' | ||
import { SCREEN_BREAKPOINT_MD, PROJECT_REPORTS, REPORT_SESSION_LENGTH } from '../../../config/constants' | ||
import TwoColsLayout from '../../../components/TwoColsLayout' | ||
import UserSidebar from '../../../components/UserSidebar/UserSidebar' | ||
import spinnerWhileLoading from '../../../components/LoadingSpinner' | ||
|
||
const LookerEmbedReport = (props) => { | ||
return (<iframe width="100%" src={props.userReportsEmbedUrl} onLoad={props.onLoad} />) | ||
} | ||
|
||
const EnhancedLookerEmbedReport = spinnerWhileLoading(props => { | ||
return !props.isLoading | ||
})(LookerEmbedReport) | ||
|
||
class UserReportsContainer extends Component { | ||
constructor(props) { | ||
super(props) | ||
|
||
this.timer = null | ||
this.setLookerSessionTimer = this.setLookerSessionTimer.bind(this) | ||
this.reloadProjectReport = this.reloadProjectReport.bind(this) | ||
} | ||
|
||
reloadProjectReport() { | ||
this.props.loadUserReportsUrls(PROJECT_REPORTS.PROJECT_SUMMARY) | ||
// don't have to set session expire timer here, it would be set of iframe load | ||
} | ||
|
||
componentWillMount() { | ||
this.reloadProjectReport() | ||
// don't have to set session expire timer here, it would be set of iframe load | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.timer) { | ||
clearTimeout(this.timer) | ||
} | ||
} | ||
|
||
setLookerSessionTimer() { | ||
console.log('Setting Looker Session Timer') | ||
|
||
if (this.timer) { | ||
clearTimeout(this.timer) | ||
} | ||
|
||
// set timeout for raising alert to refresh the token when session expires | ||
this.timer = setTimeout(() => { | ||
console.log('Looker Session is expired by timer') | ||
this.props.setLookerSessionExpired(true) | ||
window.analytics && window.analytics.track('Looker Session Expired') | ||
}, REPORT_SESSION_LENGTH * 1000) | ||
} | ||
|
||
render() { | ||
const { user, isLoading, userReportsEmbedUrl, lookerSessionExpired } = this.props | ||
|
||
return ( | ||
<TwoColsLayout noPadding> | ||
<TwoColsLayout.Sidebar> | ||
<MediaQuery minWidth={SCREEN_BREAKPOINT_MD}> | ||
{(matches) => { | ||
if (matches) { | ||
return ( | ||
<Sticky top={60} bottomBoundary="#wrapper-main"> | ||
<UserSidebar user={user}/> | ||
</Sticky> | ||
) | ||
} else { | ||
return <UserSidebar user={user}/> | ||
} | ||
}} | ||
</MediaQuery> | ||
</TwoColsLayout.Sidebar> | ||
<TwoColsLayout.Content> | ||
<Modal | ||
isOpen={lookerSessionExpired && !isLoading} | ||
className="delete-post-dialog" | ||
overlayClassName="delete-post-dialog-overlay" | ||
contentLabel="" | ||
> | ||
<div className="modal-title"> | ||
Report sessions expired | ||
</div> | ||
|
||
<div className="modal-body"> | ||
To keep the data up to date, please, hit "Refresh" button to reload the report. | ||
</div> | ||
|
||
<div className="button-area flex center action-area"> | ||
<button className="tc-btn tc-btn-primary tc-btn-sm" onClick={this.reloadProjectReport}>Refresh</button> | ||
</div> | ||
</Modal> | ||
<EnhancedLookerEmbedReport | ||
isLoading={isLoading} | ||
userReportsEmbedUrl={userReportsEmbedUrl} | ||
onLoad={this.setLookerSessionTimer} | ||
/> | ||
</TwoColsLayout.Content> | ||
</TwoColsLayout> | ||
) | ||
} | ||
} | ||
const mapStateToProps = ({ loadUser, userReports }) => { | ||
|
||
return { | ||
user: loadUser.user, | ||
isLoading: userReports.isLoading, | ||
lookerSessionExpired: userReports.lookerSessionExpired, | ||
userReportsEmbedUrl: userReports.userReportsEmbedUrl, | ||
} | ||
} | ||
|
||
const mapDispatchToProps = { | ||
loadUserReportsUrls, | ||
setLookerSessionExpired, | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(UserReportsContainer)) |
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,51 @@ | ||
import { | ||
LOAD_USER_REPORTS_PENDING, | ||
LOAD_USER_REPORTS_SUCCESS, | ||
LOAD_USER_REPORTS_FAILURE, | ||
SET_LOOKER_SESSION_EXPIRED, | ||
} from '../../../config/constants' | ||
|
||
const initialState = { | ||
isLoading: false, | ||
error: false, | ||
userReports: null, | ||
userReportsEmbedUrl: null, | ||
lookerSessionExpired: false, | ||
} | ||
|
||
export const userReports = function (state=initialState, action) { | ||
const payload = action.payload | ||
|
||
switch (action.type) { | ||
case LOAD_USER_REPORTS_PENDING: | ||
return Object.assign({}, state, { | ||
isLoading: true, | ||
error: false, | ||
}) | ||
|
||
case LOAD_USER_REPORTS_SUCCESS: | ||
return Object.assign({}, state, { | ||
isLoading: false, | ||
error: false, | ||
userReportsEmbedUrl: payload, | ||
lookerSessionExpired: false, | ||
}) | ||
|
||
case LOAD_USER_REPORTS_FAILURE: { | ||
return Object.assign({}, state, { | ||
isLoading: false, | ||
error: payload | ||
}) | ||
} | ||
|
||
case SET_LOOKER_SESSION_EXPIRED: { | ||
return Object.assign({}, state, { | ||
lookerSessionExpired: payload | ||
}) | ||
} | ||
|
||
default: | ||
return state | ||
} | ||
} | ||
|
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,15 @@ | ||
/** | ||
* Settings routes | ||
*/ | ||
import React from 'react' | ||
import { Route } from 'react-router-dom' | ||
import { renderApp } from '../../components/App/App' | ||
import TopBarContainer from '../../components/TopBar/TopBarContainer' | ||
import ProjectsToolBar from '../../components/TopBar/ProjectsToolBar' | ||
import { requiresAuthentication } from '../../components/AuthenticatedComponent' | ||
import UserReportsContainer from './containers/UserReportsContainer' | ||
const UserReportsContainerWithAuth = requiresAuthentication(UserReportsContainer) | ||
export default [ | ||
<Route key="reports" exact path="/reports" render={renderApp(<TopBarContainer toolbar={ProjectsToolBar} />, <UserReportsContainerWithAuth />)} />, | ||
|
||
] |