-
Notifications
You must be signed in to change notification settings - Fork 136
Reporting initial work #3712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reporting initial work #3712
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,34 +9,66 @@ import { | |
| SCREEN_BREAKPOINT_MD, | ||
| PROJECT_FEED_TYPE_PRIMARY, | ||
| PROJECT_FEED_TYPE_MESSAGES, | ||
| PROJECT_REPORTS, | ||
| REPORT_SESSION_LENGTH, | ||
| } from '../../../config/constants' | ||
| import TwoColsLayout from '../../../components/TwoColsLayout' | ||
| import Sticky from '../../../components/Sticky' | ||
| import ProjectInfoContainer from './ProjectInfoContainer' | ||
| import PERMISSIONS from '../../../config/permissions' | ||
| import { checkPermission } from '../../../helpers/permissions' | ||
| import { loadProjectSummary } from '../../actions/projectReports' | ||
| import { loadProjectSummary, loadProjectReportsUrls, refreshLookerSession } from '../../actions/projectReports' | ||
| import spinnerWhileLoading from '../../../components/LoadingSpinner' | ||
| import ProjectSummaryReport from '../components/ProjectSummaryReport' | ||
|
|
||
| const EnhancedProjectSummaryReport = spinnerWhileLoading(props => { | ||
| return props.project && !props.isLoading && props.reportsProjectId === props.project.id | ||
| })(ProjectSummaryReport) | ||
| import './ProjectSummaryReportContainer.scss' | ||
|
|
||
| const LookerEmbedReport = (props) => { | ||
| return (<iframe width="100%" src={props.projectSummaryEmbedUrl} onLoad={props.onLoad} />) | ||
| } | ||
|
|
||
| const EnhancedLookerEmbedReport = spinnerWhileLoading(props => { | ||
| return !props.isLoading | ||
| })(LookerEmbedReport) | ||
|
|
||
| let timer | ||
|
|
||
| class ProjectSummaryReportContainer extends React.Component { | ||
|
|
||
| constructor(props) { | ||
| super(props) | ||
| this.setLookerSessionTimer = this.setLookerSessionTimer.bind(this) | ||
| } | ||
|
|
||
| componentWillUpdate(nextProps) { | ||
| const nextReportProjectId = _.get(nextProps, 'projectReports.projectId') | ||
| const nextReportProjectId = _.get(nextProps, 'reportsProjectId') | ||
| const nextProjectId = _.get(nextProps, 'project.id') | ||
| if(nextProps.project && nextReportProjectId !== nextProjectId) { | ||
| nextProps.loadProjectSummary(nextProps.project.id) | ||
| const lookerSessionExpired = !this.props.lookerSessionExpired && nextProps.lookerSessionExpired | ||
| if(lookerSessionExpired || (nextProjectId && nextReportProjectId !== nextProjectId)) { | ||
| nextProps.loadProjectReportsUrls(nextProjectId, PROJECT_REPORTS.PROJECT_SUMMARY) | ||
| this.setLookerSessionTimer() | ||
| } | ||
| } | ||
|
|
||
| setLookerSessionTimer() { | ||
| console.log('Setting Looker Session Timer') | ||
| if (timer) { | ||
| clearTimeout(timer) | ||
| } | ||
| const thisRef = this | ||
| let timeoutDuration = 60*1000 | ||
| if (REPORT_SESSION_LENGTH > 2*60) { | ||
| timeoutDuration = REPORT_SESSION_LENGTH*1000 - 2*60*1000 | ||
| } | ||
| // set timeout for raising alert to refresh the token 2 minutes before the session expire | ||
| timer = setTimeout(() => { | ||
| console.log('Calling refresh looker session action') | ||
| thisRef.props.refreshLookerSession() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hint: @vikasrohit fyi
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I always found the |
||
| }, (timeoutDuration)) | ||
| } | ||
|
|
||
| render() { | ||
| const { | ||
| project, | ||
| projectReports, | ||
| isSuperUser, | ||
| isManageUser, | ||
| currentMemberRole, | ||
|
|
@@ -45,11 +77,10 @@ class ProjectSummaryReportContainer extends React.Component { | |
| phases, | ||
| productsTimelines, | ||
| phasesTopics, | ||
| isProcessing, | ||
| isLoading, | ||
| location, | ||
| reportsProjectId, | ||
| projectSummaryEmbedUrl, | ||
| } = this.props | ||
| const projectSummary = _.get(projectReports, 'projectSummary') | ||
|
|
||
| const leftArea = ( | ||
| <ProjectInfoContainer | ||
|
|
@@ -64,7 +95,7 @@ class ProjectSummaryReportContainer extends React.Component { | |
| productsTimelines={productsTimelines} | ||
| phasesTopics={phasesTopics} | ||
| onChannelClick={this.onChannelClick} | ||
| isProjectProcessing={isProcessing} | ||
| isProjectProcessing={isLoading} | ||
| /> | ||
| ) | ||
|
|
||
|
|
@@ -82,29 +113,28 @@ class ProjectSummaryReportContainer extends React.Component { | |
| </MediaQuery> | ||
| </TwoColsLayout.Sidebar> | ||
| <TwoColsLayout.Content> | ||
| <EnhancedProjectSummaryReport | ||
| projectSummary={projectSummary} | ||
| isLoading={isProcessing} | ||
| reportsProjectId={reportsProjectId} | ||
| project={project} | ||
| /> | ||
| { | ||
| <EnhancedLookerEmbedReport | ||
| isLoading={isLoading} | ||
| projectSummaryEmbedUrl={projectSummaryEmbedUrl} | ||
| onLoad={this.setLookerSessionTimer} | ||
| /> | ||
| } | ||
| </TwoColsLayout.Content> | ||
|
|
||
| </TwoColsLayout> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ProjectSummaryReportContainer.propTypes = { | ||
| currentMemberRole: PT.string.isRequired, | ||
| isProcessing: PT.bool.isRequired, | ||
| isLoading: PT.bool.isRequired, | ||
| isSuperUser: PT.bool.isRequired, | ||
| isManageUser: PT.bool.isRequired, | ||
| project: PT.object.isRequired, | ||
| projectReports: PT.object.isRequired, | ||
| phases: PT.array.isRequired, | ||
| productsTimelines: PT.object.isRequired, | ||
| reportsProjectId: PT.number.isRequired, | ||
| reportsProjectId: PT.number, | ||
| } | ||
|
|
||
| const mapStateToProps = ({ projectState, projectTopics, phasesTopics, projectReports }) => { | ||
|
|
@@ -118,14 +148,17 @@ const mapStateToProps = ({ projectState, projectTopics, phasesTopics, projectRep | |
| phases: projectState.phases, | ||
| feeds: allFeed, | ||
| phasesTopics, | ||
| projectReports, | ||
| isProcessing: projectReports.isLoading, | ||
| isLoading: projectReports.isLoading, | ||
| reportsProjectId: projectReports.projectId, | ||
| lookerSessionExpired: projectReports.lookerSessionExpired, | ||
| projectSummaryEmbedUrl: projectReports.projectSummaryEmbedUrl, | ||
| } | ||
| } | ||
|
|
||
| const mapDispatchToProps = { | ||
| loadProjectSummary, | ||
| loadProjectReportsUrls, | ||
| refreshLookerSession, | ||
| } | ||
|
|
||
| export default connect(mapStateToProps, mapDispatchToProps)(withRouter(ProjectSummaryReportContainer)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| iframe { | ||
| height: calc(100vh - 60px); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, it's safer to keep
timerinside class likethis.timer. Otherwise, if we have 2 components on one page, they would use the sametimerand break each other.fyi @vikasrohit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I placed it intentionally outside because I do want to use the same time for all reporting components on the same page.
However, on second thought, I think we can move it to inside the class for better reading because I don't expect multiple copies of this component on the same page.