@google-psat/report 0.9.0-3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/dashboard/components/cookiesWithIssues/index.js +43 -0
  2. package/dist/dashboard/components/header/index.js +26 -0
  3. package/dist/dashboard/components/siteMapReport/cookies.js +73 -0
  4. package/dist/dashboard/components/siteMapReport/index.js +31 -0
  5. package/dist/dashboard/components/siteMapReport/layout.js +140 -0
  6. package/dist/dashboard/components/siteMapReport/sidebarData.js +46 -0
  7. package/dist/dashboard/components/siteMapReport/sitemapCookiesWithIssues.js +9 -0
  8. package/dist/dashboard/components/siteReport/components/layout.js +145 -0
  9. package/dist/dashboard/components/siteReport/index.js +33 -0
  10. package/dist/dashboard/components/siteReport/stateProviders/contentStore/index.js +55 -0
  11. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/blockedCookiesSection.js +79 -0
  12. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/cookiesSection.js +38 -0
  13. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/exemptedCookiesSection.js +63 -0
  14. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/framesSection.js +38 -0
  15. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/index.js +17 -0
  16. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/knownBreakages.js +53 -0
  17. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/landing.js +106 -0
  18. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/index.js +58 -0
  19. package/dist/dashboard/components/siteReport/tabs/cookies/cookiesListing/index.js +47 -0
  20. package/dist/dashboard/components/siteReport/tabs/cookies/index.js +56 -0
  21. package/dist/dashboard/components/siteReport/tabs/index.js +54 -0
  22. package/dist/dashboard/components/siteReport/tabs/siteCookiesWithIssues/index.js +29 -0
  23. package/dist/dashboard/components/siteReport/tabs/technologies/index.js +91 -0
  24. package/dist/dashboard/components/utils/NamePrefixIconSelector.js +67 -0
  25. package/dist/dashboard/components/utils/extractCookies.js +36 -0
  26. package/dist/dashboard/components/utils/extractReportData.js +56 -0
  27. package/dist/dashboard/components/utils/reportDownloader/generateSiteMapReportandDownload.js +44 -0
  28. package/dist/dashboard/components/utils/reportDownloader/generateSiteReportandDownload.js +52 -0
  29. package/dist/dashboard/components/utils/reportDownloader/index.js +17 -0
  30. package/dist/dashboard/components/utils/reportDownloader/utils.js +148 -0
  31. package/dist/dashboard/components/utils/reshapeCookies.js +97 -0
  32. package/dist/dashboard/components/utils/tests/data.mock.js +176 -0
  33. package/dist/dashboard/components/utils/tests/extractCookies.js +84 -0
  34. package/dist/dashboard/components/utils/tests/extractReportData.js +64 -0
  35. package/dist/dashboard/components/utils/tests/reshapeCookies.js +89 -0
  36. package/dist/dashboard/hooks/useCookieListing/index.js +412 -0
  37. package/dist/dashboard/index.js +19 -0
  38. package/dist/index.js +16 -0
  39. package/dist-types/dashboard/components/cookiesWithIssues/index.d.ts +8 -0
  40. package/dist-types/dashboard/components/header/index.d.ts +6 -0
  41. package/dist-types/dashboard/components/siteMapReport/cookies.d.ts +15 -0
  42. package/dist-types/dashboard/components/siteMapReport/index.d.ts +11 -0
  43. package/dist-types/dashboard/components/siteMapReport/layout.d.ts +18 -0
  44. package/dist-types/dashboard/components/siteMapReport/sidebarData.d.ts +3 -0
  45. package/dist-types/dashboard/components/siteMapReport/sitemapCookiesWithIssues.d.ts +10 -0
  46. package/dist-types/dashboard/components/siteReport/components/layout.d.ts +13 -0
  47. package/dist-types/dashboard/components/siteReport/index.d.ts +17 -0
  48. package/dist-types/dashboard/components/siteReport/stateProviders/contentStore/index.d.ts +32 -0
  49. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/blockedCookiesSection.d.ts +8 -0
  50. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/cookiesSection.d.ts +7 -0
  51. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/exemptedCookiesSection.d.ts +7 -0
  52. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/framesSection.d.ts +2 -0
  53. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/index.d.ts +2 -0
  54. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/knownBreakages.d.ts +9 -0
  55. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/cookieLanding/landing.d.ts +15 -0
  56. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesLandingContainer/index.d.ts +23 -0
  57. package/dist-types/dashboard/components/siteReport/tabs/cookies/cookiesListing/index.d.ts +9 -0
  58. package/dist-types/dashboard/components/siteReport/tabs/cookies/index.d.ts +9 -0
  59. package/dist-types/dashboard/components/siteReport/tabs/index.d.ts +3 -0
  60. package/dist-types/dashboard/components/siteReport/tabs/siteCookiesWithIssues/index.d.ts +5 -0
  61. package/dist-types/dashboard/components/siteReport/tabs/technologies/index.d.ts +5 -0
  62. package/dist-types/dashboard/components/utils/NamePrefixIconSelector.d.ts +3 -0
  63. package/dist-types/dashboard/components/utils/extractCookies.d.ts +6 -0
  64. package/dist-types/dashboard/components/utils/extractReportData.d.ts +11 -0
  65. package/dist-types/dashboard/components/utils/reportDownloader/generateSiteMapReportandDownload.d.ts +4 -0
  66. package/dist-types/dashboard/components/utils/reportDownloader/generateSiteReportandDownload.d.ts +4 -0
  67. package/dist-types/dashboard/components/utils/reportDownloader/index.d.ts +2 -0
  68. package/dist-types/dashboard/components/utils/reportDownloader/utils.d.ts +9 -0
  69. package/dist-types/dashboard/components/utils/reshapeCookies.d.ts +8 -0
  70. package/dist-types/dashboard/components/utils/tests/data.mock.d.ts +6 -0
  71. package/dist-types/dashboard/components/utils/tests/extractCookies.d.ts +1 -0
  72. package/dist-types/dashboard/components/utils/tests/extractReportData.d.ts +1 -0
  73. package/dist-types/dashboard/components/utils/tests/reshapeCookies.d.ts +1 -0
  74. package/dist-types/dashboard/hooks/useCookieListing/index.d.ts +10 -0
  75. package/dist-types/dashboard/index.d.ts +4 -0
  76. package/dist-types/index.d.ts +1 -0
  77. package/package.json +11 -5
  78. package/public/index.html +1 -0
  79. package/tsconfig.json +19 -3
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import { useState } from 'react';
21
+ import { Resizable } from 're-resizable';
22
+ import {} from '@google-psat/common';
23
+ import { CookieTable, CookieDetails } from '@google-psat/design-system';
24
+ /**
25
+ * Internal dependencies.
26
+ */
27
+ import useCookieListing from '../../hooks/useCookieListing';
28
+ const CookiesWithIssues = ({ cookies, selectedSite, hostName, }) => {
29
+ const [selectedFrameCookie, setSelectedFrameCookie] = useState(null);
30
+ const { tableColumns, filters, searchKeys, tablePersistentSettingsKey } = useCookieListing(cookies, 'frame', 'cookiesWithIssuesListing', selectedSite);
31
+ //@ts-ignore -- PSAT_EXTENSTION is added only when the report is downloaded from the extension. Since optional chaining is done it will return false if it doesnt exist.
32
+ const isCLI = globalThis?.PSAT_EXTENSION ? false : true;
33
+ return (_jsxs("div", { className: "w-full h-full flex flex-col", children: [_jsx(Resizable, { defaultSize: {
34
+ width: '100%',
35
+ height: '80%',
36
+ }, minHeight: "6%", maxHeight: "95%", enable: {
37
+ top: false,
38
+ right: false,
39
+ bottom: true,
40
+ left: false,
41
+ }, className: "h-full flex", children: _jsx(CookieTable, { data: cookies, tableColumns: tableColumns, tableFilters: filters, tableSearchKeys: searchKeys, tablePersistentSettingsKey: tablePersistentSettingsKey, selectedFrame: selectedSite, selectedFrameCookie: selectedFrameCookie, hideExport: true, setSelectedFrameCookie: setSelectedFrameCookie, isCLI: isCLI, hostname: hostName }) }), _jsx(CookieDetails, { selectedFrameCookie: selectedFrameCookie, isUsingCDP: true })] }));
42
+ };
43
+ export default CookiesWithIssues;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import { PrivacySandboxColoredIcon } from '@google-psat/design-system';
21
+ const Header = ({ url, dateTime }) => {
22
+ // @ts-ignore - Global object.
23
+ const isExtension = globalThis?.PSAT_EXTENSION;
24
+ return (_jsxs("div", { className: "flex justify-between gap-3 px-4 py-2", children: [_jsxs("div", { className: "flex gap-2 items-center", children: [_jsx(PrivacySandboxColoredIcon, { className: "w-[40px] h-[40px]" }), _jsxs("div", { children: [url && _jsx("p", { className: "text-xs mb-[1px]", children: url }), _jsx("p", { className: "text-xs mb-[1px]", children: dateTime })] })] }), _jsx("div", { className: "flex items-center text-cente", children: isExtension ? 'PSAT Extension Analysis' : 'PSAT CLI Analysis' })] }));
25
+ };
26
+ export default Header;
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import { useCallback, useMemo, useState } from 'react';
21
+ import { noop, } from '@google-psat/common';
22
+ import { useSidebar } from '@google-psat/design-system';
23
+ /**
24
+ * Internal dependencies.
25
+ */
26
+ import AssembledCookiesLanding from '../siteReport/tabs/cookies/cookiesLandingContainer';
27
+ import SiteReport from '../siteReport';
28
+ import { generateSiteMapReportandDownload } from '../utils/reportDownloader';
29
+ import extractCookies from '../utils/extractCookies';
30
+ const CookiesTab = ({ selectedSite, tabCookies, tabFrames, completeJson, path, libraryMatches, query = '', clearQuery = noop, }) => {
31
+ const isKeySelected = useSidebar(({ actions }) => actions.isKeySelected);
32
+ const [appliedFilters, setAppliedFilters] = useState({});
33
+ const [siteMapLibraryMatches, libraryMatchesUrlCount] = useMemo(() => {
34
+ const _libraryMatchesUrlCount = {};
35
+ const _siteMapLibraryMatches = completeJson?.reduce((acc, data) => {
36
+ const _libraryMatches = data.libraryMatches;
37
+ Object.keys(_libraryMatches).forEach((key) => {
38
+ acc[key] =
39
+ // @ts-ignore
40
+ acc[key]?.matches?.length || acc[key]?.domQuerymatches?.length
41
+ ? acc[key]
42
+ : _libraryMatches[key];
43
+ if (Object.keys(_libraryMatches[key]?.matches ?? {}).length ||
44
+ Object.keys(_libraryMatches[key]?.domQuerymatches ?? {}).length) {
45
+ _libraryMatchesUrlCount[key] =
46
+ (_libraryMatchesUrlCount[key] || 0) + 1;
47
+ }
48
+ });
49
+ return acc;
50
+ }, {}) || {};
51
+ return [_siteMapLibraryMatches, _libraryMatchesUrlCount];
52
+ }, [completeJson]);
53
+ const downloadReport = useCallback(async () => {
54
+ if (!Array.isArray(completeJson)) {
55
+ return;
56
+ }
57
+ await generateSiteMapReportandDownload(completeJson, appliedFilters, path);
58
+ }, [appliedFilters, completeJson, path]);
59
+ const [siteFilteredCookies, siteFilteredTechnologies, siteFilteredCompleteJson,] = useMemo(() => {
60
+ const reportData = completeJson?.find((data) => isKeySelected(data.pageUrl));
61
+ if (!reportData) {
62
+ return [{}, [], null];
63
+ }
64
+ const _cookies = extractCookies(reportData.cookieData, '', true);
65
+ const _technologies = reportData.technologyData;
66
+ return [_cookies, _technologies, [reportData]];
67
+ }, [completeJson, isKeySelected]);
68
+ const sitemapPath =
69
+ // @ts-ignore - Global object
70
+ globalThis?.PSAT_DATA?.siteMapUrl || globalThis?.PSAT_DATA?.selectedSite;
71
+ return (_jsx(_Fragment, { children: !selectedSite ? (_jsx(AssembledCookiesLanding, { tabCookies: tabCookies, tabFrames: tabFrames, libraryMatches: siteMapLibraryMatches, libraryMatchesUrlCount: libraryMatchesUrlCount, downloadReport: downloadReport, menuBarScrollContainerId: "dashboard-sitemap-layout-container", setAppliedFilters: setAppliedFilters, query: query, clearQuery: clearQuery, url: sitemapPath })) : (_jsx(SiteReport, { cookies: siteFilteredCookies, technologies: siteFilteredTechnologies, completeJson: siteFilteredCompleteJson, selectedSite: selectedSite || '', path: path, libraryMatches: libraryMatches && selectedSite ? libraryMatches[selectedSite] : {}, query: query, clearQuery: clearQuery })) }));
72
+ };
73
+ export default CookiesTab;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import { useState } from 'react';
21
+ import { SidebarProvider } from '@google-psat/design-system';
22
+ /**
23
+ * Internal dependencies.
24
+ */
25
+ import sidebarData from './sidebarData';
26
+ import Layout from './layout';
27
+ const SiteMapReport = ({ landingPageCookies, completeJson, path, libraryMatches, }) => {
28
+ const [data, setData] = useState(sidebarData);
29
+ return (_jsx(SidebarProvider, { data: data, children: _jsx(Layout, { landingPageCookies: landingPageCookies, completeJson: completeJson, sidebarData: data, setSidebarData: setData, path: path, libraryMatches: libraryMatches }) }));
30
+ };
31
+ export default SiteMapReport;
@@ -0,0 +1,140 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import React, { useEffect, useMemo, useState } from 'react';
21
+ import { Resizable } from 're-resizable';
22
+ import { noop, } from '@google-psat/common';
23
+ import { useSidebar, Sidebar, SIDEBAR_ITEMS_KEYS, File, FileWhite, } from '@google-psat/design-system';
24
+ /**
25
+ * Internal dependencies.
26
+ */
27
+ import SiteMapCookiesWithIssues from './sitemapCookiesWithIssues';
28
+ import reshapeCookies from '../utils/reshapeCookies';
29
+ import CookiesTab from './cookies';
30
+ const Layout = ({ landingPageCookies, completeJson, sidebarData, setSidebarData, path, libraryMatches, }) => {
31
+ const [sites, setSites] = useState([]);
32
+ useEffect(() => {
33
+ const _sites = new Set();
34
+ completeJson?.forEach(({ pageUrl }) => {
35
+ _sites.add(pageUrl);
36
+ });
37
+ setSites(Array.from(_sites));
38
+ }, [completeJson]);
39
+ const reshapedCookies = useMemo(() => reshapeCookies(landingPageCookies), [landingPageCookies]);
40
+ const cookiesWithIssues = useMemo(() => Object.fromEntries(Object.entries(reshapedCookies).filter(([, cookie]) => cookie.isBlocked || cookie.blockedReasons?.length)), [reshapedCookies]);
41
+ const { activePanel, selectedItemKey, updateSelectedItemKey, isKeySelected } = useSidebar(({ state, actions }) => ({
42
+ activePanel: state.activePanel,
43
+ selectedItemKey: state.selectedItemKey,
44
+ updateSelectedItemKey: actions.updateSelectedItemKey,
45
+ isKeySelected: actions.isKeySelected,
46
+ }));
47
+ const { Element: PanelElement, props } = activePanel.panel;
48
+ const { query } = activePanel;
49
+ const clearQuery = useMemo(() => {
50
+ return query ? activePanel.clearQuery : noop;
51
+ }, [query, activePanel.clearQuery]);
52
+ const doesSiteHaveCookies = useMemo(() => {
53
+ const store = {};
54
+ completeJson?.forEach((data) => {
55
+ store[data.pageUrl] = Object.entries(data.cookieData).reduce((acc, [, frameData]) => {
56
+ return acc || Object.keys(frameData.frameCookies || {}).length > 0;
57
+ }, false);
58
+ });
59
+ return store;
60
+ }, [completeJson]);
61
+ const tabFrames = useMemo(() => sites.reduce((acc, site) => {
62
+ acc[site] = {};
63
+ return acc;
64
+ }, {}), [sites]);
65
+ useEffect(() => {
66
+ setSidebarData((prev) => {
67
+ const _data = { ...prev };
68
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES].panel = {
69
+ Element: CookiesTab,
70
+ props: {
71
+ tabCookies: reshapedCookies,
72
+ tabFrames,
73
+ completeJson,
74
+ path,
75
+ libraryMatches,
76
+ query,
77
+ clearQuery,
78
+ },
79
+ };
80
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES].children = sites.reduce((acc, site) => {
81
+ acc[site] = {
82
+ title: site,
83
+ panel: {
84
+ Element: CookiesTab,
85
+ props: {
86
+ selectedSite: site,
87
+ tabCookies: reshapedCookies,
88
+ tabFrames,
89
+ completeJson,
90
+ path,
91
+ libraryMatches,
92
+ query,
93
+ clearQuery,
94
+ },
95
+ },
96
+ children: {},
97
+ icon: {
98
+ //@ts-ignore
99
+ Element: File,
100
+ },
101
+ selectedIcon: {
102
+ //@ts-ignore
103
+ Element: FileWhite,
104
+ },
105
+ isBlurred: doesSiteHaveCookies[site] === false,
106
+ };
107
+ return acc;
108
+ }, {});
109
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES_WITH_ISSUES].panel = {
110
+ Element: SiteMapCookiesWithIssues,
111
+ props: {
112
+ cookies: Object.values(cookiesWithIssues),
113
+ path,
114
+ },
115
+ };
116
+ return _data;
117
+ });
118
+ }, [
119
+ clearQuery,
120
+ completeJson,
121
+ cookiesWithIssues,
122
+ doesSiteHaveCookies,
123
+ libraryMatches,
124
+ path,
125
+ query,
126
+ reshapedCookies,
127
+ setSidebarData,
128
+ sites,
129
+ tabFrames,
130
+ ]);
131
+ useEffect(() => {
132
+ if (selectedItemKey === null && Object.keys(sidebarData).length > 0) {
133
+ updateSelectedItemKey(SIDEBAR_ITEMS_KEYS.COOKIES);
134
+ }
135
+ }, [isKeySelected, selectedItemKey, sidebarData, updateSelectedItemKey]);
136
+ return (_jsxs("div", { className: "w-full h-screen flex", children: [_jsx(Resizable, { defaultSize: { width: '200px', height: '100%' }, minWidth: '150px', maxWidth: '50%', enable: {
137
+ right: true,
138
+ }, children: _jsx(Sidebar, {}) }), _jsx("div", { className: "flex-1 max-h-screen overflow-auto", children: PanelElement && _jsx(PanelElement, { ...props }) })] }));
139
+ };
140
+ export default Layout;
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * External dependencies
18
+ */
19
+ import { I18n } from '@google-psat/i18n';
20
+ import { SIDEBAR_ITEMS_KEYS, WarningBare, } from '@google-psat/design-system';
21
+ const sidebarData = {
22
+ [SIDEBAR_ITEMS_KEYS.COOKIES]: {
23
+ title: () => 'Aggregated Report',
24
+ children: {},
25
+ dropdownOpen: true,
26
+ },
27
+ [SIDEBAR_ITEMS_KEYS.COOKIES_WITH_ISSUES]: {
28
+ title: () => I18n.getMessage('cookieIssues'),
29
+ children: {},
30
+ icon: {
31
+ //@ts-ignore
32
+ Element: WarningBare,
33
+ props: {
34
+ className: 'fill-granite-gray',
35
+ },
36
+ },
37
+ selectedIcon: {
38
+ //@ts-ignore
39
+ Element: WarningBare,
40
+ props: {
41
+ className: 'fill-white',
42
+ },
43
+ },
44
+ },
45
+ };
46
+ export default sidebarData;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Internal dependencies.
4
+ */
5
+ import CookiesWithIssues from '../cookiesWithIssues';
6
+ const SiteMapCookiesWithIssues = ({ cookies, path, }) => {
7
+ return (_jsx(CookiesWithIssues, { cookies: cookies, selectedSite: null, hostName: path }));
8
+ };
9
+ export default SiteMapCookiesWithIssues;
@@ -0,0 +1,145 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import React, { useEffect, useMemo, useRef } from 'react';
21
+ import { Resizable } from 're-resizable';
22
+ import { I18n } from '@google-psat/i18n';
23
+ import { noop } from '@google-psat/common';
24
+ import { Sidebar, useSidebar, SIDEBAR_ITEMS_KEYS, CookieIcon, CookieIconWhite, SiteBoundariesIcon, SiteBoundariesIconWhite, } from '@google-psat/design-system';
25
+ /**
26
+ * Internal dependencies.
27
+ */
28
+ import { useContentStore } from '../stateProviders/contentStore';
29
+ import CookiesTab from '../tabs/cookies';
30
+ import SiteCookiesWithIssues from '../tabs/siteCookiesWithIssues';
31
+ import Technologies from '../tabs/technologies';
32
+ const Layout = ({ selectedSite, setSidebarData, query = '', clearQuery = noop, }) => {
33
+ const { technologies, completeJson } = useContentStore(({ state }) => ({
34
+ technologies: state.technologies,
35
+ completeJson: state.completeJson,
36
+ }));
37
+ const frameUrls = useMemo(() => {
38
+ const frames = Object.keys(completeJson?.[0].cookieData ?? {});
39
+ return frames.filter((url) => url?.includes('http'));
40
+ }, [completeJson]);
41
+ const { activePanel, selectedItemKey, updateSelectedItemKey } = useSidebar(({ state, actions }) => ({
42
+ activePanel: state.activePanel,
43
+ selectedItemKey: state.selectedItemKey,
44
+ updateSelectedItemKey: actions.updateSelectedItemKey,
45
+ }));
46
+ const { Element: PanelElement, props } = activePanel.panel;
47
+ const _clearQuery = useMemo(() => (query ? clearQuery : noop), [query, clearQuery]);
48
+ useEffect(() => {
49
+ setSidebarData((prev) => {
50
+ const _data = { ...prev };
51
+ const keys = selectedItemKey?.split('#') ?? [];
52
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES].panel = {
53
+ Element: CookiesTab,
54
+ props: {
55
+ selectedFrameUrl: null,
56
+ selectedSite,
57
+ isSiteMapLandingContainer: false,
58
+ query,
59
+ clearQuery: _clearQuery,
60
+ url: completeJson && completeJson?.length > 1
61
+ ? selectedSite
62
+ : completeJson?.[0]?.pageUrl,
63
+ },
64
+ };
65
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES].children = frameUrls.reduce((acc, url) => {
66
+ acc[url] = {
67
+ title: url,
68
+ panel: {
69
+ Element: CookiesTab,
70
+ props: {
71
+ selectedFrameUrl: keys[keys.length - 1],
72
+ selectedSite,
73
+ },
74
+ },
75
+ children: {},
76
+ icon: {
77
+ //@ts-ignore
78
+ Element: CookieIcon,
79
+ },
80
+ selectedIcon: {
81
+ //@ts-ignore
82
+ Element: CookieIconWhite,
83
+ },
84
+ isBlurred: Object.keys(completeJson?.[0].cookieData?.[url]?.frameCookies || {}).length === 0,
85
+ };
86
+ return acc;
87
+ }, {});
88
+ _data[SIDEBAR_ITEMS_KEYS.COOKIES_WITH_ISSUES].panel = {
89
+ Element: SiteCookiesWithIssues,
90
+ props: {
91
+ selectedSite,
92
+ },
93
+ };
94
+ if (technologies && technologies.length > 0) {
95
+ _data[SIDEBAR_ITEMS_KEYS.TECHNOLOGIES] = {
96
+ title: I18n.getMessage('technologies'),
97
+ children: {},
98
+ icon: {
99
+ //@ts-ignore
100
+ Element: SiteBoundariesIcon,
101
+ },
102
+ selectedIcon: {
103
+ //@ts-ignore
104
+ Element: SiteBoundariesIconWhite,
105
+ },
106
+ panel: {
107
+ Element: Technologies,
108
+ props: {
109
+ selectedSite,
110
+ },
111
+ },
112
+ };
113
+ }
114
+ else {
115
+ delete _data[SIDEBAR_ITEMS_KEYS.TECHNOLOGIES];
116
+ }
117
+ return _data;
118
+ });
119
+ }, [
120
+ _clearQuery,
121
+ completeJson,
122
+ frameUrls,
123
+ query,
124
+ selectedItemKey,
125
+ selectedSite,
126
+ setSidebarData,
127
+ technologies,
128
+ ]);
129
+ useEffect(() => {
130
+ if (selectedItemKey === null) {
131
+ updateSelectedItemKey(SIDEBAR_ITEMS_KEYS.COOKIES);
132
+ }
133
+ }, [clearQuery, selectedItemKey, updateSelectedItemKey]);
134
+ const lastSelectedSite = useRef(null);
135
+ useEffect(() => {
136
+ if (selectedSite !== lastSelectedSite.current) {
137
+ updateSelectedItemKey(SIDEBAR_ITEMS_KEYS.COOKIES);
138
+ lastSelectedSite.current = selectedSite;
139
+ }
140
+ }, [selectedSite, updateSelectedItemKey]);
141
+ return (_jsxs("div", { className: "w-full h-full flex", children: [_jsx(Resizable, { defaultSize: { width: '200px', height: '100%' }, minWidth: '150px', maxWidth: '60%', enable: {
142
+ right: true,
143
+ }, children: _jsx(Sidebar, {}) }), _jsx("div", { className: "flex-1 max-h-screen overflow-auto", children: PanelElement && _jsx(PanelElement, { ...props }) })] }));
144
+ };
145
+ export default Layout;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies
19
+ */
20
+ import { useState } from 'react';
21
+ import { noop, } from '@google-psat/common';
22
+ import { SidebarProvider } from '@google-psat/design-system';
23
+ /**
24
+ * Internal dependencies.
25
+ */
26
+ import { Provider as ContentStoreProvider } from './stateProviders/contentStore';
27
+ import Layout from './components/layout';
28
+ import Tabs from './tabs';
29
+ const SiteReport = ({ cookies, technologies, completeJson, selectedSite, path, libraryMatches, query = '', clearQuery = noop, }) => {
30
+ const [data, setData] = useState(Tabs);
31
+ return (_jsx(ContentStoreProvider, { cookies: cookies, technologies: technologies, completeJson: completeJson, libraryMatches: libraryMatches, path: path, children: _jsx(SidebarProvider, { data: data, children: _jsx(Layout, { selectedSite: selectedSite, setSidebarData: setData, query: query, clearQuery: clearQuery }) }) }));
32
+ };
33
+ export default SiteReport;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * External dependencies.
19
+ */
20
+ import { useMemo } from 'react';
21
+ import { useContextSelector, createContext, } from '@google-psat/common';
22
+ /**
23
+ * Internal dependencies.
24
+ */
25
+ import reshapeCookies from '../../../utils/reshapeCookies';
26
+ const initialState = {
27
+ state: {
28
+ tabCookies: {},
29
+ technologies: [],
30
+ completeJson: null,
31
+ path: '',
32
+ libraryMatches: null,
33
+ },
34
+ };
35
+ export const Context = createContext(initialState);
36
+ export const Provider = ({ cookies, technologies, completeJson, children, path, libraryMatches, }) => {
37
+ const tabCookies = useMemo(() => reshapeCookies(cookies), [cookies]);
38
+ return (_jsx(Context.Provider, { value: {
39
+ state: {
40
+ tabCookies,
41
+ technologies,
42
+ completeJson,
43
+ path,
44
+ libraryMatches,
45
+ },
46
+ }, children: children }));
47
+ };
48
+ /**
49
+ * Cookie store hook.
50
+ * @param selector Selector function to partially select state.
51
+ * @returns selected part of the state
52
+ */
53
+ export function useContentStore(selector = (state) => state) {
54
+ return useContextSelector(Context, selector);
55
+ }