From 7c43c1a05b2fbc3f42841f6427f9b9b4bdf83141 Mon Sep 17 00:00:00 2001 From: Ken Sternberg <133134217+kensternberg-authentik@users.noreply.github.com> Date: Wed, 24 May 2023 11:51:49 -0700 Subject: [PATCH] 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. --- web/src/user/LibraryPage/ApplicationSearch.ts | 9 ++------- web/src/user/LibraryPage/LibraryPageImpl.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/web/src/user/LibraryPage/ApplicationSearch.ts b/web/src/user/LibraryPage/ApplicationSearch.ts index a37975f67..c6c104223 100644 --- a/web/src/user/LibraryPage/ApplicationSearch.ts +++ b/web/src/user/LibraryPage/ApplicationSearch.ts @@ -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[] { - 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[]) { - 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; diff --git a/web/src/user/LibraryPage/LibraryPageImpl.ts b/web/src/user/LibraryPage/LibraryPageImpl.ts index ce75cc9f3..9f8d50e26 100644 --- a/web/src/user/LibraryPage/LibraryPageImpl.ts +++ b/web/src/user/LibraryPage/LibraryPageImpl.ts @@ -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``; + return html``; } render() {