Skip to content

Commit abbff0e

Browse files
make group selection in the new repository form look more hierarchical
1 parent d138ca6 commit abbff0e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

web_src/js/features/repo-new.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {hideElem, querySingleVisibleElem, showElem, toggleElem} from '../utils/dom.ts';
2-
import {htmlEscape} from '../utils/html.ts';
2+
import {html, htmlEscape} from '../utils/html.ts';
33
import {fomanticQuery} from '../modules/fomantic/base.ts';
44
import {sanitizeRepoName} from './repo-common.ts';
55

66
const {appSubUrl} = window.config;
7-
7+
const $ = window.$;
88
function initRepoNewTemplateSearch(form: HTMLFormElement) {
99
const elSubmitButton = querySingleVisibleElem<HTMLInputElement>(form, '.ui.primary.button');
1010
const elCreateRepoErrorMessage = form.querySelector('#create-repo-error-message');
@@ -59,18 +59,25 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) {
5959
}
6060

6161
function initRepoGroupSelector(form: HTMLFormElement) {
62-
const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('#uid');
62+
const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('input[name="uid"]');
6363
const elGroupDropdown = form.querySelector<HTMLInputElement>('#group_selector');
6464
const $dropdown = fomanticQuery(elGroupDropdown);
6565
const onChangeRepoOwner = function () {
66-
$dropdown.dropdown('setting', {
66+
$dropdown.dropdown({
67+
keepSearchTerm: true,
68+
fireOnInit: true,
69+
saveRemoteData: false,
6770
apiSettings: {
6871
url: `${appSubUrl}/group/search?uid=${inputRepoOwnerUid.value}&recurse=true`,
69-
onResponse(response) {
72+
onResponse(response: {data: any}) {
7073
const results = [];
71-
results.push({name: '', value: ''}); // empty item means not using template
72-
const forEachFn = function({group, subgroups}, depth: number) {
73-
results.push({name: group.name, value: String(group.id)});
74+
results.push({name: '', value: '0'});
75+
const forEachFn = function ({group, subgroups}: {group: any, subgroups: any[]}, depth: number) {
76+
results.push({
77+
// eslint-disable-next-line github/unescaped-html-literal
78+
name: `<span style="margin-left: ${depth + 1}rem">${html`${group.name}`}</span>`,
79+
value: String(group.id),
80+
});
7481
for (const sg of subgroups) {
7582
forEachFn(sg, depth + 1);
7683
}

0 commit comments

Comments
 (0)