Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add context provider to sidebar #498

Merged
merged 42 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c6874ed
Move useContextSelector to common package
mayan-000 Feb 15, 2024
aa5167e
perf: improve conditional check for array of objects
mayan-000 Feb 15, 2024
002f331
ref: import useContextSelector from common package
mayan-000 Feb 15, 2024
01301d5
pef: add provider to useSidebar hook
mayan-000 Feb 15, 2024
94927ca
ref: break UI to new component for using useSidebar hook
mayan-000 Feb 15, 2024
080009c
Merge branch 'ref/move-context-selector' into ref/provider-to-sidebar
mayan-000 Feb 15, 2024
6b3d980
ref: import useContextSelector from common package
mayan-000 Feb 15, 2024
8e84257
ref: use callbacks to render UI elements
mayan-000 Feb 15, 2024
0dbcb5d
fix: conditionally update dropdown flag on cookies menu item
mayan-000 Feb 15, 2024
d11bb02
use context-selector inside components
mayan-000 Feb 15, 2024
fae277c
use context-selector in siteReport component
mayan-000 Feb 15, 2024
01f10a3
use context-selector in siteMapReport component
mayan-000 Feb 15, 2024
8cad0af
feat: add new key for allowing query string for activePanel
mayan-000 Feb 20, 2024
cf1c60c
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Feb 20, 2024
ae88bc7
Basic setup of UI
mayan-000 Feb 20, 2024
0f66f5a
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Feb 21, 2024
be86aa1
Squashed commit of the following:
mayan-000 Feb 21, 2024
3231895
Merge branch 'develop' into ref/move-context-selector
mayan-000 Feb 21, 2024
8e925a3
Merge branch 'ref/move-context-selector' into ref/provider-to-sidebar
mayan-000 Feb 21, 2024
8d19cf5
fix: remove managing of dropdown flag from layout
mayan-000 Feb 21, 2024
b9a6f64
fix: remove component state and use from props
mayan-000 Feb 26, 2024
7b3272e
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Feb 26, 2024
caf8901
Squashed commit of the following:
mayan-000 Feb 29, 2024
005f57d
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Mar 1, 2024
9bf6c6c
resolve merge issues
mayan-000 Mar 1, 2024
440a9bf
remove unused files
mayan-000 Mar 1, 2024
09058f4
fix: loop to find deepest child
mayan-000 Mar 1, 2024
67389ac
test: add sidebar util tests
mayan-000 Mar 1, 2024
2312f15
Small refactoring
mohdsayed Mar 5, 2024
a4702c1
ref: introduce new type for rendering and storing react componens thr…
mayan-000 Mar 6, 2024
0d92751
ref: use util for tabId
mayan-000 Mar 6, 2024
927a19e
ref: use session storage with new key to store selected item
mayan-000 Mar 6, 2024
27edc62
test: fix testcases
mayan-000 Mar 6, 2024
bcf6ba8
fix: create tabId entry to keep persistence
mayan-000 Mar 6, 2024
d62ce45
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Mar 21, 2024
f83be09
chore: add jsdoc to utils
mayan-000 Mar 25, 2024
d0d9087
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Mar 27, 2024
248db60
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Mar 29, 2024
1f5fd60
ref: break sidebar context to separate files
mayan-000 Apr 2, 2024
4c9e9ff
Move Context Invalidated logic to a custom hook
mohdsayed Apr 2, 2024
b7fd7ae
Merge branch 'develop' into ref/provider-to-sidebar
mayan-000 Apr 3, 2024
86fa586
use inspectedWindow.tabId instead of getCurrentTabId callback
mayan-000 Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 13 additions & 172 deletions packages/cli-dashboard/src/components/siteMapReport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,22 @@
/**
* External dependencies.
*/
import React, { useEffect, useMemo, useState } from 'react';
import { Resizable } from 're-resizable';
import React, { useState } from 'react';
import {
File,
FileWhite,
Sidebar,
useSidebar,
SidebarProvider,
type SidebarItems,
} from '@ps-analysis-tool/design-system';
import {
type TabFrames,
type TechnologyData,
UNKNOWN_FRAME_KEY,
type CookieFrameStorageType,
type CompleteJson,
} from '@ps-analysis-tool/common';

/**
* Internal dependencies.
*/
import SiteReport from '../siteReport';
import SiteMapCookiesWithIssues from './sitemapCookiesWithIssues';
import CookiesLandingContainer from '../siteReport/tabs/cookies/cookiesLandingContainer';
import reshapeCookies from '../utils/reshapeCookies';
import sidebarData from './sidebarData';
import { generateSiteMapReportandDownload } from '../utils/reportDownloader';
import Layout from './layout';

