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 .map() and enable eslint rules for it #29272

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ rules:
jquery/no-delegate: [2]
jquery/no-each: [0]
jquery/no-extend: [2]
jquery/no-fade: [0]
jquery/no-fade: [2]
jquery/no-filter: [0]
jquery/no-find: [0]
jquery/no-global-eval: [2]
Expand All @@ -309,7 +309,7 @@ rules:
jquery/no-is-function: [2]
jquery/no-is: [0]
jquery/no-load: [2]
jquery/no-map: [0]
jquery/no-map: [2]
jquery/no-merge: [2]
jquery/no-param: [2]
jquery/no-parent: [0]
Expand Down Expand Up @@ -451,7 +451,7 @@ rules:
no-jquery/no-load: [2]
no-jquery/no-map-collection: [0]
no-jquery/no-map-util: [2]
no-jquery/no-map: [0]
no-jquery/no-map: [2]
no-jquery/no-merge: [2]
no-jquery/no-node-name: [2]
no-jquery/no-noop: [2]
Expand Down
18 changes: 8 additions & 10 deletions web_src/js/features/repo-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ export function initRepoEllipsisButton() {
}

export function initRepoCommitLastCommitLoader() {
const entryMap = {};

const entries = $('table#repo-files-table tr.notready')
.map((_, v) => {
entryMap[$(v).attr('data-entryname')] = $(v);
return $(v).attr('data-entryname');
})
.get();
const notReadyEls = document.querySelectorAll('table#repo-files-table tr.notready');
if (!notReadyEls.length) return;

if (entries.length === 0) {
return;
const entryMap = {};
const entries = [];
for (const el of notReadyEls) {
const entryname = el.getAttribute('data-entryname');
entryMap[entryname] = $(el);
entries.push(entryname);
}

const lastCommitLoaderURL = $('table#repo-files-table').data('lastCommitLoaderUrl');
Expand Down
9 changes: 3 additions & 6 deletions web_src/js/features/repo-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,14 @@ async function onEditContent(event) {
}
};

const saveAndRefresh = (dz, $dropzone) => {
const saveAndRefresh = (dz) => {
showElem($renderContent);
hideElem($editContentZone);
const $attachments = $dropzone.find('.files').find('[name=files]').map(function () {
return $(this).val();
}).get();
$.post($editContentZone.attr('data-update-url'), {
_csrf: csrfToken,
content: comboMarkdownEditor.value(),
context: $editContentZone.attr('data-context'),
files: $attachments,
files: dz.files.map((file) => file.uuid),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replacement is wrong and causes a regression, I spent many hours on debugging it ........

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm pretty sure it was a array of either urls or uuids before and after the change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought maybe it is actually a array of File elements. Not sure what the value of a input[type=file] really is currently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because the dropzone was abused, the dz.files seldom gets correctly updated.

Copy link
Member Author

@silverwind silverwind Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I would definitely prefer for dropzone to be removed at some point. Won't be too hard to render a list of files with a "x" icon besides each, no need for fancy image preview etc.

}, (data) => {
if (!data.content) {
$renderContent.html($('#no-content').html());
Expand Down Expand Up @@ -452,7 +449,7 @@ async function onEditContent(event) {
});
$editContentZone.find('.save.button').on('click', (e) => {
e.preventDefault();
saveAndRefresh(dz, $dropzone);
saveAndRefresh(dz);
});
} else {
comboMarkdownEditor = getComboMarkdownEditor($editContentZone.find('.combo-markdown-editor'));
Expand Down
Loading