From 77735d9d7299447e0a1844293d70d804501a7e5a Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Mon, 31 Mar 2025 10:29:27 +0200 Subject: [PATCH] ui: use metadata as filter on click --- .../shared/SessionItem/SessionItem.tsx | 19 +++++++++---------- .../SessionMetaList/SessionMetaList.tsx | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frontend/app/components/shared/SessionItem/SessionItem.tsx b/frontend/app/components/shared/SessionItem/SessionItem.tsx index aad5fefa5..6168b0f58 100644 --- a/frontend/app/components/shared/SessionItem/SessionItem.tsx +++ b/frontend/app/components/shared/SessionItem/SessionItem.tsx @@ -81,25 +81,21 @@ const PREFETCH_STATE = { function SessionItem(props: RouteComponentProps & Props) { const { location } = useHistory(); - const { settingsStore, sessionStore } = useStore(); + const { settingsStore, sessionStore, searchStore, searchStoreLive } = useStore(); const { timezone, shownTimezone } = settingsStore.sessionSettings; const { t } = useTranslation(); const [prefetchState, setPrefetched] = useState(PREFETCH_STATE.none); - // Destructure all props at the top const { session, onUserClick = () => null, hasUserFilter = false, disableUser = false, - metaList = [], lastPlayedSessionId, onClick = null, compact = false, ignoreAssist = false, - bookmarked = false, query, - // location, isDisabled, live: propsLive, isAdd, @@ -131,7 +127,6 @@ function SessionItem(props: RouteComponentProps & Props) { agentIds, } = session; - // Memoize derived values const queryParams = useMemo( () => Object.fromEntries(new URLSearchParams(location.search)), [location.search], @@ -164,7 +159,6 @@ function SessionItem(props: RouteComponentProps & Props) { const isMultiviewDisabled = isDisabled && location.pathname.includes('multiview'); - // Memoize metadata list creation const _metaList = useMemo(() => { return Object.keys(metadata).map((key) => ({ label: key, @@ -172,7 +166,6 @@ function SessionItem(props: RouteComponentProps & Props) { })); }, [metadata]); - // Memoize event handlers const handleHover = useCallback(async () => { if (prefetchState !== PREFETCH_STATE.none || live || isAssist || isMobile) return; @@ -226,7 +219,6 @@ function SessionItem(props: RouteComponentProps & Props) { return formatTimeOrDate(startedAt, timezoneToUse); }, [startedAt, shownTimezone, userTimezone, timezone]); - // Memoize tooltip content const timeTooltipContent = useMemo(() => { return (
@@ -252,6 +244,13 @@ function SessionItem(props: RouteComponentProps & Props) { ); }, [startedAt, timezone, userTimezone]); + const onMetaClick = (meta: { name: string, value: string }) => { + if (isAssist) { + searchStoreLive.addFilterByKeyAndValue(meta.name, meta.value) + } else { + searchStore.addFilterByKeyAndValue(meta.name, meta.value); + } + } return (
{_metaList.length > 0 && ( - + )} )} diff --git a/frontend/app/components/shared/SessionItem/SessionMetaList/SessionMetaList.tsx b/frontend/app/components/shared/SessionItem/SessionMetaList/SessionMetaList.tsx index 4ceb4f3fe..3c7608138 100644 --- a/frontend/app/components/shared/SessionItem/SessionMetaList/SessionMetaList.tsx +++ b/frontend/app/components/shared/SessionItem/SessionMetaList/SessionMetaList.tsx @@ -7,6 +7,7 @@ interface Props { className?: string; metaList: any[]; maxLength?: number; + onMetaClick?: (meta: { name: string, value: string }) => void; } export default function SessionMetaList(props: Props) { @@ -15,9 +16,9 @@ export default function SessionMetaList(props: Props) { return (
{metaList.slice(0, maxLength).map(({ label, value }, index) => ( - - - +
props.onMetaClick?.({ name: `_${label}`, value })}> + +
))} {metaList.length > maxLength && (