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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
daabbaea
Commit
daabbaea
authored
Dec 17, 2019
by
Himanshu Kapoor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix "Discard" button in Web IDE does nothing
Discard button in Web IDE commits pane was broken.
parent
ae27abc9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
6 deletions
+114
-6
app/assets/javascripts/ide/components/commit_sidebar/editor_header.vue
...vascripts/ide/components/commit_sidebar/editor_header.vue
+26
-6
changelogs/unreleased/himkp-27242.yml
changelogs/unreleased/himkp-27242.yml
+5
-0
spec/frontend/ide/components/commit_sidebar/editor_header_spec.js
...ntend/ide/components/commit_sidebar/editor_header_spec.js
+83
-0
No files found.
app/assets/javascripts/ide/components/commit_sidebar/editor_header.vue
View file @
daabbaea
<
script
>
<
script
>
import
$
from
'
jquery
'
;
import
{
mapActions
}
from
'
vuex
'
;
import
{
mapActions
}
from
'
vuex
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
sprintf
,
__
}
from
'
~/locale
'
;
import
{
GlModal
}
from
'
@gitlab/ui
'
;
import
FileIcon
from
'
~/vue_shared/components/file_icon.vue
'
;
import
FileIcon
from
'
~/vue_shared/components/file_icon.vue
'
;
import
ChangedFileIcon
from
'
~/vue_shared/components/changed_file_icon.vue
'
;
import
ChangedFileIcon
from
'
~/vue_shared/components/changed_file_icon.vue
'
;
export
default
{
export
default
{
components
:
{
components
:
{
GlModal
,
FileIcon
,
FileIcon
,
ChangedFileIcon
,
ChangedFileIcon
,
},
},
...
@@ -17,7 +18,13 @@ export default {
...
@@ -17,7 +18,13 @@ export default {
},
},
},
},
computed
:
{
computed
:
{
activeButtonText
()
{
discardModalId
()
{
return
`discard-file-
${
this
.
activeFile
.
path
}
`
;
},
discardModalTitle
()
{
return
sprintf
(
__
(
'
Discard changes to %{path}?
'
),
{
path
:
this
.
activeFile
.
path
});
},
actionButtonText
()
{
return
this
.
activeFile
.
staged
?
__
(
'
Unstage
'
)
:
__
(
'
Stage
'
);
return
this
.
activeFile
.
staged
?
__
(
'
Unstage
'
)
:
__
(
'
Stage
'
);
},
},
isStaged
()
{
isStaged
()
{
...
@@ -25,7 +32,7 @@ export default {
...
@@ -25,7 +32,7 @@ export default {
},
},
},
},
methods
:
{
methods
:
{
...
mapActions
([
'
stageChange
'
,
'
unstageChange
'
]),
...
mapActions
([
'
stageChange
'
,
'
unstageChange
'
,
'
discardFileChanges
'
]),
actionButtonClicked
()
{
actionButtonClicked
()
{
if
(
this
.
activeFile
.
staged
)
{
if
(
this
.
activeFile
.
staged
)
{
this
.
unstageChange
(
this
.
activeFile
.
path
);
this
.
unstageChange
(
this
.
activeFile
.
path
);
...
@@ -34,7 +41,7 @@ export default {
...
@@ -34,7 +41,7 @@ export default {
}
}
},
},
showDiscardModal
()
{
showDiscardModal
()
{
$
(
document
.
getElementById
(
`discard-file-
${
this
.
activeFile
.
path
}
`
)).
modal
(
'
show
'
);
this
.
$refs
.
discardModal
.
show
(
);
},
},
},
},
};
};
...
@@ -53,6 +60,7 @@ export default {
...
@@ -53,6 +60,7 @@ export default {
<div
class=
"ml-auto"
>
<div
class=
"ml-auto"
>
<button
<button
v-if=
"!isStaged"
v-if=
"!isStaged"
ref=
"discardButton"
type=
"button"
type=
"button"
class=
"btn btn-remove btn-inverted append-right-8"
class=
"btn btn-remove btn-inverted append-right-8"
@
click=
"showDiscardModal"
@
click=
"showDiscardModal"
...
@@ -60,6 +68,7 @@ export default {
...
@@ -60,6 +68,7 @@ export default {
{{ __('Discard') }}
{{ __('Discard') }}
</button>
</button>
<button
<button
ref=
"actionButton"
:class=
"{
:class=
"{
'btn-success': !isStaged,
'btn-success': !isStaged,
'btn-warning': isStaged,
'btn-warning': isStaged,
...
@@ -68,8 +77,19 @@ export default {
...
@@ -68,8 +77,19 @@ export default {
class=
"btn btn-inverted"
class=
"btn btn-inverted"
@
click=
"actionButtonClicked"
@
click=
"actionButtonClicked"
>
>
{{ acti
ve
ButtonText }}
{{ acti
on
ButtonText }}
</button>
</button>
</div>
</div>
<gl-modal
ref=
"discardModal"
ok-variant=
"danger"
cancel-variant=
"light"
:ok-title=
"__('Discard changes')"
:modal-id=
"discardModalId"
:title=
"discardModalTitle"
@
ok=
"discardFileChanges(activeFile.path)"
>
{{ __("You will lose all changes you've made to this file. This action cannot be undone.") }}
</gl-modal>
</div>
</div>
</template>
</template>
changelogs/unreleased/himkp-27242.yml
0 → 100644
View file @
daabbaea
---
title
:
'
Fix
issue:
Discard
button
in
Web
IDE
does
nothing'
merge_request
:
21902
author
:
type
:
fixed
spec/frontend/ide/components/commit_sidebar/editor_header_spec.js
0 → 100644
View file @
daabbaea
import
Vuex
from
'
vuex
'
;
import
{
mount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
createStore
}
from
'
~/ide/stores
'
;
import
EditorHeader
from
'
~/ide/components/commit_sidebar/editor_header.vue
'
;
import
{
file
}
from
'
../../helpers
'
;
const
localVue
=
createLocalVue
();
localVue
.
use
(
Vuex
);
describe
(
'
IDE commit editor header
'
,
()
=>
{
let
wrapper
;
let
f
;
let
store
;
const
findDiscardModal
=
()
=>
wrapper
.
find
({
ref
:
'
discardModal
'
});
const
findDiscardButton
=
()
=>
wrapper
.
find
({
ref
:
'
discardButton
'
});
const
findActionButton
=
()
=>
wrapper
.
find
({
ref
:
'
actionButton
'
});
beforeEach
(()
=>
{
f
=
file
(
'
file
'
);
store
=
createStore
();
wrapper
=
mount
(
EditorHeader
,
{
store
,
localVue
,
sync
:
false
,
propsData
:
{
activeFile
:
f
,
},
});
jest
.
spyOn
(
wrapper
.
vm
,
'
stageChange
'
).
mockImplementation
();
jest
.
spyOn
(
wrapper
.
vm
,
'
unstageChange
'
).
mockImplementation
();
jest
.
spyOn
(
wrapper
.
vm
,
'
discardFileChanges
'
).
mockImplementation
();
});
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
});
it
(
'
renders button to discard & stage
'
,
()
=>
{
expect
(
wrapper
.
vm
.
$el
.
querySelectorAll
(
'
.btn
'
).
length
).
toBe
(
2
);
});
describe
(
'
discard button
'
,
()
=>
{
let
modal
;
beforeEach
(()
=>
{
modal
=
findDiscardModal
();
jest
.
spyOn
(
modal
.
vm
,
'
show
'
);
findDiscardButton
().
trigger
(
'
click
'
);
});
it
(
'
opens a dialog confirming discard
'
,
()
=>
{
expect
(
modal
.
vm
.
show
).
toHaveBeenCalled
();
});
it
(
'
calls discardFileChanges if dialog result is confirmed
'
,
()
=>
{
modal
.
vm
.
$emit
(
'
ok
'
);
expect
(
wrapper
.
vm
.
discardFileChanges
).
toHaveBeenCalledWith
(
f
.
path
);
});
});
describe
(
'
stage/unstage button
'
,
()
=>
{
it
(
'
unstages the file if it was already staged
'
,
()
=>
{
f
.
staged
=
true
;
findActionButton
().
trigger
(
'
click
'
);
expect
(
wrapper
.
vm
.
unstageChange
).
toHaveBeenCalledWith
(
f
.
path
);
});
it
(
'
stages the file if it was not staged
'
,
()
=>
{
findActionButton
().
trigger
(
'
click
'
);
expect
(
wrapper
.
vm
.
stageChange
).
toHaveBeenCalledWith
(
f
.
path
);
});
});
});
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