Skip to content

Remove jQuery AJAX from repo collaborator mode dropdown #29371

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

Merged
merged 8 commits into from
Feb 24, 2024
20 changes: 11 additions & 9 deletions web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import $ from 'jquery';
import {minimatch} from 'minimatch';
import {createMonaco} from './codeeditor.js';
import {onInputDebounce, toggleElem} from '../utils/dom.js';
import {POST} from '../modules/fetch.js';

const {appSubUrl, csrfToken} = window.config;

Expand All @@ -11,18 +12,19 @@ export function initRepoSettingsCollaboration() {
const $dropdown = $(e);
const $text = $dropdown.find('> .text');
$dropdown.dropdown({
action(_text, value) {
async action(_text, value) {
const lastValue = $dropdown.attr('data-last-value');
$.post($dropdown.attr('data-url'), {
_csrf: csrfToken,
uid: $dropdown.attr('data-uid'),
mode: value,
}).fail(() => {
try {
$dropdown.attr('data-last-value', value);
$dropdown.dropdown('hide');
const data = new FormData();
data.append('uid', $dropdown.attr('data-uid'));
data.append('mode', value);
await POST($dropdown.attr('data-url'), {data});
} catch {
$text.text('(error)'); // prevent from misleading users when error occurs
$dropdown.attr('data-last-value', lastValue);
});
$dropdown.attr('data-last-value', value);
$dropdown.dropdown('hide');
}
},
onChange(_value, text, _$choice) {
$text.text(text); // update the text when using keyboard navigating
Expand Down