@@ -4,6 +4,7 @@ import PT from 'prop-types'
44import { connect } from 'react-redux'
55import { withRouter } from 'react-router-dom'
66import MediaQuery from 'react-responsive'
7+ import Modal from 'react-modal'
78
89import {
910 SCREEN_BREAKPOINT_MD ,
@@ -17,7 +18,7 @@ import Sticky from '../../../components/Sticky'
1718import ProjectInfoContainer from './ProjectInfoContainer'
1819import PERMISSIONS from '../../../config/permissions'
1920import { checkPermission } from '../../../helpers/permissions'
20- import { loadProjectSummary , loadProjectReportsUrls , refreshLookerSession } from '../../actions/projectReports'
21+ import { loadProjectReportsUrls , setLookerSessionExpired } from '../../actions/projectReports'
2122import spinnerWhileLoading from '../../../components/LoadingSpinner'
2223
2324import './ProjectSummaryReportContainer.scss'
@@ -34,34 +35,60 @@ class ProjectSummaryReportContainer extends React.Component {
3435
3536 constructor ( props ) {
3637 super ( props )
38+
39+ this . state = {
40+ iframeKey : 0 , // we would use it to force iframe to reload
41+ }
3742 this . timer = null
3843 this . setLookerSessionTimer = this . setLookerSessionTimer . bind ( this )
44+ this . reloadProjectReport = this . reloadProjectReport . bind ( this )
45+ }
46+
47+ reloadProjectReport ( ) {
48+ this . props . loadProjectReportsUrls ( _ . get ( this . props , 'project.id' ) , PROJECT_REPORTS . PROJECT_SUMMARY )
49+ // don't have to set session expire timer here, it would be set of iframe load
50+ }
51+
52+ componentWillMount ( ) {
53+ this . reloadProjectReport ( )
54+ // don't have to set session expire timer here, it would be set of iframe load
55+ }
56+
57+ componentWillUnmount ( ) {
58+ if ( this . timer ) {
59+ clearTimeout ( this . timer )
60+ }
3961 }
4062
4163 componentWillUpdate ( nextProps ) {
4264 const nextReportProjectId = _ . get ( nextProps , 'reportsProjectId' )
4365 const nextProjectId = _ . get ( nextProps , 'project.id' )
44- const lookerSessionExpired = ! this . props . lookerSessionExpired && nextProps . lookerSessionExpired
45- if ( lookerSessionExpired || ( nextProjectId && nextReportProjectId !== nextProjectId ) ) {
46- nextProps . loadProjectReportsUrls ( nextProjectId , PROJECT_REPORTS . PROJECT_SUMMARY )
47- this . setLookerSessionTimer ( )
66+
67+ if ( nextProjectId && nextReportProjectId !== nextProjectId ) {
68+ this . props . loadProjectReportsUrls ( nextProjectId , PROJECT_REPORTS . PROJECT_SUMMARY )
69+ // don't have to set session expire timer here, it would be set of iframe load
70+ }
71+
72+ // when we get a new URL for report, force iframe to reload, in case the URL stays the same
73+ if ( this . props . isLoading && ! nextProps . isLoading ) {
74+ this . setState ( {
75+ iframeKey : this . state . iframeKey + 1
76+ } )
4877 }
4978 }
5079
5180 setLookerSessionTimer ( ) {
5281 console . log ( 'Setting Looker Session Timer' )
82+
5383 if ( this . timer ) {
5484 clearTimeout ( this . timer )
5585 }
56- let timeoutDuration = 60 * 1000
57- if ( REPORT_SESSION_LENGTH > 2 * 60 ) {
58- timeoutDuration = REPORT_SESSION_LENGTH * 1000 - 2 * 60 * 1000
59- }
60- // set timeout for raising alert to refresh the token 2 minutes before the session expire
86+
87+ // set timeout for raising alert to refresh the token when session expires
6188 this . timer = setTimeout ( ( ) => {
62- console . log ( 'Calling refresh looker session action ' )
63- this . props . refreshLookerSession ( )
64- } , ( timeoutDuration ) )
89+ console . log ( 'Looker Session is expired by timer ' )
90+ this . props . setLookerSessionExpired ( true )
91+ } , REPORT_SESSION_LENGTH * 1000 )
6592 }
6693
6794 render ( ) {
@@ -78,6 +105,7 @@ class ProjectSummaryReportContainer extends React.Component {
78105 isLoading,
79106 location,
80107 projectSummaryEmbedUrl,
108+ lookerSessionExpired,
81109 } = this . props
82110
83111 const leftArea = (
@@ -111,13 +139,30 @@ class ProjectSummaryReportContainer extends React.Component {
111139 </ MediaQuery >
112140 </ TwoColsLayout . Sidebar >
113141 < TwoColsLayout . Content >
114- {
115- < EnhancedLookerEmbedReport
116- isLoading = { isLoading }
117- projectSummaryEmbedUrl = { projectSummaryEmbedUrl }
118- onLoad = { this . setLookerSessionTimer }
119- />
120- }
142+ < Modal
143+ isOpen = { lookerSessionExpired && ! isLoading }
144+ className = "delete-post-dialog"
145+ overlayClassName = "delete-post-dialog-overlay"
146+ contentLabel = ""
147+ >
148+ < div className = "modal-title" >
149+ Report sessions expired
150+ </ div >
151+
152+ < div className = "modal-body" >
153+ To keep the data up to date, please, hit "Refresh" button to reload the report.
154+ </ div >
155+
156+ < div className = "button-area flex center action-area" >
157+ < button className = "tc-btn tc-btn-primary tc-btn-sm" onClick = { this . reloadProjectReport } > Refresh</ button >
158+ </ div >
159+ </ Modal >
160+ < EnhancedLookerEmbedReport
161+ key = { this . state . iframeKey }
162+ isLoading = { isLoading }
163+ projectSummaryEmbedUrl = { projectSummaryEmbedUrl }
164+ onLoad = { this . setLookerSessionTimer }
165+ />
121166 </ TwoColsLayout . Content >
122167 </ TwoColsLayout >
123168 )
@@ -154,9 +199,8 @@ const mapStateToProps = ({ projectState, projectTopics, phasesTopics, projectRep
154199}
155200
156201const mapDispatchToProps = {
157- loadProjectSummary,
158202 loadProjectReportsUrls,
159- refreshLookerSession ,
203+ setLookerSessionExpired ,
160204}
161205
162206export default connect ( mapStateToProps , mapDispatchToProps ) ( withRouter ( ProjectSummaryReportContainer ) )
0 commit comments