interface SiteMapReportProps {
landingPageCookies: CookieFrameStorageType;
Expand All @@ -57,168 +47,19 @@ const SiteMapReport = ({
landingPageCookies,
completeJson,
}: SiteMapReportProps) => {
const [sites, setSites] = useState<string[]>([]);
const [data, setData] = useState<SidebarItems>(sidebarData);

useEffect(() => {
const _sites = new Set<string>();
Object.values(cookies).forEach((cookieData) => {
Object.values(cookieData).forEach((cookie) => {
_sites.add(cookie.pageUrl || '');
});
});

setSites(Array.from(_sites));
}, [cookies]);

const frames = useMemo(() => {
return Object.keys(cookies).reduce((acc, frame) => {
if (frame?.includes('http') || frame === UNKNOWN_FRAME_KEY) {
acc[frame] = {} as TabFrames[string];
}
return acc;
}, {} as TabFrames);
}, [cookies]);

const reshapedCookies = useMemo(
() => reshapeCookies(landingPageCookies),
[landingPageCookies]
);

const cookiesWithIssues = useMemo(
() =>
Object.fromEntries(
Object.entries(reshapedCookies).filter(([, cookie]) => cookie.isBlocked)
),
[reshapedCookies]
);

const {
activePanel,
selectedItemKey,
sidebarItems,
isSidebarFocused,
setIsSidebarFocused,
updateSelectedItemKey,
onKeyNavigation,
toggleDropdown,
isKeyAncestor,
isKeySelected,
} = useSidebar({ data });

const siteFilteredCookies = useMemo(() => {
return Object.entries(cookies).reduce(
(acc: CookieFrameStorageType, [frame, _cookies]) => {
acc[frame] = Object.fromEntries(
Object.entries(_cookies).filter(([, cookie]) =>
isKeySelected(cookie.pageUrl || '')
)
);

return acc;
},
{}
);
}, [cookies, isKeySelected]);

const siteFilteredTechnologies = useMemo(() => {
return technologies.filter((technology) =>
isKeySelected(technology.pageUrl || '')
);
}, [isKeySelected, technologies]);

useEffect(() => {
setData((prev) => {
const _data = { ...prev };

_data['sitemap-landing-page'].panel = (
<CookiesLandingContainer
tabCookies={reshapedCookies}
tabFrames={frames}
cookiesWithIssues={cookiesWithIssues}
downloadReport={() => {
if (!Array.isArray(completeJson)) {
return;
}

generateSiteMapReportandDownload(completeJson);
}}
/>
);

_data['sitemap-landing-page'].children = sites.reduce(
(acc: SidebarItems, site: string) => {
acc[site] = {
title: site,
panel: (
<SiteReport
cookies={siteFilteredCookies}
technologies={siteFilteredTechnologies}
completeJson={completeJson}
selectedSite={site}
/>
),
children: {},
icon: <File />,
selectedIcon: <FileWhite />,
};

return acc;
},
{}
);

_data['sitemap-cookies-with-issues'].panel = (
<SiteMapCookiesWithIssues
cookies={Object.values(reshapedCookies).filter(
(cookie) => cookie.isBlocked
)}
/>
);

return _data;
});
}, [
cookiesWithIssues,
completeJson,
frames,
isKeySelected,
reshapedCookies,
siteFilteredCookies,
siteFilteredTechnologies,
sites,
]);

useEffect(() => {
if (selectedItemKey === null && Object.keys(data).length > 0) {
updateSelectedItemKey('sitemap-landing-page');
}
}, [data, isKeySelected, selectedItemKey, updateSelectedItemKey]);

return (
<div className="w-full h-screen flex">
<Resizable
defaultSize={{ width: '200px', height: '100%' }}
minWidth={'150px'}
maxWidth={'50%'}
enable={{
right: true,
}}
>
<Sidebar
selectedItemKey={selectedItemKey}
sidebarItems={sidebarItems}
isSidebarFocused={isSidebarFocused}
setIsSidebarFocused={setIsSidebarFocused}
onKeyNavigation={onKeyNavigation}
updateSelectedItemKey={updateSelectedItemKey}
toggleDropdown={toggleDropdown}
isKeyAncestor={isKeyAncestor}
isKeySelected={isKeySelected}
/>
</Resizable>
<div className="flex-1 max-h-screen overflow-auto">{activePanel}</div>
</div>
<SidebarProvider data={data}>
<Layout
landingPageCookies={landingPageCookies}
cookies={cookies}
technologies={technologies}
completeJson={completeJson}
sidebarData={data}
setSidebarData={setData}
/>
</SidebarProvider>
);
};

Expand Down
Loading
Loading