import type { ConversationResponse, FeedbackByPageResponse, FeedbackResponse, SearchResponse, } from './types.js'; export function filterSearchResponse( data: SearchResponse, filters: { query?: string; page?: string } ): SearchResponse { let searches = data.searches; if (filters.query) { const query = filters.query.toLowerCase(); searches = searches.filter((row) => row.searchQuery.toLowerCase().includes(query)); } const page = filters.page; if (page) { searches = searches.filter((row) => row.topClickedPage?.includes(page)); } return { ...data, searches }; } export function filterFeedbackByPageResponse( data: FeedbackByPageResponse, page?: string ): FeedbackByPageResponse { if (!page) return data; return { ...data, feedback: data.feedback.filter((row) => row.path.includes(page)) }; } export function filterFeedbackResponse(data: FeedbackResponse, page?: string): FeedbackResponse { if (!page) return data; return { ...data, feedback: data.feedback.filter((row) => row.path.includes(page)) }; } export function filterConversationResponse( data: ConversationResponse, page?: string ): ConversationResponse { if (!page) return data; return { ...data, conversations: data.conversations.filter((conversation) => conversation.sources.some((source) => source.url.includes(page)) ), }; }