5
5
JupyterFrontEndPlugin
6
6
} from '@jupyterlab/application' ;
7
7
8
- import { showDialog } from '@jupyterlab/apputils' ;
8
+ import { showDialog , Dialog } from '@jupyterlab/apputils' ;
9
9
10
10
import { DocumentWidget } from '@jupyterlab/docregistry' ;
11
11
@@ -17,7 +17,16 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';
17
17
* A session expiration body
18
18
*/
19
19
export const SessionExpBody = ( ) => {
20
- return < > { 'Session is expiring, click OK to refresh login' } </ > ;
20
+ return (
21
+ < div >
22
+ < p >
23
+ Your session is about to expire. We saved your notebooks, so your work
24
+ won't be lost.
25
+ </ p >
26
+ < br > </ br >
27
+ < p > Please re-login to continue using Data Studio Notebooks.</ p >
28
+ </ div >
29
+ ) ;
21
30
} ;
22
31
23
32
function readCookie ( name : string ) {
@@ -56,6 +65,7 @@ export const SessionExpPlugin: JupyterFrontEndPlugin<void> = {
56
65
57
66
// Get the expiration from the login cookie.
58
67
let obj = readCookie ( loginCookie ) ;
68
+
59
69
let expires : number ;
60
70
if ( ! obj ) {
61
71
console . log ( `Login cookie ${ loginCookie } not found` ) ;
@@ -64,13 +74,26 @@ export const SessionExpPlugin: JupyterFrontEndPlugin<void> = {
64
74
expires = parseFloat ( obj ) ;
65
75
}
66
76
67
- // Set the callback time to "sessionWarningMinutes" before expiration, all times are in msec.
68
- let callbackTime =
69
- expires * 24 * 60 * 60 * 1000 - sessionWarningMinutes * 60 * 1000 ;
77
+ // Time since Epoch (in milliseconds).
78
+ let currentTime = Date . now ( ) ;
79
+ let secondsUntilExpiration = expires - currentTime ;
80
+ let twentyMinutesAsMilliseconds = sessionWarningMinutes * 60 * 1000 ;
81
+ let reloginTimeout = secondsUntilExpiration - twentyMinutesAsMilliseconds ;
82
+ let reloginMinutes = reloginTimeout / 1000 / 60 ;
83
+ let reloginSeconds = ( ( reloginTimeout / 1000 / 60 ) % 1 ) * 60 ;
84
+
85
+ // Write a human-readable statement about the expiration time to the console.
86
+ console . log (
87
+ 'This Data Studio Notebooks Session expires in: ' +
88
+ Math . trunc ( reloginMinutes ) +
89
+ ' minutes and ' +
90
+ Math . round ( reloginSeconds ) +
91
+ ' seconds'
92
+ ) ;
70
93
71
- callbackTime = Math . max ( callbackTime , 1000 ) ;
94
+ reloginTimeout = Math . max ( reloginTimeout , 1000 ) ;
72
95
if ( PageConfig . getOption ( 'sessionWarningOverride' ) === 'true' ) {
73
- callbackTime = 0 ;
96
+ reloginTimeout = 0 ;
74
97
}
75
98
76
99
setTimeout ( async ( ) => {
@@ -87,8 +110,14 @@ export const SessionExpPlugin: JupyterFrontEndPlugin<void> = {
87
110
88
111
// Prompt the user to login.
89
112
const result = await showDialog ( {
90
- title : 'Session Expiring' ,
91
- body : SessionExpBody ( )
113
+ title : 'Session is expiring.' ,
114
+ body : SessionExpBody ( ) ,
115
+ buttons : [
116
+ Dialog . okButton ( {
117
+ label : 'Re-login' ,
118
+ displayType : 'default'
119
+ } )
120
+ ]
92
121
} ) ;
93
122
if ( ! result . button . accept ) {
94
123
return ;
@@ -99,6 +128,6 @@ export const SessionExpPlugin: JupyterFrontEndPlugin<void> = {
99
128
await fetch ( URLExt . join ( baseUrl , 'logout' ) ) ;
100
129
const url = URLExt . join ( baseUrl , 'login' ) ;
101
130
window . location . replace ( url ) ;
102
- } , callbackTime ) ;
131
+ } , reloginTimeout ) ;
103
132
}
104
133
} ;
0 commit comments