aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/common-button.ts3
-rw-r--r--web_src/js/utils.test.ts1
-rw-r--r--web_src/js/utils.ts2
3 files changed, 4 insertions, 2 deletions
diff --git a/web_src/js/features/common-button.ts b/web_src/js/features/common-button.ts
index acce992b90..3162557b9b 100644
--- a/web_src/js/features/common-button.ts
+++ b/web_src/js/features/common-button.ts
@@ -17,7 +17,8 @@ export function initGlobalDeleteButton(): void {
// Some model/form elements will be filled by `data-id` / `data-name` / `data-data-xxx` attributes.
// If there is a form defined by `data-form`, then the form will be submitted as-is (without any modification).
// If there is no form, then the data will be posted to `data-url`.
- // TODO: it's not encouraged to use this method. `show-modal` does far better than this.
+ // TODO: do not use this method in new code. `show-modal` / `link-action(data-modal-confirm)` does far better than this.
+ // FIXME: all legacy `delete-button` should be refactored to use `show-modal` or `link-action`
for (const btn of document.querySelectorAll<HTMLElement>('.delete-button')) {
btn.addEventListener('click', (e) => {
e.preventDefault();
diff --git a/web_src/js/utils.test.ts b/web_src/js/utils.test.ts
index bbe328f658..b527111533 100644
--- a/web_src/js/utils.test.ts
+++ b/web_src/js/utils.test.ts
@@ -50,6 +50,7 @@ test('parseIssueNewHref', () => {
expect(parseIssueNewHref('/owner/repo/issues/new?query')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
expect(parseIssueNewHref('/sub/owner/repo/issues/new#hash')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'issues'});
expect(parseIssueNewHref('/sub/owner/repo/compare/feature/branch-1...fix/branch-2')).toEqual({ownerName: 'owner', repoName: 'repo', pathType: 'pulls'});
+ expect(parseIssueNewHref('/other')).toEqual({});
});
test('parseUrl', () => {
diff --git a/web_src/js/utils.ts b/web_src/js/utils.ts
index efa144c3c7..2a2bdc60f9 100644
--- a/web_src/js/utils.ts
+++ b/web_src/js/utils.ts
@@ -40,7 +40,7 @@ export function parseIssueHref(href: string): IssuePathInfo {
export function parseIssueNewHref(href: string): IssuePathInfo {
const path = (href || '').replace(/[#?].*$/, '');
const [_, ownerName, repoName, pathTypeField] = /([^/]+)\/([^/]+)\/(issues\/new|compare\/.+\.\.\.)/.exec(path) || [];
- const pathType = pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls';
+ const pathType = pathTypeField ? (pathTypeField.startsWith('issues/new') ? 'issues' : 'pulls') : undefined;
return {ownerName, repoName, pathType};
}