File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/dashboard/Data/Browser Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -38,11 +38,30 @@ import subscribeTo from 'lib/subscribeTo';
38
38
import * as ColumnPreferences from 'lib/ColumnPreferences' ;
39
39
import * as ClassPreferences from 'lib/ClassPreferences' ;
40
40
import { Helmet } from 'react-helmet' ;
41
+ import { unstable_usePrompt as usePrompt , useBeforeUnload } from 'react-router-dom' ;
41
42
import generatePath from 'lib/generatePath' ;
42
43
import { withRouter } from 'lib/withRouter' ;
43
44
import { get } from 'lib/AJAX' ;
44
45
import BrowserFooter from './BrowserFooter.react' ;
45
46
47
+ function SelectedRowsNavigationPrompt ( { when } ) {
48
+ usePrompt ( {
49
+ when,
50
+ message : 'There are selected rows. Are you sure you want to leave this page?'
51
+ } ) ;
52
+ useBeforeUnload (
53
+ React . useCallback (
54
+ event => {
55
+ if ( when ) {
56
+ event . preventDefault ( ) ;
57
+ }
58
+ } ,
59
+ [ when ]
60
+ )
61
+ ) ;
62
+ return null ;
63
+ }
64
+
46
65
// The initial and max amount of rows fetched by lazy loading
47
66
const BROWSER_LAST_LOCATION = 'brower_last_location' ;
48
67
@@ -2446,6 +2465,9 @@ class Browser extends DashboardView {
2446
2465
< Helmet >
2447
2466
< title > { pageTitle } </ title >
2448
2467
</ Helmet >
2468
+ < SelectedRowsNavigationPrompt
2469
+ when = { Object . keys ( this . state . selection ) . length > 0 }
2470
+ />
2449
2471
{ browser }
2450
2472
{ notification }
2451
2473
{ extras }
You can’t perform that action at this time.
0 commit comments