Skip to content

Commit 3ec69bf

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

File tree

8 files changed

+241
-28
lines changed

8 files changed

+241
-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: 23 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,17 @@
5664
</div>
5765
</div>
5866
{{end}}
59-
{{template "repo/editor/commit_form" .}}
6067
</form>
6168
</div>
6269
</div>
6370
</div>
71+
72+
{{/* Commit Changes Modal */}}
73+
<div class="ui modal" id="commit-changes-modal">
74+
<i class="close icon"></i>
75+
<div class="content">
76+
{{template "repo/editor/commit_form" .}}
77+
</div>
78+
</div>
6479
</div>
6580
{{template "base/footer" .}}

templates/repo/editor/patch.tmpl

Lines changed: 23 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,17 @@
4250
<div class="editor-loading is-loading"></div>
4351
</div>
4452
</div>
45-
{{template "repo/editor/commit_form" .}}
4653
</form>
4754
</div>
4855
</div>
4956
</div>
57+
58+
{{/* Commit Changes Modal */}}
59+
<div class="ui modal" id="commit-changes-modal">
60+
<i class="close icon"></i>
61+
<div class="content">
62+
{{template "repo/editor/commit_form" .}}
63+
</div>
64+
</div>
5065
</div>
5166
{{template "base/footer" .}}

templates/repo/editor/upload.tmpl

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,36 @@
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" .}}
2633
</form>
2734
</div>
2835
</div>
2936
</div>
37+
38+
{{/* Commit Changes Modal */}}
39+
<div class="ui modal" id="commit-changes-modal">
40+
<i class="close icon"></i>
41+
<div class="content">
42+
{{template "repo/editor/commit_form" .}}
43+
</div>
44+
</div>
3045
</div>
3146
{{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: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* Editor commit modal styling */
2+
#commit-changes-modal .content {
3+
padding: 1.5rem;
4+
}
5+
6+
/* Replicate the original commit form styling in the modal */
7+
#commit-changes-modal .commit-form-wrapper {
8+
padding-left: 48px;
9+
}
10+
11+
#commit-changes-modal .commit-form-wrapper .commit-avatar {
12+
float: left;
13+
margin-left: -48px;
14+
}
15+
16+
#commit-changes-modal .commit-form-wrapper .commit-form {
17+
position: relative;
18+
padding: 15px;
19+
border: 1px solid var(--color-secondary);
20+
border-radius: var(--border-radius);
21+
background-color: var(--color-box-body);
22+
}
23+
24+
#commit-changes-modal .commit-form h3 {
25+
margin-top: 0;
26+
margin-bottom: 1rem;
27+
}
28+
29+
#commit-changes-modal .commit-form .field {
30+
margin-bottom: 1rem;
31+
}
32+
33+
#commit-changes-modal .commit-form input[name="commit_summary"] {
34+
width: 100%;
35+
padding: 10px 12px;
36+
font-size: 14px;
37+
}
38+
39+
#commit-changes-modal .commit-form textarea[name="commit_message"] {
40+
width: 100%;
41+
padding: 10px 12px;
42+
font-size: 14px;
43+
}
44+
45+
#commit-changes-modal .quick-pull-choice .field {
46+
margin-bottom: 0.75rem;
47+
}
48+
49+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .new-branch-name-input {
50+
position: relative;
51+
margin-left: 25px;
52+
}
53+
54+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .new-branch-name-input input {
55+
width: 240px !important;
56+
padding-left: 26px !important;
57+
}
58+
59+
#commit-changes-modal .commit-form-wrapper .commit-form .quick-pull-choice .octicon-git-branch {
60+
position: absolute;
61+
top: 9px;
62+
left: 8px;
63+
}
64+
65+
/* Arrow pointing to avatar */
66+
#commit-changes-modal .avatar-content-left-arrow::before,
67+
#commit-changes-modal .avatar-content-left-arrow::after {
68+
right: 100%;
69+
top: 20px;
70+
border: solid transparent;
71+
content: " ";
72+
height: 0;
73+
width: 0;
74+
position: absolute;
75+
pointer-events: none;
76+
}
77+
78+
#commit-changes-modal .avatar-content-left-arrow::before {
79+
border-right-color: var(--color-secondary);
80+
border-width: 9px;
81+
margin-top: -9px;
82+
}
83+
84+
#commit-changes-modal .avatar-content-left-arrow::after {
85+
border-right-color: var(--color-box-body);
86+
border-width: 8px;
87+
margin-top: -8px;
88+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
commitButton.addEventListener('click', (e) => {
64+
e.preventDefault();
65+
if (!commitButton.classList.contains('disabled')) {
66+
$(commitModal).modal('show');
67+
}
68+
});
69+
70+
// Handle form submission - close modal after submit
71+
if (elForm) {
72+
elForm.addEventListener('submit', () => {
73+
$(commitModal).modal('hide');
74+
});
75+
}
76+
}

web_src/js/index-domready.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {initOrgTeam} from './features/org-team.ts';
3434
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
3535
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
3636
import {initRepoEditor} from './features/repo-editor.ts';
37+
import {initRepoEditorCommit} from './features/repo-editor-commit.ts';
3738
import {initCompSearchUserBox} from './features/comp/SearchUserBox.ts';
3839
import {initInstall} from './features/install.ts';
3940
import {initCompWebHookEditor} from './features/comp/WebHookEditor.ts';
@@ -123,6 +124,7 @@ const initPerformanceTracer = callInitFunctions([
123124
initRepoEllipsisButton,
124125
initRepoDiffCommitBranchesAndTags,
125126
initRepoEditor,
127+
initRepoEditorCommit,
126128
initRepoGraphGit,
127129
initRepoIssueContentHistory,
128130
initRepoIssueList,

0 commit comments

Comments
 (0)