From 3bcf2a265823071a579df6f14a6075c128f121cf Mon Sep 17 00:00:00 2001 From: Amoghavarsha Kudaligi Date: Mon, 9 Oct 2023 19:10:32 +0530 Subject: [PATCH 1/9] Handle sitemap report case. --- .../src/components/siteMapReport/index.tsx | 1 + .../siteReport/components/layout.tsx | 11 +++++++-- .../src/components/siteReport/index.tsx | 4 +++- .../siteReport/tabs/cookies/index.tsx | 24 ++++++++++++++++--- .../src/components/utils/reportDownloader.ts | 18 ++++++++++++-- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/packages/cli-dashboard/src/components/siteMapReport/index.tsx b/packages/cli-dashboard/src/components/siteMapReport/index.tsx index 1dc7c2e9b..f0ac6f709 100644 --- a/packages/cli-dashboard/src/components/siteMapReport/index.tsx +++ b/packages/cli-dashboard/src/components/siteMapReport/index.tsx @@ -198,6 +198,7 @@ const SiteMapReport = ({
{selectedSite ? ( { +interface LayoutProps { + selectedSite?: string; +} + +const Layout = ({ selectedSite }: LayoutProps) => { const { frameUrls } = useContentStore(({ state }) => ({ frameUrls: [ ...new Set( @@ -73,7 +77,10 @@ const Layout = () => { />
- +
); diff --git a/packages/cli-dashboard/src/components/siteReport/index.tsx b/packages/cli-dashboard/src/components/siteReport/index.tsx index c775f956f..df90ad41c 100644 --- a/packages/cli-dashboard/src/components/siteReport/index.tsx +++ b/packages/cli-dashboard/src/components/siteReport/index.tsx @@ -35,12 +35,14 @@ interface SiteReportProps { }; technologies: TechnologyData[]; completeJson: CompleteJson | null; + selectedSite?: string; } const SiteReport = ({ cookies, technologies, completeJson, + selectedSite, }: SiteReportProps) => { return ( - + ); }; diff --git a/packages/cli-dashboard/src/components/siteReport/tabs/cookies/index.tsx b/packages/cli-dashboard/src/components/siteReport/tabs/cookies/index.tsx index a60616d0d..6730ff049 100644 --- a/packages/cli-dashboard/src/components/siteReport/tabs/cookies/index.tsx +++ b/packages/cli-dashboard/src/components/siteReport/tabs/cookies/index.tsx @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import React, { useMemo } from 'react'; +import React, { useMemo, useCallback } from 'react'; import { prepareCookiesCount, prepareCookieStatsComponents, @@ -22,19 +22,22 @@ import { import { CookiesLanding, CookiesMatrix, + Button, } from '@cookie-analysis-tool/design-system'; /** * Internal dependencies. */ import CookiesListing from './cookieListing'; import { useContentStore } from '../../stateProviders/contentStore'; +import { reportDownloader } from '../../../utils/reportDownloader'; interface CookiesTabProps { selectedFrameUrl?: string | null; + selectedSite?: string | null; } -const CookiesTab = ({ selectedFrameUrl }: CookiesTabProps) => { - const { tabCookies } = useContentStore(({ state }) => ({ +const CookiesTab = ({ selectedFrameUrl, selectedSite }: CookiesTabProps) => { + const { tabCookies, completeJson } = useContentStore(({ state }) => ({ tabCookies: state.tabCookies, completeJson: state.completeJson, })); @@ -60,6 +63,16 @@ const CookiesTab = ({ selectedFrameUrl }: CookiesTabProps) => { ), [tabCookies] ); + const downloadReport = useCallback(() => { + if (!completeJson) { + return; + } + if (Array.isArray(completeJson)) { + reportDownloader(completeJson, selectedSite); + } else if (!Array.isArray(completeJson)) { + reportDownloader([completeJson]); + } + }, [completeJson, selectedSite]); return (
@@ -67,6 +80,11 @@ const CookiesTab = ({ selectedFrameUrl }: CookiesTabProps) => { ) : (
+