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

Feature: Enable navigating from a sitemap report insights page #736

Merged
merged 7 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"ignorePatterns": [
"**/node_modules/**",
"dist/**",
"dist-types/**",
"**/dist/**",
"**/dist-types/**",
"out/**",
"data/**",
"coverage/**"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
timeout-minutes: 20
steps:
- name: Harden Runner # Security agent: blocks outbound traffic & detects code overwrite to prevent breaches
uses: step-security/harden-runner@128a63446a954579617e875aaab7d2978154e969
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6
mayan-000 marked this conversation as resolved.
Show resolved Hide resolved
with:
disable-sudo: true
disable-file-monitoring: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Layout = ({
}));

const { Element: PanelElement, props } = activePanel.panel;
const { query, clearQuery } = activePanel;

const [
siteFilteredCookies,
Expand Down Expand Up @@ -179,6 +180,8 @@ const Layout = ({
selectedSite: site,
path,
libraryMatches: libraryMatches ? libraryMatches[site] : {},
query,
clearQuery,
},
},
children: {},
Expand Down Expand Up @@ -219,6 +222,8 @@ const Layout = ({
siteFilteredCookies,
siteFilteredTechnologies,
sites,
query,
clearQuery,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
SIDEBAR_ITEMS_KEYS,
} from '@google-psat/design-system';
import { I18n } from '@google-psat/i18n';
import { noop } from '@google-psat/common';

/**
* Internal dependencies.
Expand All @@ -41,9 +42,16 @@ import Technologies from '../tabs/technologies';
interface LayoutProps {
selectedSite: string | null;
setSidebarData: React.Dispatch<React.SetStateAction<SidebarItems>>;
query?: string;
clearQuery?: () => void;
}

const Layout = ({ selectedSite, setSidebarData }: LayoutProps) => {
const Layout = ({
selectedSite,
setSidebarData,
query = '',
clearQuery = noop,
}: LayoutProps) => {
const { technologies, completeJson } = useContentStore(({ state }) => ({
technologies: state.technologies,
completeJson: state.completeJson,
Expand Down Expand Up @@ -80,18 +88,14 @@ const Layout = ({ selectedSite, setSidebarData }: LayoutProps) => {
},
};

const selectedFrameUrl = frameUrls.find(
(url) => url === keys[keys.length - 1]
);

_data[SIDEBAR_ITEMS_KEYS.COOKIES].children = frameUrls.reduce(
(acc: SidebarItems, url: string): SidebarItems => {
acc[url] = {
title: url,
panel: {
Element: CookiesTab,
props: {
selectedFrameUrl,
selectedFrameUrl: keys[keys.length - 1],
selectedSite,
},
},
Expand Down Expand Up @@ -167,6 +171,13 @@ const Layout = ({ selectedSite, setSidebarData }: LayoutProps) => {
}
}, [selectedSite, updateSelectedItemKey]);

useEffect(() => {
if (query) {
updateSelectedItemKey(frameUrls[0], query);
clearQuery();
}
}, [query, clearQuery, updateSelectedItemKey, frameUrls]);

return (
<div className="w-full h-full flex">
<Resizable
Expand Down
23 changes: 17 additions & 6 deletions packages/cli-dashboard/src/components/siteReport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
* External dependencies
*/
import React, { useState } from 'react';
import type {
CompleteJson,
CookieJsonDataType,
LibraryData,
TechnologyData,
import {
noop,
type CompleteJson,
type CookieJsonDataType,
type LibraryData,
type TechnologyData,
} from '@google-psat/common';
import { SidebarProvider, type SidebarItems } from '@google-psat/design-system';

Expand All @@ -44,6 +45,8 @@ interface SiteReportProps {
selectedSite: string | null;
path: string;
libraryMatches: LibraryData | null;
query?: string;
clearQuery?: () => void;
}

const SiteReport = ({
Expand All @@ -53,8 +56,11 @@ const SiteReport = ({
selectedSite,
path,
libraryMatches,
query = '',
clearQuery = noop,
}: SiteReportProps) => {
const [data, setData] = useState<SidebarItems>(Tabs);

return (
<ContentStoreProvider
cookies={cookies}
Expand All @@ -64,7 +70,12 @@ const SiteReport = ({
path={path}
>
<SidebarProvider data={data}>
<Layout selectedSite={selectedSite} setSidebarData={setData} />
<Layout
selectedSite={selectedSite}
setSidebarData={setData}
query={query}
clearQuery={clearQuery}
/>
</SidebarProvider>
</ContentStoreProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ const CookiesListing = ({
[tabCookies, selectedFrameUrl]
);

const memoTabCookies = useMemo(() => Object.values(tabCookies), [tabCookies]);

const {
tableColumns,
filters,
searchKeys,
tablePersistentSettingsKey,
isSidebarOpen,
} = useCookieListing(
Object.values(tabCookies),
memoTabCookies,
selectedFrameUrl,
'cookiesListing' + selectedSite,
'cookiesListing',
selectedSite
);

Expand Down
38 changes: 25 additions & 13 deletions packages/cli-dashboard/src/hooks/useCookieListing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const useCookieListing = (
[activePanelQuery]
);

const tablePersistentSettingsKey = useMemo(() => {
if (selectedSite) {
return persistenceKey + '#' + selectedSite + selectedFrameUrl;
}

return persistenceKey + '#' + selectedFrameUrl;
}, [persistenceKey, selectedFrameUrl, selectedSite]);

const tableColumns = useMemo<TableColumn[]>(
() => [
{
Expand Down Expand Up @@ -170,12 +178,24 @@ const useCookieListing = (
title: I18n.getMessage('category'),
hasStaticFilterValues: true,
hasPrecalculatedFilterValues: true,
filterValues: calculateDynamicFilterValues(
filterValues: evaluateStaticFilterValues(
{
[I18n.getMessage('analytics')]: {
selected: false,
},
[I18n.getMessage('functional')]: {
selected: false,
},
[I18n.getMessage('marketing')]: {
selected: false,
},
[I18n.getMessage('uncategorized')]: {
selected: false,
},
},
'analytics.category',
tabCookies,
parsedQuery?.filter?.['analytics.category'],
clearActivePanelQuery,
true
parsedQuery,
clearActivePanelQuery
),
sortValues: true,
useGenericPersistenceKey: true,
Expand Down Expand Up @@ -382,14 +402,6 @@ const useCookieListing = (
[]
);

const tablePersistentSettingsKey = useMemo(() => {
if (selectedSite) {
return persistenceKey + '#' + selectedSite + selectedFrameUrl;
}

return persistenceKey + '#' + selectedFrameUrl;
}, [persistenceKey, selectedFrameUrl, selectedSite]);

return {
tableColumns,
filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,24 @@ const useCookieListing = (domainsInAllowList: Set<string>) => {
title: I18n.getMessage('category'),
hasStaticFilterValues: true,
hasPrecalculatedFilterValues: true,
filterValues: calculateDynamicFilterValues(
filterValues: evaluateStaticFilterValues(
{
[I18n.getMessage('analytics')]: {
selected: false,
},
[I18n.getMessage('functional')]: {
selected: false,
},
[I18n.getMessage('marketing')]: {
selected: false,
},
[I18n.getMessage('uncategorized')]: {
selected: false,
},
},
'analytics.category',
Object.values(cookies),
parsedQuery?.filter?.['analytics.category'],
clearActivePanelQuery,
true
parsedQuery,
clearActivePanelQuery
),
sortValues: true,
useGenericPersistenceKey: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ describe('useCookieListing', () => {
uncategorized: {
message: 'Uncategorized',
},
analytics: {
message: 'Analytics',
},
functional: {
message: 'Functional',
},
true: {
message: 'True',
},
Expand Down Expand Up @@ -115,6 +121,12 @@ describe('useCookieListing', () => {
result.current.filters['analytics.category'].hasPrecalculatedFilterValues
).toBe(true);
expect(result.current.filters['analytics.category'].filterValues).toEqual({
Analytics: {
selected: false,
},
Functional: {
selected: false,
},
Marketing: {
selected: false,
},
Expand Down
Loading