Skip to content

Commit 2b608e7

Browse files
committed
enhance(repo): move commit_form to modal and commit action buttons above editor.
1 parent 5df4956 commit 2b608e7

File tree

8 files changed

+291
-28
lines changed

8 files changed

+291
-28
lines changed

templates/repo/editor/commit_form.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@
8080
{{end}}
8181
</div>
8282
<input type="hidden" name="last_commit" value="{{.last_commit}}">
83-
<button id="commit-button" type="submit" class="ui primary button">
84-
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
85-
</button>
86-
<a class="ui button red" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
83+
<div class="tw-text-right tw-mt-4">
84+
<button id="commit-button" type="submit" class="ui primary button">
85+
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
86+
</button>
87+
</div>
8788
</div>

templates/repo/editor/edit.tmpl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
>
1515
{{.CsrfTokenHtml}}
1616
{{template "repo/editor/common_top" .}}
17-
<div class="repo-editor-header tw-flex tw-items-center tw-gap-2">
18-
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
19-
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
20-
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
21-
{{svg "octicon-sidebar-collapse"}}
22-
</button>
23-
{{template "repo/editor/common_breadcrumb" .}}
17+
<div class="repo-editor-header tw-flex tw-items-center tw-justify-between tw-gap-2">
18+
<div class="tw-flex tw-items-center tw-gap-2">
19+
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
20+
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
21+
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
22+
{{svg "octicon-sidebar-collapse"}}
23+
</button>
24+
{{template "repo/editor/common_breadcrumb" .}}
25+
</div>
26+
<div class="tw-flex tw-gap-2">
27+
<a class="ui red button" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
28+
<button type="button" class="ui primary button disabled" id="commit-changes-button">
29+
{{ctx.Locale.Tr "repo.editor.commit_changes"}}
30+
</button>
31+
</div>
2432
</div>
2533
{{if not .NotEditableReason}}
2634
<div class="field">
@@ -56,10 +64,22 @@
5664
</div>
5765
</div>
5866
{{end}}
59-
{{template "repo/editor/commit_form" .}}
67+
{{/* Commit form fields - inside form but hidden, will be shown in modal */}}
68+
<div id="commit-form-fields" style="display: none;">
69+
{{template "repo/editor/commit_form" .}}
70+
</div>
71+
{{/* Hidden dummy button for repo-editor.ts compatibility */}}
72+
<button id="commit-button" type="button" style="display: none;"></button>
6073
</form>
6174
</div>
6275
</div>
6376
</div>
77+
78+
{{/* Commit Changes Modal - fields will be moved here visually */}}
79+
<div class="ui modal" id="commit-changes-modal">
80+
<i class="close icon"></i>
81+
<div class="content" id="commit-modal-content">
82+
</div>
83+
</div>
6484
</div>
6585
{{template "base/footer" .}}

templates/repo/editor/patch.tmpl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@
1414
>
1515
{{.CsrfTokenHtml}}
1616
{{template "repo/editor/common_top" .}}
17-
<div class="repo-editor-header tw-flex tw-items-center tw-gap-2">
18-
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
19-
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
20-
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
21-
{{svg "octicon-sidebar-collapse"}}
22-
</button>
23-
<div class="breadcrumb">
17+
<div class="repo-editor-header tw-flex tw-items-center tw-justify-between tw-gap-2">
18+
<div class="tw-flex tw-items-center tw-gap-2">
19+
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
20+
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
21+
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
22+
{{svg "octicon-sidebar-collapse"}}
23+
</button>
24+
<div class="breadcrumb">
2425
{{ctx.Locale.Tr "repo.editor.patching"}}
2526
<a class="section" href="{{$.RepoLink}}">{{.Repository.FullName}}</a>
2627
<div class="breadcrumb-divider">:</div>
2728
<a class="section" href="{{$.BranchLink}}">{{.BranchName}}</a>
2829
<span>{{ctx.Locale.Tr "repo.editor.or"}} <a href="{{$.BranchLink}}">{{ctx.Locale.Tr "repo.editor.cancel_lower"}}</a></span>
2930
<input type="hidden" name="tree_path" value="__dummy_for_EditRepoFileForm.TreePath(Required)__">
3031
<input id="file-name" type="hidden" value="diff.patch">
32+
</div>
33+
</div>
34+
<div class="tw-flex tw-gap-2">
35+
<a class="ui red button" href="{{$.BranchLink}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
36+
<button type="button" class="ui primary button disabled" id="commit-changes-button">
37+
{{ctx.Locale.Tr "repo.editor.commit_changes"}}
38+
</button>
3139
</div>
3240
</div>
3341
<div class="field">
@@ -42,10 +50,22 @@
4250
<div class="editor-loading is-loading"></div>
4351
</div>
4452
</div>
45-
{{template "repo/editor/commit_form" .}}
53+
{{/* Commit form fields - inside form but hidden, will be shown in modal */}}
54+
<div id="commit-form-fields" style="display: none;">
55+
{{template "repo/editor/commit_form" .}}
56+
</div>
57+
{{/* Hidden dummy button for repo-editor.ts compatibility */}}
58+
<button id="commit-button" type="button" style="display: none;"></button>
4659
</form>
4760
</div>
4861
</div>
4962
</div>
63+
64+
{{/* Commit Changes Modal - fields will be moved here visually */}}
65+
<div class="ui modal" id="commit-changes-modal">
66+
<i class="close icon"></i>
67+
<div class="content" id="commit-modal-content">
68+
</div>
69+
</div>
5070
</div>
5171
{{template "base/footer" .}}

