Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
4154477c
Commit
4154477c
authored
Jul 26, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warn in IDE when user navigates away with staged changes
parent
88738408
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
11 deletions
+45
-11
app/assets/javascripts/ide/components/ide.vue
app/assets/javascripts/ide/components/ide.vue
+13
-11
changelogs/unreleased/ide-warn-staged-files.yml
changelogs/unreleased/ide-warn-staged-files.yml
+5
-0
spec/javascripts/ide/components/ide_spec.js
spec/javascripts/ide/components/ide_spec.js
+27
-0
No files found.
app/assets/javascripts/ide/components/ide.vue
View file @
4154477c
<
script
>
<
script
>
import
Mousetrap
from
'
mousetrap
'
;
import
Mousetrap
from
'
mousetrap
'
;
import
{
mapActions
,
mapState
,
mapGetters
}
from
'
vuex
'
;
import
{
mapActions
,
mapState
,
mapGetters
}
from
'
vuex
'
;
import
{
__
}
from
'
~/locale
'
;
import
NewModal
from
'
./new_dropdown/modal.vue
'
;
import
NewModal
from
'
./new_dropdown/modal.vue
'
;
import
IdeSidebar
from
'
./ide_side_bar.vue
'
;
import
IdeSidebar
from
'
./ide_side_bar.vue
'
;
import
RepoTabs
from
'
./repo_tabs.vue
'
;
import
RepoTabs
from
'
./repo_tabs.vue
'
;
...
@@ -25,7 +26,6 @@ export default {
...
@@ -25,7 +26,6 @@ export default {
},
},
computed
:
{
computed
:
{
...
mapState
([
...
mapState
([
'
changedFiles
'
,
'
openFiles
'
,
'
openFiles
'
,
'
viewer
'
,
'
viewer
'
,
'
currentMergeRequestId
'
,
'
currentMergeRequestId
'
,
...
@@ -34,18 +34,10 @@ export default {
...
@@ -34,18 +34,10 @@ export default {
'
currentProjectId
'
,
'
currentProjectId
'
,
'
errorMessage
'
,
'
errorMessage
'
,
]),
]),
...
mapGetters
([
'
activeFile
'
,
'
hasChanges
'
]),
...
mapGetters
([
'
activeFile
'
,
'
hasChanges
'
,
'
someUncommitedChanges
'
]),
},
},
mounted
()
{
mounted
()
{
const
returnValue
=
'
Are you sure you want to lose unsaved changes?
'
;
window
.
onbeforeunload
=
e
=>
this
.
onBeforeUnload
(
e
);
window
.
onbeforeunload
=
e
=>
{
if
(
!
this
.
changedFiles
.
length
)
return
undefined
;
Object
.
assign
(
e
,
{
returnValue
,
});
return
returnValue
;
};
Mousetrap
.
bind
([
'
t
'
,
'
command+p
'
,
'
ctrl+p
'
],
e
=>
{
Mousetrap
.
bind
([
'
t
'
,
'
command+p
'
,
'
ctrl+p
'
],
e
=>
{
if
(
e
.
preventDefault
)
{
if
(
e
.
preventDefault
)
{
...
@@ -59,6 +51,16 @@ export default {
...
@@ -59,6 +51,16 @@ export default {
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
toggleFileFinder
'
]),
...
mapActions
([
'
toggleFileFinder
'
]),
onBeforeUnload
(
e
=
{})
{
const
returnValue
=
__
(
'
Are you sure you want to lose unsaved changes?
'
);
if
(
!
this
.
someUncommitedChanges
)
return
undefined
;
Object
.
assign
(
e
,
{
returnValue
,
});
return
returnValue
;
},
mousetrapStopCallback
(
e
,
el
,
combo
)
{
mousetrapStopCallback
(
e
,
el
,
combo
)
{
if
(
if
(
(
combo
===
'
t
'
&&
el
.
classList
.
contains
(
'
dropdown-input-field
'
))
||
(
combo
===
'
t
'
&&
el
.
classList
.
contains
(
'
dropdown-input-field
'
))
||
...
...
changelogs/unreleased/ide-warn-staged-files.yml
0 → 100644
View file @
4154477c
---
title
:
Warn user when reload IDE with staged changes
merge_request
:
author
:
type
:
added
spec/javascripts/ide/components/ide_spec.js
View file @
4154477c
...
@@ -45,6 +45,33 @@ describe('ide component', () => {
...
@@ -45,6 +45,33 @@ describe('ide component', () => {
});
});
});
});
describe
(
'
onBeforeUnload
'
,
()
=>
{
it
(
'
returns undefined when no staged files or changed files
'
,
()
=>
{
expect
(
vm
.
onBeforeUnload
()).
toBe
(
undefined
);
});
it
(
'
returns warning text when their are changed files
'
,
()
=>
{
vm
.
$store
.
state
.
changedFiles
.
push
(
file
());
expect
(
vm
.
onBeforeUnload
()).
toBe
(
'
Are you sure you want to lose unsaved changes?
'
);
});
it
(
'
returns warning text when their are staged files
'
,
()
=>
{
vm
.
$store
.
state
.
stagedFiles
.
push
(
file
());
expect
(
vm
.
onBeforeUnload
()).
toBe
(
'
Are you sure you want to lose unsaved changes?
'
);
});
it
(
'
updates event object
'
,
()
=>
{
const
event
=
{};
vm
.
$store
.
state
.
stagedFiles
.
push
(
file
());
vm
.
onBeforeUnload
(
event
);
expect
(
event
.
returnValue
).
toBe
(
'
Are you sure you want to lose unsaved changes?
'
);
});
});
describe
(
'
file finder
'
,
()
=>
{
describe
(
'
file finder
'
,
()
=>
{
beforeEach
(
done
=>
{
beforeEach
(
done
=>
{
spyOn
(
vm
,
'
toggleFileFinder
'
);
spyOn
(
vm
,
'
toggleFileFinder
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment