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
dad1ada1
Commit
dad1ada1
authored
Feb 04, 2021
by
jerasmus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display unload warning if MR edit changed
Display an unload warning if MR has been edited
parent
e8dae231
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
2 deletions
+82
-2
app/assets/javascripts/pages/projects/merge_requests/edit/check_form_state.js
...ts/pages/projects/merge_requests/edit/check_form_state.js
+24
-0
app/assets/javascripts/pages/projects/merge_requests/edit/index.js
...s/javascripts/pages/projects/merge_requests/edit/index.js
+5
-1
changelogs/unreleased/290622-display-warning-mr-edit.yml
changelogs/unreleased/290622-display-warning-mr-edit.yml
+5
-0
ee/app/assets/javascripts/approvals/components/mr_edit/mr_rules_hidden_inputs.vue
...s/approvals/components/mr_edit/mr_rules_hidden_inputs.vue
+3
-0
ee/app/assets/javascripts/pages/projects/merge_requests/shared/init_form.js
...scripts/pages/projects/merge_requests/shared/init_form.js
+4
-1
spec/frontend/pages/projects/merge_requests/edit/check_form_state_spec.js
...ges/projects/merge_requests/edit/check_form_state_spec.js
+41
-0
No files found.
app/assets/javascripts/pages/projects/merge_requests/edit/check_form_state.js
0 → 100644
View file @
dad1ada1
import
{
serializeForm
}
from
'
~/lib/utils/forms
'
;
const
findForm
=
()
=>
document
.
querySelector
(
'
.merge-request-form
'
);
const
serializeFormData
=
()
=>
JSON
.
stringify
(
serializeForm
(
findForm
()));
export
default
()
=>
{
const
oldFormData
=
serializeFormData
();
const
compareFormData
=
(
e
)
=>
{
const
newFormData
=
serializeFormData
();
if
(
oldFormData
!==
newFormData
)
{
e
.
preventDefault
();
// eslint-disable-next-line no-param-reassign
e
.
returnValue
=
''
;
// Chrome requires returnValue to be set
}
};
window
.
addEventListener
(
'
beforeunload
'
,
compareFormData
);
findForm
().
addEventListener
(
'
submit
'
,
()
=>
window
.
removeEventListener
(
'
beforeunload
'
,
compareFormData
),
);
};
app/assets/javascripts/pages/projects/merge_requests/edit/index.js
View file @
dad1ada1
import
initMergeRequest
from
'
~/pages/projects/merge_requests/init_merge_request
'
;
import
initCheckFormState
from
'
./check_form_state
'
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
initMergeRequest
);
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
initMergeRequest
();
initCheckFormState
();
});
changelogs/unreleased/290622-display-warning-mr-edit.yml
0 → 100644
View file @
dad1ada1
---
title
:
Display unload warning if MR edit changed
merge_request
:
53438
author
:
type
:
added
ee/app/assets/javascripts/approvals/components/mr_edit/mr_rules_hidden_inputs.vue
View file @
dad1ada1
...
...
@@ -23,6 +23,9 @@ export default {
fallbackApprovalsRequired
:
(
state
)
=>
state
.
approvals
.
fallbackApprovalsRequired
,
}),
},
mounted
()
{
this
.
$root
.
$emit
(
'
hidden-inputs-mounted
'
);
},
INPUT_ID
,
INPUT_SOURCE_ID
,
INPUT_NAME
,
...
...
ee/app/assets/javascripts/pages/projects/merge_requests/shared/init_form.js
View file @
dad1ada1
import
mountApprovals
from
'
ee/approvals/mount_mr_edit
'
;
import
mountBlockingMergeRequestsInput
from
'
ee/projects/merge_requests/blocking_mr_input
'
;
import
initCheckFormState
from
'
~/pages/projects/merge_requests/edit/check_form_state
'
;
export
default
()
=>
{
mountApprovals
(
document
.
getElementById
(
'
js-mr-approvals-input
'
));
const
editMrApp
=
mountApprovals
(
document
.
getElementById
(
'
js-mr-approvals-input
'
));
mountBlockingMergeRequestsInput
(
document
.
getElementById
(
'
js-blocking-merge-requests-input
'
));
editMrApp
.
$on
(
'
hidden-inputs-mounted
'
,
initCheckFormState
);
};
spec/frontend/pages/projects/merge_requests/edit/check_form_state_spec.js
0 → 100644
View file @
dad1ada1
import
initCheckFormState
from
'
~/pages/projects/merge_requests/edit/check_form_state
'
;
describe
(
'
Check form state
'
,
()
=>
{
const
findInput
=
()
=>
document
.
querySelector
(
'
#form-input
'
);
let
beforeUnloadEvent
;
let
setDialogContent
;
beforeEach
(()
=>
{
setFixtures
(
`
<form class="merge-request-form">
<input type="text" name="test" id="form-input"/>
</form>`
);
beforeUnloadEvent
=
new
Event
(
'
beforeunload
'
);
jest
.
spyOn
(
beforeUnloadEvent
,
'
preventDefault
'
);
setDialogContent
=
jest
.
spyOn
(
beforeUnloadEvent
,
'
returnValue
'
,
'
set
'
);
initCheckFormState
();
});
afterEach
(()
=>
{
beforeUnloadEvent
.
preventDefault
.
mockRestore
();
setDialogContent
.
mockRestore
();
});
it
(
'
shows confirmation dialog when there are unsaved changes
'
,
()
=>
{
findInput
().
value
=
'
value changed
'
;
window
.
dispatchEvent
(
beforeUnloadEvent
);
expect
(
beforeUnloadEvent
.
preventDefault
).
toHaveBeenCalled
();
expect
(
setDialogContent
).
toHaveBeenCalledWith
(
''
);
});
it
(
'
does not show confirmation dialog when there are no unsaved changes
'
,
()
=>
{
window
.
dispatchEvent
(
beforeUnloadEvent
);
expect
(
beforeUnloadEvent
.
preventDefault
).
not
.
toHaveBeenCalled
();
expect
(
setDialogContent
).
not
.
toHaveBeenCalled
();
});
});
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