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
6e2f2539
Commit
6e2f2539
authored
Oct 19, 2021
by
indigane
Committed by
Phil Hughes
Oct 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix merge request dropdown branch input not detecting changes, also racing issues
parent
a1ce1804
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
7 deletions
+38
-7
app/assets/javascripts/create_merge_request_dropdown.js
app/assets/javascripts/create_merge_request_dropdown.js
+34
-6
spec/frontend/create_merge_request_dropdown_spec.js
spec/frontend/create_merge_request_dropdown_spec.js
+4
-1
No files found.
app/assets/javascripts/create_merge_request_dropdown.js
View file @
6e2f2539
...
...
@@ -54,6 +54,7 @@ export default class CreateMergeRequestDropdown {
this
.
isCreatingBranch
=
false
;
this
.
isCreatingMergeRequest
=
false
;
this
.
isGettingRef
=
false
;
this
.
refCancelToken
=
null
;
this
.
mergeRequestCreated
=
false
;
this
.
refDebounce
=
debounce
((
value
,
target
)
=>
this
.
getRef
(
value
,
target
),
500
);
this
.
refIsValid
=
true
;
...
...
@@ -101,9 +102,18 @@ export default class CreateMergeRequestDropdown {
'
click
'
,
this
.
onClickCreateMergeRequestButton
.
bind
(
this
),
);
this
.
branchInput
.
addEventListener
(
'
input
'
,
this
.
onChangeInput
.
bind
(
this
));
this
.
branchInput
.
addEventListener
(
'
keyup
'
,
this
.
onChangeInput
.
bind
(
this
));
this
.
dropdownToggle
.
addEventListener
(
'
click
'
,
this
.
onClickSetFocusOnBranchNameInput
.
bind
(
this
));
// Detect for example when user pastes ref using the mouse
this
.
refInput
.
addEventListener
(
'
input
'
,
this
.
onChangeInput
.
bind
(
this
));
// Detect for example when user presses right arrow to apply the suggested ref
this
.
refInput
.
addEventListener
(
'
keyup
'
,
this
.
onChangeInput
.
bind
(
this
));
// Detect when user clicks inside the input to apply the suggested ref
this
.
refInput
.
addEventListener
(
'
click
'
,
this
.
onChangeInput
.
bind
(
this
));
// Detect when user clicks outside the input to apply the suggested ref
this
.
refInput
.
addEventListener
(
'
blur
'
,
this
.
onChangeInput
.
bind
(
this
));
// Detect when user presses tab to apply the suggested ref
this
.
refInput
.
addEventListener
(
'
keydown
'
,
CreateMergeRequestDropdown
.
processTab
.
bind
(
this
));
}
...
...
@@ -247,8 +257,12 @@ export default class CreateMergeRequestDropdown {
getRef
(
ref
,
target
=
'
all
'
)
{
if
(
!
ref
)
return
false
;
this
.
refCancelToken
=
axios
.
CancelToken
.
source
();
return
axios
.
get
(
`
${
createEndpoint
(
this
.
projectPath
,
this
.
refsPath
)}${
encodeURIComponent
(
ref
)}
`
)
.
get
(
`
${
createEndpoint
(
this
.
projectPath
,
this
.
refsPath
)}${
encodeURIComponent
(
ref
)}
`
,
{
cancelToken
:
this
.
refCancelToken
.
token
,
})
.
then
(({
data
})
=>
{
const
branches
=
data
[
Object
.
keys
(
data
)[
0
]];
const
tags
=
data
[
Object
.
keys
(
data
)[
1
]];
...
...
@@ -267,7 +281,10 @@ export default class CreateMergeRequestDropdown {
return
this
.
updateInputState
(
target
,
ref
,
result
);
})
.
catch
(()
=>
{
.
catch
((
thrown
)
=>
{
if
(
axios
.
isCancel
(
thrown
))
{
return
false
;
}
this
.
unavailable
();
this
.
disable
();
createFlash
({
...
...
@@ -325,14 +342,23 @@ export default class CreateMergeRequestDropdown {
let
target
;
let
value
;
// User changed input, cancel to prevent previous request from interfering
if
(
this
.
refCancelToken
!==
null
)
{
this
.
refCancelToken
.
cancel
();
}
if
(
event
.
target
===
this
.
branchInput
)
{
target
=
'
branch
'
;
({
value
}
=
this
.
branchInput
);
}
else
if
(
event
.
target
===
this
.
refInput
)
{
target
=
'
ref
'
;
value
=
event
.
target
.
value
.
slice
(
0
,
event
.
target
.
selectionStart
)
+
event
.
target
.
value
.
slice
(
event
.
target
.
selectionEnd
);
if
(
event
.
target
===
document
.
activeElement
)
{
value
=
event
.
target
.
value
.
slice
(
0
,
event
.
target
.
selectionStart
)
+
event
.
target
.
value
.
slice
(
event
.
target
.
selectionEnd
);
}
else
{
value
=
event
.
target
.
value
;
}
}
else
{
return
false
;
}
...
...
@@ -358,6 +384,7 @@ export default class CreateMergeRequestDropdown {
this
.
enable
();
this
.
showAvailableMessage
(
target
);
this
.
refDebounce
(
value
,
target
);
return
true
;
}
...
...
@@ -414,7 +441,8 @@ export default class CreateMergeRequestDropdown {
if
(
!
selectedText
||
this
.
refInput
.
dataset
.
value
===
this
.
suggestedRef
)
return
;
event
.
preventDefault
();
window
.
getSelection
().
removeAllRanges
();
const
caretPositionEnd
=
this
.
refInput
.
value
.
length
;
this
.
refInput
.
setSelectionRange
(
caretPositionEnd
,
caretPositionEnd
);
}
removeMessage
(
target
)
{
...
...
spec/frontend/create_merge_request_dropdown_spec.js
View file @
6e2f2539
...
...
@@ -46,7 +46,10 @@ describe('CreateMergeRequestDropdown', () => {
dropdown
.
getRef
(
'
contains#hash
'
)
.
then
(()
=>
{
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
endpoint
);
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
endpoint
,
expect
.
objectContaining
({
cancelToken
:
expect
.
anything
()
}),
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
...
...
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