Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove jQuery class from the repository topic box #30191

Merged
merged 18 commits into from
Mar 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions web_src/js/features/repo-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export function initRepoTopicBar() {
const viewDiv = document.getElementById('repo-topics');
const saveBtn = document.getElementById('save_topic');
const topicDropdown = editDiv.querySelector('.dropdown');
const $topicDropdown = $(topicDropdown);
const $topicForm = $(editDiv);
const $topicDropdownSearch = $topicDropdown.find('input.search');
/**
* @type {HTMLInputElement}
*/
const topicDropdownSearch = topicDropdown.querySelector('input.search');
const topicPrompts = {
countPrompt: topicDropdown.getAttribute('data-text-count-prompt') ?? undefined,
formatPrompt: topicDropdown.getAttribute('data-text-format-prompt') ?? undefined,
Expand All @@ -23,7 +25,7 @@ export function initRepoTopicBar() {
mgrBtn.addEventListener('click', () => {
hideElem(viewDiv);
showElem(editDiv);
$topicDropdownSearch.trigger('focus');
topicDropdownSearch?.focus();
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
});

$('#cancel_topic_edit').on('click', () => {
Expand Down Expand Up @@ -64,10 +66,11 @@ export function initRepoTopicBar() {
topicPrompts.formatPrompt = responseData.message;

const {invalidTopics} = responseData;
const $topicLabels = $topicDropdown.children('a.ui.label');
const topicLabels = topicDropdown.querySelectorAll(':scope > a.ui.label');
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
for (const [index, value] of topics.split(',').entries()) {
if (invalidTopics.includes(value)) {
$topicLabels.eq(index).removeClass('green').addClass('red');
topicLabels[index].classList.remove('green');
topicLabels[index].classList.add('red');
}
}
} else {
Expand All @@ -79,7 +82,7 @@ export function initRepoTopicBar() {
$topicForm.form('validate form');
});

$topicDropdown.dropdown({
$(topicDropdown).dropdown({
allowAdditions: true,
forceSelection: false,
fullTextSearch: 'exact',
Expand All @@ -102,9 +105,9 @@ export function initRepoTopicBar() {
const query = stripTags(this.urlData.query.trim());
let found_query = false;
const current_topics = [];
$topicDropdown.find('a.label.visible').each((_, el) => {
for (const el of topicDropdown.querySelectorAll(':scope > a.label.visible')) {
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
current_topics.push(el.getAttribute('data-value'));
});
}

if (res.topics) {
let found = false;
Expand Down Expand Up @@ -152,12 +155,14 @@ export function initRepoTopicBar() {
});

$.fn.form.settings.rules.validateTopic = function (_values, regExp) {
const $topics = $topicDropdown.children('a.ui.label');
const status = !$topics.length || $topics.last()[0].getAttribute('data-value').match(regExp);
const topics = topicDropdown.querySelectorAll(':scope > a.ui.label');
const lastTopic = topics[topics.length - 1];
const status = !topics.length || lastTopic.getAttribute('data-value').match(regExp);
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
if (!status) {
$topics.last().removeClass('green').addClass('red');
lastTopic.classList.remove('green');
lastTopic.classList.add('red');
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}
return status && !$topicDropdown.children('a.ui.label.red').length;
return status && !topicDropdown.querySelectorAll(':scope > a.ui.label.red').length;
yardenshoham marked this conversation as resolved.
Show resolved Hide resolved
};

$topicForm.form({
Expand Down