templates/repo/editor/upload.tmpl

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,41 @@
1111
<form class="ui comment form form-fetch-action" method="post" action="{{.CommitFormOptions.TargetFormAction}}">
1212
{{.CsrfTokenHtml}}
1313
{{template "repo/editor/common_top" .}}
14-
<div class="repo-editor-header tw-flex tw-items-center tw-gap-2">
15-
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
16-
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
17-
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
18-
{{svg "octicon-sidebar-collapse"}}
19-
</button>
20-
{{template "repo/editor/common_breadcrumb" .}}
14+
<div class="repo-editor-header tw-flex tw-items-center tw-justify-between tw-gap-2">
15+
<div class="tw-flex tw-items-center tw-gap-2">
16+
<button type="button" class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if .UserSettingCodeViewShowFileTree}}tw-hidden{{end}}"
17+
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
18+
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}">
19+
{{svg "octicon-sidebar-collapse"}}
20+
</button>
21+
{{template "repo/editor/common_breadcrumb" .}}
22+
</div>
23+
<div class="tw-flex tw-gap-2">
24+
<a class="ui red button" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>
25+
<button type="button" class="ui primary button disabled" id="commit-changes-button">
26+
{{ctx.Locale.Tr "repo.editor.commit_changes"}}
27+
</button>
28+
</div>
2129
</div>
2230
<div class="field">
2331
{{template "repo/upload" .}}
2432
</div>
25-
{{template "repo/editor/commit_form" .}}
33+
{{/* Commit form fields - inside form but hidden, will be shown in modal */}}
34+
<div id="commit-form-fields" style="display: none;">
35+
{{template "repo/editor/commit_form" .}}
36+
</div>
37+
{{/* Hidden dummy button for repo-editor.ts compatibility */}}
38+
<button id="commit-button" type="button" style="display: none;"></button>
2639
</form>
2740
</div>
2841
</div>
2942
</div>
43+
44+
{{/* Commit Changes Modal - fields will be moved here visually */}}
45+
<div class="ui modal" id="commit-changes-modal">
46+
<i class="close icon"></i>
47+
<div class="content" id="commit-modal-content">
48+
</div>
49+
</div>
3050
</div>
3151
{{template "base/footer" .}}

web_src/css/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
@import "./repo/list-header.css";
6565
@import "./repo/file-view.css";
6666
@import "./repo/file-actions.css";
67+
@import "./repo/editor-commit.css";
6768
@import "./repo/wiki.css";
6869
@import "./repo/header.css";
6970
@import "./repo/home.css";

