web/admin: replace group selections with ak-search-select
closes #4157 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		@ -1,4 +1,5 @@
 | 
			
		||||
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
 | 
			
		||||
import "@goauthentik/elements/SearchSelect";
 | 
			
		||||
import "@goauthentik/elements/forms/HorizontalFormElement";
 | 
			
		||||
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
 | 
			
		||||
 | 
			
		||||
@ -9,7 +10,14 @@ import { customElement } from "lit/decorators.js";
 | 
			
		||||
import { ifDefined } from "lit/directives/if-defined.js";
 | 
			
		||||
import { until } from "lit/directives/until.js";
 | 
			
		||||
 | 
			
		||||
import { CoreApi, EventsApi, NotificationRule, SeverityEnum } from "@goauthentik/api";
 | 
			
		||||
import {
 | 
			
		||||
    CoreApi,
 | 
			
		||||
    CoreGroupsListRequest,
 | 
			
		||||
    EventsApi,
 | 
			
		||||
    Group,
 | 
			
		||||
    NotificationRule,
 | 
			
		||||
    SeverityEnum,
 | 
			
		||||
} from "@goauthentik/api";
 | 
			
		||||
 | 
			
		||||
@customElement("ak-event-rule-form")
 | 
			
		||||
export class RuleForm extends ModelForm<NotificationRule, string> {
 | 
			
		||||
@ -74,24 +82,29 @@ export class RuleForm extends ModelForm<NotificationRule, string> {
 | 
			
		||||
                />
 | 
			
		||||
            </ak-form-element-horizontal>
 | 
			
		||||
            <ak-form-element-horizontal label=${t`Group`} name="group">
 | 
			
		||||
                <select class="pf-c-form-control">
 | 
			
		||||
                    <option value="" ?selected=${this.instance?.group === undefined}>
 | 
			
		||||
                        ---------
 | 
			
		||||
                    </option>
 | 
			
		||||
                    ${until(
 | 
			
		||||
                        new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then((groups) => {
 | 
			
		||||
                            return groups.results.map((group) => {
 | 
			
		||||
                                return html`<option
 | 
			
		||||
                                    value=${ifDefined(group.pk)}
 | 
			
		||||
                                    ?selected=${this.instance?.group === group.pk}
 | 
			
		||||
                                >
 | 
			
		||||
                                    ${group.name}
 | 
			
		||||
                                </option>`;
 | 
			
		||||
                            });
 | 
			
		||||
                        }),
 | 
			
		||||
                        html`<option>${t`Loading...`}</option>`,
 | 
			
		||||
                    )}
 | 
			
		||||
                </select>
 | 
			
		||||
                <ak-search-select
 | 
			
		||||
                    .fetchObjects=${async (query?: string): Promise<Group[]> => {
 | 
			
		||||
                        const args: CoreGroupsListRequest = {
 | 
			
		||||
                            ordering: "name",
 | 
			
		||||
                        };
 | 
			
		||||
                        if (query !== undefined) {
 | 
			
		||||
                            args.search = query;
 | 
			
		||||
                        }
 | 
			
		||||
                        const groups = await new CoreApi(DEFAULT_CONFIG).coreGroupsList(args);
 | 
			
		||||
                        return groups.results;
 | 
			
		||||
                    }}
 | 
			
		||||
                    .renderElement=${(group: Group): string => {
 | 
			
		||||
                        return group.name;
 | 
			
		||||
                    }}
 | 
			
		||||
                    .value=${(group: Group | undefined): string | undefined => {
 | 
			
		||||
                        return group?.pk;
 | 
			
		||||
                    }}
 | 
			
		||||
                    .selected=${(group: Group): boolean => {
 | 
			
		||||
                        return group.pk === this.instance?.group;
 | 
			
		||||
                    }}
 | 
			
		||||
                    ?blankable=${true}
 | 
			
		||||
                >
 | 
			
		||||
                </ak-search-select>
 | 
			
		||||
            </ak-form-element-horizontal>
 | 
			
		||||
            <ak-form-element-horizontal label=${t`Transports`} ?required=${true} name="transports">
 | 
			
		||||
                <select name="users" class="pf-c-form-control" multiple>
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user