From 47f89efbbb28b38414d20347d5664bbaebb2ec92 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Tue, 8 Apr 2025 20:23:08 -0500 Subject: [PATCH] Filter group options in dropdown to include only those used by guide channels --- frontend/src/pages/Guide.jsx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/Guide.jsx b/frontend/src/pages/Guide.jsx index ca81c049..d87eef5b 100644 --- a/frontend/src/pages/Guide.jsx +++ b/frontend/src/pages/Guide.jsx @@ -591,21 +591,33 @@ export default function TVChannelGuide({ startDate, endDate }) { ); } - // Create group options for dropdown + // Create group options for dropdown - but only include groups used by guide channels const groupOptions = useMemo(() => { const options = [{ value: 'all', label: 'All Channel Groups' }]; - if (channelGroups) { - Object.values(channelGroups).forEach(group => { - options.push({ - value: group.id.toString(), - label: group.name - }); + if (channelGroups && guideChannels.length > 0) { + // Get unique channel group IDs from the channels that have program data + const usedGroupIds = new Set(); + guideChannels.forEach(channel => { + if (channel.channel_group?.id) { + usedGroupIds.add(channel.channel_group.id); + } }); + + // Only add groups that are actually used by channels in the guide + Object.values(channelGroups) + .filter(group => usedGroupIds.has(group.id)) + .sort((a, b) => a.name.localeCompare(b.name)) // Sort alphabetically + .forEach(group => { + options.push({ + value: group.id.toString(), + label: group.name + }); + }); } return options; - }, [channelGroups]); + }, [channelGroups, guideChannels]); // Create profile options for dropdown const profileOptions = useMemo(() => {