mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-10 19:32:02 +00:00
exclude current issue from suggestion
This commit is contained in:
parent
3b0b5d0513
commit
8d30b52fc1
4 changed files with 15 additions and 4 deletions
|
@ -4,11 +4,13 @@ import {getIssueIcon, getIssueColor,isIssueSuggestionsLoaded, fetchIssueSuggesti
|
||||||
import {svg} from '../../svg.js'
|
import {svg} from '../../svg.js'
|
||||||
import {createElementFromHTML} from '../../utils/dom.js';
|
import {createElementFromHTML} from '../../utils/dom.js';
|
||||||
import { GET } from '../../modules/fetch.js';
|
import { GET } from '../../modules/fetch.js';
|
||||||
|
import {parseIssueHref} from '../../utils.js'
|
||||||
|
|
||||||
async function issueSuggestions(text) {
|
async function issueSuggestions(text) {
|
||||||
const key = '#';
|
const key = '#';
|
||||||
|
|
||||||
const matches = matchIssue(text);
|
const issuePathInfo = parseIssueHref(window.location.href);
|
||||||
|
const matches = matchIssue(text, Number(issuePathInfo.index));
|
||||||
if (!matches.length) return {matched: false};
|
if (!matches.length) return {matched: false};
|
||||||
|
|
||||||
const ul = document.createElement('ul');
|
const ul = document.createElement('ul');
|
||||||
|
|
|
@ -36,7 +36,7 @@ export function isIssueSuggestionsLoaded() {
|
||||||
return !!window.config.issueValues
|
return !!window.config.issueValues
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchIssueSuggestions() {
|
export async function fetchIssueSuggestions() {
|
||||||
const issuePathInfo = parseIssueHref(window.location.href);
|
const issuePathInfo = parseIssueHref(window.location.href);
|
||||||
if (!issuePathInfo.ownerName) {
|
if (!issuePathInfo.ownerName) {
|
||||||
const repoOwnerPathInfo = parseRepoOwnerPathInfo(window.location.pathname);
|
const repoOwnerPathInfo = parseRepoOwnerPathInfo(window.location.pathname);
|
||||||
|
|
|
@ -44,8 +44,10 @@ export function matchMention(queryText) {
|
||||||
return sortAndReduce(results);
|
return sortAndReduce(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function matchIssue(queryText) {
|
export function matchIssue(queryText, currentIssue = null) {
|
||||||
const issues = window.config.issueValues ?? [];
|
const issues = (window.config.issueValues ?? []).filter(
|
||||||
|
issue => issue.number !== currentIssue
|
||||||
|
);
|
||||||
const query = queryText.toLowerCase().trim();
|
const query = queryText.toLowerCase().trim();
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ test('matchMention', () => {
|
||||||
test('matchIssue', () => {
|
test('matchIssue', () => {
|
||||||
expect(matchIssue('')).toEqual(window.config.issueValues.slice(0, 6));
|
expect(matchIssue('')).toEqual(window.config.issueValues.slice(0, 6));
|
||||||
expect(matchIssue('1')).toEqual([window.config.issueValues[9], window.config.issueValues[0]]);
|
expect(matchIssue('1')).toEqual([window.config.issueValues[9], window.config.issueValues[0]]);
|
||||||
|
expect(matchIssue('1', 1)).toEqual([window.config.issueValues[0]]);
|
||||||
expect(matchIssue('issue')).toEqual([
|
expect(matchIssue('issue')).toEqual([
|
||||||
window.config.issueValues[0],
|
window.config.issueValues[0],
|
||||||
window.config.issueValues[1],
|
window.config.issueValues[1],
|
||||||
|
@ -59,4 +60,10 @@ test('matchIssue', () => {
|
||||||
window.config.issueValues[7],
|
window.config.issueValues[7],
|
||||||
window.config.issueValues[9],
|
window.config.issueValues[9],
|
||||||
]);
|
]);
|
||||||
|
expect(matchIssue('issue', 10)).toEqual([
|
||||||
|
window.config.issueValues[1],
|
||||||
|
window.config.issueValues[2],
|
||||||
|
window.config.issueValues[7],
|
||||||
|
window.config.issueValues[9],
|
||||||
|
]);
|
||||||
});
|
});
|
Loading…
Add table
Add a link
Reference in a new issue