web_src/css/repo/editor-commit.css

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* Editor commit modal styling */
2+
#commit-changes-modal .content {
3+
padding: 1.5rem;
4+
}
5+
6+
/* Position commit form fields inside modal when visible */
7+
.commit-form-in-modal {
8+
position: fixed;
9+
top: 50%;
10+
left: 50%;
11+
transform: translate(-50%, -50%);
12+
z-index: 10001;
13+
max-width: 680px;
14+
width: 90%;
15+
max-height: 85vh;
16+
overflow-y: auto;
17+
background: var(--color-box-body);
18+
border-radius: 6px;
19+
padding: 1.5rem;
20+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
21+
}
22+
23+
/* Replicate the original commit form styling in the modal */
24+
#commit-changes-modal .commit-form-wrapper {
25+
padding-left: 48px;
26+
}
27+
28+
#commit-changes-modal .commit-form-wrapper .commit-avatar {
29+
float: left;
30+
margin-left: -48px;
31+
}
32+
33+
#commit-changes-modal .commit-form-wrapper .commit-form {
34+
position: relative;
35+
padding: 15px;
36+
border: 1px solid var(--color-secondary);
37+
border-radius: var(--border-radius);
38+
background-color: var(--color-box-body);
39+
}
40+
41+
#commit-changes-modal .commit-form h3 {
42+
margin-top: 0;
43+
margin-bottom: 1rem;
44+
}
45+
46+
#commit-changes-modal .commit-form .field {
47+
margin-bottom: 1rem;
48+
}
49+
50+
#commit-changes-modal .commit-form input[name="commit_summary"] {
51+
width: 100%;
52+
padding: 10px 12px;
53+
font-size: 14px;
54+
}
55+
56+
#commit-changes-modal .commit-form textarea[name="commit_message"] {
57+
width: 100%;
58+
padding: 10px 12px;
59+
font-size: 14px;
60+
}
61+
62+
#commit-changes-modal .quick-pull-choice .field {
63+
margin-bottom: 0.75rem;
64+
}
65+
66+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .new-branch-name-input {
67+
position: relative;
68+
margin-left: 25px;
69+
}
70+
71+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .new-branch-name-input input {
72+
width: 240px !important;
73+
padding-left: 26px !important;
74+
}
75+
76+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .octicon-git-branch {
77+
position: absolute;
78+
top: 9px;
79+
left: 8px;
80+
}
81+
82+
/* Arrow pointing to avatar */
83+
#commit-changes-modal .avatar-content-left-arrow::before,
84+
#commit-changes-modal .avatar-content-left-arrow::after {
85+
right: 100%;
86+
top: 20px;
87+
border: solid transparent;
88+
content: " ";
89+
height: 0;
90+
width: 0;
91+
position: absolute;
92+
pointer-events: none;
93+
}
94+
95+
#commit-changes-modal .avatar-content-left-arrow::before {
96+
border-right-color: var(--color-secondary);
97+
border-width: 9px;
98+
margin-top: -9px;
99+
}
100+
101+
#commit-changes-modal .avatar-content-left-arrow::after {
102+
border-right-color: var(--color-box-body);
103+
border-width: 8px;
104+
margin-top: -8px;
105+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import $ from 'jquery';
2+
3+
export function initRepoEditorCommit() {
4+
const commitButton = document.querySelector('#commit-changes-button');
5+
const commitModal = document.querySelector('#commit-changes-modal');
6+
const modalCommitButton = document.querySelector<HTMLButtonElement>('#commit-button');
7+
8+
if (!commitButton || !commitModal) return;
9+
10+
const elForm = document.querySelector<HTMLFormElement>('.repository.editor .edit.form');
11+
const dirtyFileClass = 'dirty-file';
12+
13+
// Sync the top commit button state with the modal commit button state
14+
const syncTopCommitButtonState = () => {
15+
// Check if form has changes (using the same dirty class from repo-editor.ts)
16+
const hasChanges = elForm?.classList.contains(dirtyFileClass);
17+
18+
// Also check the modal commit button state as fallback
19+
const modalButtonDisabled = modalCommitButton?.disabled;
20+
21+
if (hasChanges || !modalButtonDisabled) {
22+
commitButton.classList.remove('disabled');
23+
} else {
24+
commitButton.classList.add('disabled');
25+
}
26+
};
27+
28+
// For upload page - enable button when files are added
29+
const dropzone = document.querySelector('.dropzone');
30+
if (dropzone) {
31+
const observer = new MutationObserver(() => {
32+
const filesContainer = dropzone.querySelector('.files');
33+
const hasFiles = filesContainer && filesContainer.children.length > 0;
34+
35+
if (hasFiles) {
36+
commitButton.classList.remove('disabled');
37+
} else {
38+
commitButton.classList.add('disabled');
39+
}
40+
});
41+
42+
const filesContainer = dropzone.querySelector('.files');
43+
if (filesContainer) {
44+
observer.observe(filesContainer, {childList: true});
45+
}
46+
}
47+
48+
// Watch for changes in the form's dirty state
49+
if (elForm) {
50+
const observer = new MutationObserver(syncTopCommitButtonState);
51+
observer.observe(elForm, {attributes: true, attributeFilter: ['class']});
52+
53+
// Initial sync
54+
syncTopCommitButtonState();
55+
}
56+
57+
// Also sync when modal commit button state changes
58+
if (modalCommitButton) {
59+
const observer = new MutationObserver(syncTopCommitButtonState);
60+
observer.observe(modalCommitButton, {attributes: true, attributeFilter: ['disabled']});
61+
}
62+
63+
const commitFormFields = document.querySelector<HTMLElement>('#commit-form-fields');
64+
65+
commitButton.addEventListener('click', (e) => {
66+
e.preventDefault();
67+
if (!commitButton.classList.contains('disabled')) {
68+
// Show the commit form fields (they stay in the form, just become visible)
69+
if (commitFormFields) {
70+
commitFormFields.style.display = 'block';
71+
// Position it inside the modal using CSS
72+
commitFormFields.classList.add('commit-form-in-modal');
73+
}
74+
$(commitModal).modal('show');
75+
}
76+
});
77+
78+
// When modal closes, hide the form fields again
79+
$(commitModal).modal({
80+
onHidden: () => {
81+
if (commitFormFields) {
82+
commitFormFields.style.display = 'none';
83+
commitFormFields.classList.remove('commit-form-in-modal');
84+
}
85+
},
86+
});
87+
88+
// Handle form submission - close modal after submit
89+
if (elForm) {
90+
elForm.addEventListener('submit', () => {
91+
$(commitModal).modal('hide');
92+
});
93+
}
94+
}

0 commit comments

Comments
 (0)