From c0f7f872caa88016a0617ffc089a7e38cb8b9013 Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Mon, 14 Jul 2025 14:14:53 +0200 Subject: [PATCH] Fix service filter in sidebar --- .../common/RepositorySidebarOverlay/index.tsx | 20 ++++++++++++++++++- .../Insights/hooks/useInsightsData.ts | 14 +++++++++++-- .../Insights/hooks/useInsightsStats.ts | 8 +++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/components/Admin/common/RepositorySidebarOverlay/index.tsx b/src/components/Admin/common/RepositorySidebarOverlay/index.tsx index 1f07697f8..200d80c76 100644 --- a/src/components/Admin/common/RepositorySidebarOverlay/index.tsx +++ b/src/components/Admin/common/RepositorySidebarOverlay/index.tsx @@ -71,7 +71,13 @@ export const RepositorySidebarOverlay = ({ const insightIdToOpenSuggestion = useAdminSelector( (state) => state.repository.issues.insightIdToOpenSuggestion ); - const { resetInsights, resetAssets, resetGlobalErrors } = useStore.getState(); + const { + resetInsights, + resetAssets, + resetGlobalErrors, + setSelectedServices, + clearInsightsFilters + } = useStore.getState(); const dispatch = useAdminDispatch(); const [history, setHistory] = useState( () => new History([]) @@ -212,6 +218,18 @@ export const RepositorySidebarOverlay = ({ dispatch ]); + // Set selected services on query change + useEffect(() => { + setSelectedServices(sidebarQuery?.query?.services ?? []); + }, [sidebarQuery?.query?.services, setSelectedServices]); + + // Clear insights filters on sidebar close + useEffect(() => { + if (!isSidebarOpen) { + clearInsightsFilters(); + } + }, [isSidebarOpen, clearInsightsFilters]); + const handleSidebarTransitionStart = () => { setIsSidebarTransitioning(true); }; diff --git a/src/components/Insights/hooks/useInsightsData.ts b/src/components/Insights/hooks/useInsightsData.ts index 7295b439a..ea09df553 100644 --- a/src/components/Insights/hooks/useInsightsData.ts +++ b/src/components/Insights/hooks/useInsightsData.ts @@ -1,5 +1,6 @@ import { useCallback, useEffect, useMemo } from "react"; import { getFeatureFlagValue } from "../../../featureFlags"; +import { platform } from "../../../platform"; import { useGetInsightsQuery, useGetIssuesQuery, @@ -50,7 +51,12 @@ export const useInsightsData = () => { const spanCodeObjectId = scope?.span?.spanCodeObjectId ?? null; const filteredServices = useMemo( - () => (spanCodeObjectId ? [] : selectedServices ?? []), + () => + spanCodeObjectId + ? platform === "Web" + ? selectedServices ?? [] + : [] + : selectedServices ?? [], [selectedServices, spanCodeObjectId] ); const filteredInsightTypes = spanCodeObjectId @@ -150,7 +156,11 @@ export const useInsightsData = () => { showDismissed, scopedSpanCodeObjectId: spanCodeObjectId ?? undefined, insightTypes: filteredInsightTypes, - services: spanCodeObjectId ? [] : filteredServices, + services: spanCodeObjectId + ? platform === "Web" + ? filteredServices + : [] + : filteredServices, ...(isCriticalityLevelsFilterEnabled ? { criticalityFilter: filteredCriticalityLevels } : {}), diff --git a/src/components/Insights/hooks/useInsightsStats.ts b/src/components/Insights/hooks/useInsightsStats.ts index 026208d04..e8d90aee5 100644 --- a/src/components/Insights/hooks/useInsightsStats.ts +++ b/src/components/Insights/hooks/useInsightsStats.ts @@ -1,5 +1,6 @@ import { useCallback, useMemo } from "react"; import { getFeatureFlagValue } from "../../../featureFlags"; +import { platform } from "../../../platform"; import { useGetInsightsStatsQuery } from "../../../redux/services/digma"; import { useConfigSelector } from "../../../store/config/useConfigSelector"; import { useInsightsSelector } from "../../../store/insights/useInsightsSelector"; @@ -37,7 +38,12 @@ export const useInsightsStats = ({ ? filteredInsightTypesInSpanScope : filteredInsightTypesInGlobalScope; const filteredServices = useMemo( - () => (spanCodeObjectId ? [] : services ?? []), + () => + spanCodeObjectId + ? platform === "Web" + ? services ?? [] + : [] + : services ?? [], [services, spanCodeObjectId] );