Skip to content

Commit 824b570

Browse files
committed
fix
1 parent 6bd70d4 commit 824b570

File tree

9 files changed

+92
-181
lines changed

9 files changed

+92
-181
lines changed

templates/org/settings/labels.tmpl

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{{template "org/settings/layout_head" (dict "ctxData" . "pageClass" "organization settings labels")}}
2-
<div class="org-setting-content">
3-
<div class="tw-flex tw-items-center">
4-
<div class="tw-flex-1">
5-
{{ctx.Locale.Tr "org.settings.labels_desc"}}
6-
</div>
7-
<button class="ui small primary new-label button">{{ctx.Locale.Tr "repo.issues.new_label"}}</button>
8-
</div>
9-
<div class="divider"></div>
10-
{{template "repo/issue/labels/label_new" .}}
11-
{{template "repo/issue/labels/label_list" .}}
12-
</div>
13-
{{template "repo/issue/labels/edit_delete_label" .}}
2+
<div class="org-setting-content">
3+
<div class="tw-flex tw-items-center">
4+
<div class="tw-flex-1">
5+
{{ctx.Locale.Tr "org.settings.labels_desc"}}
6+
</div>
7+
<button class="ui small primary new-label button">{{ctx.Locale.Tr "repo.issues.new_label"}}</button>
8+
</div>
9+
<div class="divider"></div>
10+
{{template "repo/issue/labels/label_list" .}}
11+
{{template "repo/issue/labels/label_edit_modal" .}}
12+
</div>
1413
{{template "org/settings/layout_footer" .}}
15-

templates/repo/issue/labels.tmpl

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
<button class="ui small primary new-label button">{{ctx.Locale.Tr "repo.issues.new_label"}}</button>
99
{{end}}
1010
</div>
11-
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
12-
{{template "repo/issue/labels/label_new" .}}
13-
{{end}}
1411
{{template "base/alert" .}}
1512
{{template "repo/issue/labels/label_list" .}}
1613
</div>
14+
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
15+
{{template "repo/issue/labels/label_edit_modal" .}}
16+
{{end}}
1717
</div>
18-
19-
{{if and (or .CanWriteIssues .CanWritePulls) (not .Repository.IsArchived)}}
20-
{{template "repo/issue/labels/edit_delete_label" .}}
21-
{{end}}
2218
{{template "base/footer" .}}

templates/repo/issue/labels/edit_delete_label.tmpl templates/repo/issue/labels/label_edit_modal.tmpl

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
<div class="ui g-modal-confirm delete modal">
2-
<div class="header">
3-
{{svg "octicon-trash"}}
4-
{{ctx.Locale.Tr "repo.issues.label_deletion"}}
5-
</div>
6-
<div class="content">
7-
<p>{{ctx.Locale.Tr "repo.issues.label_deletion_desc"}}</p>
8-
</div>
9-
{{template "base/modal_actions_confirm" .}}
10-
</div>
11-
12-
<div class="ui small edit-label modal">
13-
<div class="header">
14-
{{ctx.Locale.Tr "repo.issues.label_modify"}}
15-
</div>
1+
<div class="ui small modal" id="issue-label-edit-modal"
2+
data-repo-link="{{$.Link}}"
3+
data-text-new-label="{{ctx.Locale.Tr "repo.issues.new_label"}}"
4+
data-text-edit-label="{{ctx.Locale.Tr "repo.issues.label_modify"}}"
5+
>
6+
<div class="header"></div>
167
<div class="content">
17-
<form class="ui edit-label form ignore-dirty" action="{{$.Link}}/edit" method="post">
8+
<form class="ui form ignore-dirty" method="post">
189
{{.CsrfTokenHtml}}
19-
<input id="label-modal-id" name="id" type="hidden">
10+
<input name="id" type="hidden">
2011
<div class="required field">
2112
<label for="name">{{ctx.Locale.Tr "repo.issues.label_title"}}</label>
2213
<div class="ui small input">

templates/repo/issue/labels/label_list.tmpl

+12-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
{{end}}
2828

