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:
Ken Sternberg 2023-05-24 11:51:49 -07:00 committed by GitHub
parent 4230d8ee20
commit 7c43c1a05b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -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;

View File

@ -85,8 +85,13 @@ 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];
this.filteredApps = event.detail.apps;
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) {
@ -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() {