web/user: fix broken search on application library (#5743)
web: fix broken search on application library This is *mortifying*. I didn't test this well enough, and apparently broke it again once I'd tested it. This patch restores the original behavior ("no match" means "just show everything"), and fixes a small bit of semantic lint -- the "search" feature should not be assigning meaning to what it finds; it's enough to pass back the prioritized list to whatever client wanted it, and let the client decide what to do with it.
This commit is contained in:
parent
4230d8ee20
commit
7c43c1a05b
|
@ -16,10 +16,6 @@ import type { Application } from "@goauthentik/api";
|
|||
import { SEARCH_ITEM_SELECTED, SEARCH_UPDATED } from "./constants";
|
||||
import { customEvent } from "./helpers";
|
||||
|
||||
function fuseToApps(apps: Fuse.FuseResult<Application>[]): Application[] {
|
||||
return apps.map((item) => item.item);
|
||||
}
|
||||
|
||||
@customElement("ak-library-list-search")
|
||||
export class LibraryPageApplicationList extends AKElement {
|
||||
static styles = [PFBase, PFDisplay];
|
||||
|
@ -55,16 +51,15 @@ export class LibraryPageApplicationList extends AKElement {
|
|||
}
|
||||
|
||||
onSelected(apps: Fuse.FuseResult<Application>[]) {
|
||||
const items = fuseToApps(apps);
|
||||
this.dispatchEvent(
|
||||
customEvent(SEARCH_UPDATED, {
|
||||
selectedApp: items[0],
|
||||
filteredApps: items,
|
||||
apps: apps.map((app) => app.item),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this.fuse.setCollection(this.apps);
|
||||
if (!this.query) {
|
||||
return;
|
||||
|
|
|
@ -85,9 +85,14 @@ export class LibraryPage extends AKElement {
|
|||
throw new Error("ak-library-search-updated must send a custom event.");
|
||||
}
|
||||
event.stopPropagation();
|
||||
this.selectedApp = event.detail.apps[0];
|
||||
const apps = event.detail.apps;
|
||||
this.selectedApp = undefined;
|
||||
this.filteredApps = this.apps.results;
|
||||
if (apps.length > 0) {
|
||||
this.selectedApp = apps[0];
|
||||
this.filteredApps = event.detail.apps;
|
||||
}
|
||||
}
|
||||
|
||||
launchRequest(event: Event) {
|
||||
if (!isCustomEvent(event)) {
|
||||
|
@ -125,7 +130,7 @@ export class LibraryPage extends AKElement {
|
|||
}
|
||||
|
||||
renderSearch() {
|
||||
return html`<ak-library-list-search .apps="{this.apps.results}"></ak-library-list-search>`;
|
||||
return html`<ak-library-list-search .apps=${this.apps.results}></ak-library-list-search>`;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
Reference in a new issue