2929
<ul class="issue-label-list">
30+
{{$canEditLabel := and (not $.PageIsOrgSettingsLabels) (not $.Repository.IsArchived) (or $.CanWriteIssues $.CanWritePulls)}}
31+
{{$canEditLabel = or $canEditLabel $.PageIsOrgSettingsLabels}}
3032
{{range .Labels}}
3133
<li class="item">
3234
<div class="label-title">
@@ -43,12 +45,16 @@
4345
<div class="label-operation tw-flex">
4446
{{template "repo/issue/labels/label_archived" .}}
4547
<div class="tw-flex tw-ml-auto">
46-
{{if and (not $.PageIsOrgSettingsLabels) (not $.Repository.IsArchived) (or $.CanWriteIssues $.CanWritePulls)}}
47-
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} {{if gt .ArchivedUnix 0}}data-is-archived{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{ctx.Locale.Tr "repo.issues.label_edit"}}</a>
48-
<a class="delete-button" href="#" data-url="{{$.Link}}/delete" data-id="{{.ID}}">{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.issues.label_delete"}}</a>
49-
{{else if $.PageIsOrgSettingsLabels}}
50-
<a class="edit-label-button" href="#" data-id="{{.ID}}" data-title="{{.Name}}" {{if .Exclusive}}data-exclusive{{end}} {{if gt .ArchivedUnix 0}}data-is-archived{{end}} data-num-issues="{{.NumIssues}}" data-description="{{.Description}}" data-color={{.Color}}>{{svg "octicon-pencil"}} {{ctx.Locale.Tr "repo.issues.label_edit"}}</a>
51-
<a class="delete-button" href="#" data-url="{{$.Link}}/delete" data-id="{{.ID}}">{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.issues.label_delete"}}</a>
48+
{{if $canEditLabel}}
49+
<a class="edit-label-button" href="#"
50+
data-label-id="{{.ID}}" data-label-name="{{.Name}}" data-label-color="{{.Color}}"
51+
data-label-exclusive="{{.Exclusive}}" data-label-is-archived="{{gt .ArchivedUnix 0}}"
52+
data-label-num-issues="{{.NumIssues}}" data-label-description="{{.Description}}"
53+
>{{svg "octicon-pencil"}} {{ctx.Locale.Tr "repo.issues.label_edit"}}</a>
54+
<a class="link-action" href="#" data-url="{{$.Link}}/delete?id={{.ID}}"
55+
data-modal-confirm-header="{{ctx.Locale.Tr "repo.issues.label_deletion"}}"
56+
data-modal-confirm-content="{{ctx.Locale.Tr "repo.issues.label_deletion_desc"}}"
57+
>{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.issues.label_delete"}}</a>
5258
{{end}}
5359
</div>
5460
</div>

templates/repo/issue/labels/label_new.tmpl

-48
This file was deleted.

web_src/css/repo.css

-11
Original file line numberDiff line numberDiff line change
@@ -2061,17 +2061,6 @@ td .commit-summary {
20612061
padding: 1em;
20622062
}
20632063

2064-
.edit-label.modal .form .column,
2065-
.new-label.modal .form .column {
2066-
padding-right: 0;
2067-
}
2068-
2069-
.edit-label.modal .form .buttons,
2070-
.new-label.modal .form .buttons {
2071-
margin-left: auto;
2072-
padding-top: 15px;
2073-
}
2074-
20752064
.stats-table {
20762065
display: table;
20772066
width: 100%;

web_src/js/features/common-organization.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export function initCommonOrganization() {
1212
});
1313

1414
// Labels
15-
initCompLabelEdit('.organization.settings.labels');
15+
initCompLabelEdit('.page-content.organization.settings.labels');
1616
}

web_src/js/features/comp/LabelEdit.ts

+56-77
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,75 @@
1-
import $ from 'jquery';
1+
import {toggleElem} from '../../utils/dom.ts';
2+
import {fomanticQuery} from '../../modules/fomantic/base.ts';
23

3-
function isExclusiveScopeName(name) {
4+
function nameHasScope(name: string) {
45
return /.*[^/]\/[^/].*/.test(name);
56
}
67

7-
function updateExclusiveLabelEdit(form) {
8-
const nameInput = document.querySelector(`${form} .label-name-input`);
9-
const exclusiveField = document.querySelector(`${form} .label-exclusive-input-field`);
10-
const exclusiveCheckbox = document.querySelector(`${form} .label-exclusive-input`);
11-
const exclusiveWarning = document.querySelector(`${form} .label-exclusive-warning`);
8+
export function initCompLabelEdit(pageSelector: string) {
9+
const pageContent = document.querySelector<HTMLElement>(pageSelector);
10+
if (!pageContent) return;
1211

13-
if (isExclusiveScopeName(nameInput.value)) {
14-
exclusiveField?.classList.remove('muted');
15-
exclusiveField?.removeAttribute('aria-disabled');
16-
if (exclusiveCheckbox.checked && exclusiveCheckbox.getAttribute('data-exclusive-warn')) {
17-
exclusiveWarning?.classList.remove('tw-hidden');
18-
} else {
19-
exclusiveWarning?.classList.add('tw-hidden');
20-
}
21-
} else {
22-
exclusiveField?.classList.add('muted');
23-
exclusiveField?.setAttribute('aria-disabled', 'true');
24-
exclusiveWarning?.classList.add('tw-hidden');
25-
}
26-
}
27-
28-
export function initCompLabelEdit(selector) {
29-
if (!$(selector).length) return;
30-
31-
// Create label
32-
$('.new-label.button').on('click', () => {
33-
updateExclusiveLabelEdit('.new-label');
34-
$('.new-label.modal').modal({
35-
onApprove() {
36-
const form = document.querySelector('.new-label.form');
37-
if (!form.checkValidity()) {
38-
form.reportValidity();
39-
return false;
40-
}
41-
$('.new-label.form').trigger('submit');
42-
},
43-
}).modal('show');
44-
return false;
45-
});
46-
47-
// Edit label
48-
$('.edit-label-button').on('click', function () {
49-
$('#label-modal-id').val($(this).data('id'));
12+
const elModal = pageContent.querySelector<HTMLElement>('#issue-label-edit-modal');
13+
const elLabelId = elModal.querySelector<HTMLInputElement>('input[name="id"]');
14+
const elNameInput = elModal.querySelector<HTMLInputElement>('.label-name-input');
15+
const elExclusiveField = elModal.querySelector('.label-exclusive-input-field');
16+
const elExclusiveInput = elModal.querySelector<HTMLInputElement>('.label-exclusive-input');
17+
const elExclusiveWarning = elModal.querySelector('.label-exclusive-warning');
18+
const elIsArchivedField = elModal.querySelector('.label-is-archived-input-field');
19+
const elIsArchivedInput = elModal.querySelector<HTMLInputElement>('.label-is-archived-input');
20+
const elDescInput = elModal.querySelector<HTMLInputElement>('.label-desc-input');
21+
const elColorInput = elModal.querySelector<HTMLInputElement>('.js-color-picker-input input');
5022

51-
const $nameInput = $('.edit-label .label-name-input');
52-
$nameInput.val($(this).data('title'));
23+
const syncModalUi = () => {
24+
const hasScope = nameHasScope(elNameInput.value);
25+
elExclusiveField.classList.toggle('disabled', !hasScope);
26+
const showExclusiveWarning = hasScope && elExclusiveInput.checked && elModal.hasAttribute('data-need-warn-exclusive');
27+
toggleElem(elExclusiveWarning, showExclusiveWarning);
28+
if (!hasScope) elExclusiveInput.checked = false;
29+
};
5330

54-
const $isArchivedCheckbox = $('.edit-label .label-is-archived-input');
55-
$isArchivedCheckbox[0].checked = this.hasAttribute('data-is-archived');
31+
const showLabelEditModal = (btn:HTMLElement) => {
32+
const form = elModal.querySelector<HTMLFormElement>('form');
33+
elLabelId.value = btn.getAttribute('data-label-id') || '';
34+
elNameInput.value = btn.getAttribute('data-label-name') || '';
35+
elIsArchivedInput.checked = btn.getAttribute('data-label-is-archived') === 'true';
36+
elExclusiveInput.checked = btn.getAttribute('data-label-exclusive') === 'true';
37+
elDescInput.value = btn.getAttribute('data-label-description') || '';
38+
elColorInput.value = btn.getAttribute('data-label-color') || '';
39+
elColorInput.dispatchEvent(new Event('input', {bubbles: true})); // trigger the color picker
5640

57-
const $exclusiveCheckbox = $('.edit-label .label-exclusive-input');
58-
$exclusiveCheckbox[0].checked = this.hasAttribute('data-exclusive');
59-
// Warn when label was previously not exclusive and used in issues
60-
$exclusiveCheckbox.data('exclusive-warn',
61-
$(this).data('num-issues') > 0 &&
62-
(!this.hasAttribute('data-exclusive') || !isExclusiveScopeName($nameInput.val())));
63-
updateExclusiveLabelEdit('.edit-label');
41+
const isEdit = Boolean(elLabelId.value);
6442

65-
$('.edit-label .label-desc-input').val(this.getAttribute('data-description'));
43+
// if a label was not exclusive but has issues, then it should warn user if it will become exclusive
44+
const numIssues = parseInt(btn.getAttribute('data-label-num-issues') || '0');
45+
elModal.toggleAttribute('data-need-warn-exclusive', !elExclusiveInput.checked && numIssues > 0);
46+
elModal.querySelector('.header').textContent = isEdit ? elModal.getAttribute('data-text-edit-label') : elModal.getAttribute('data-text-new-label');
6647

67-
const colorInput = document.querySelector('.edit-label .js-color-picker-input input');
68-
colorInput.value = this.getAttribute('data-color');
69-
colorInput.dispatchEvent(new Event('input', {bubbles: true}));
70-
71-
$('.edit-label.modal').modal({
48+
const repoLink = elModal.getAttribute('data-repo-link');
49+
form.action = isEdit ? `${repoLink}/edit` : `${repoLink}/new`;
50+
toggleElem(elIsArchivedField, isEdit);
51+
syncModalUi();
52+
fomanticQuery(elModal).modal({
7253
onApprove() {
73-
const form = document.querySelector('.edit-label.form');
7454
if (!form.checkValidity()) {
7555
form.reportValidity();
7656
return false;
7757
}
78-
$('.edit-label.form').trigger('submit');
58+
form.submit();
7959
},
8060
}).modal('show');
81-
return false;
82-
});
61+
};
62+
63+
elModal.addEventListener('input', () => syncModalUi());
8364

84-
$('.new-label .label-name-input').on('input', () => {
85-
updateExclusiveLabelEdit('.new-label');
86-
});
87-
$('.new-label .label-exclusive-input').on('change', () => {
88-
updateExclusiveLabelEdit('.new-label');
89-
});
90-
$('.edit-label .label-name-input').on('input', () => {
91-
updateExclusiveLabelEdit('.edit-label');
92-
});
93-
$('.edit-label .label-exclusive-input').on('change', () => {
94-
updateExclusiveLabelEdit('.edit-label');
95-
});
65+
const elNewLabel = pageContent.querySelector<HTMLElement>('.ui.button.new-label');
66+
elNewLabel.addEventListener('click', () => showLabelEditModal(elNewLabel));
67+
68+
const elEditLabelButtons = pageContent.querySelectorAll<HTMLElement>('.edit-label-button');
69+
for (const btn of elEditLabelButtons) {
70+
btn.addEventListener('click', (e) => {
71+
e.preventDefault();
72+
showLabelEditModal(btn);
73+
});
74+
}
9675
}

web_src/js/features/repo-legacy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function initRepository() {
4343
initRepoCommentFormAndSidebar();
4444

4545
// Labels
46-
initCompLabelEdit('.repository.labels');
46+
initCompLabelEdit('.page-content.repository.labels');
4747
initRepoMilestone();
4848
initRepoNew();
4949

0 commit comments

Comments
 (0)