Skip to content

Commit

Permalink
Feature: Bridge PA data to UI panels (#864)
Browse files Browse the repository at this point in the history
* Update types, row height class, sorting and resizing logic

* Update tables column, filters config, UI changes to tables, add bottom tray and handle prettyJson

* Update colors, tabs, and pill classes

* Add frameoverlay for auctions table

* Update type and dependency

* Update data providers to handle PA data

* Fix tests

* Conditionally reset data

* Remove the word date and minor refactoring

---------

Co-authored-by: sayedtaqui <[email protected]>
  • Loading branch information
mayan-000 and mohdsayed authored Nov 5, 2024
1 parent 621e115 commit 6485fc6
Show file tree
Hide file tree
Showing 42 changed files with 1,589 additions and 334 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/common/src/protectedAudience.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export type AdsAndBiddersType = {
adUnitCode: string;
bidders: string[];
mediaContainerSize: number[][];
winningBid: number;
bidCurrency: string;
winningBidder: string;
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/src/components/pill/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface PillProps {

const Pill = ({ title }: PillProps) => {
return (
<div className="h-5 p-2 text-raisin-black dark:text-bright-gray border border-gray-300 dark:border-quartz rounded-full">
<div className="h-fit p-1 dark:text-bright-gray border border-gray-400 dark:border-dark-gray-x11 rounded-full">
{title}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface TableProps {
extraInterfaceToTopBar?: () => React.JSX.Element;
minWidth?: string;
hideSearch?: boolean;
rowHeightClass?: string;
}

const Table = ({
Expand All @@ -47,6 +48,7 @@ const Table = ({
extraInterfaceToTopBar,
minWidth,
hideSearch,
rowHeightClass,
}: TableProps) => {
const {
tableContainerRef,
Expand Down Expand Up @@ -122,7 +124,7 @@ const Table = ({
extraInterface={extraInterfaceToTopBar}
hideSearch={hideSearch}
/>
{!hideFiltering && (
{hideFiltering ? null : (
<ChipsBar
selectedFilters={selectedFilters}
resetFilters={resetFilters}
Expand All @@ -137,6 +139,7 @@ const Table = ({
enable={{
right: true,
}}
className="overflow-auto h-full"
>
<FiltersSidebar
filters={filters}
Expand Down Expand Up @@ -171,6 +174,7 @@ const Table = ({
isRowFocused={isRowFocused}
setIsRowFocused={setIsRowFocused}
selectedKey={selectedKey}
rowHeightClass={rowHeightClass}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface BodyCellProps {
Element: (props: any) => React.JSX.Element;
};
onRowClick: (e: React.MouseEvent<HTMLDivElement>) => void;
rowHeightClass?: string;
}

const BodyCell = ({
Expand All @@ -47,6 +48,7 @@ const BodyCell = ({
showIcon = false,
icon,
isHighlighted = false,
rowHeightClass,
}: BodyCellProps) => {
const IconElement = icon?.Element;
const cellValue = cell?.() ?? '';
Expand All @@ -68,13 +70,13 @@ const BodyCell = ({
e.stopPropagation();
}
}}
className={`flex box-border outline-0 px-1 py-px h-5 text-xs ${
className={`flex box-border outline-0 px-1 py-px text-xs ${
isHighlighted
? `${
isRowFocused ? 'text-white' : 'dark:text-dirty-red text-dirty-red'
}`
: 'dark:text-bright-gray'
} cursor-default flex-1`}
} cursor-default flex-1 ${rowHeightClass ?? 'h-5'}`}
>
{hasIcon && (
<div className="h-full grid place-items-center min-w-[15px] pr-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface BodyRowProps {
e: React.MouseEvent<HTMLDivElement>,
row: TableRow
) => void;
rowHeightClass?: string;
}

const BodyRow = ({
Expand All @@ -55,6 +56,7 @@ const BodyRow = ({
onRowClick,
onKeyDown,
onRowContextMenu,
rowHeightClass,
}: BodyRowProps) => {
const rowKey = getRowObjectKey(row);
const isHighlighted = row.originalData?.highlighted;
Expand Down Expand Up @@ -123,6 +125,7 @@ const BodyRow = ({
showBodyCellPrefixIcon ? showBodyCellPrefixIcon(row) : false
}
icon={bodyCellPrefixIcon ?? undefined}
rowHeightClass={rowHeightClass}
/>
)
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ interface TableBodyProps {
isRowFocused: boolean;
setIsRowFocused: (state: boolean) => void;
selectedKey: string | undefined | null;
rowHeightClass?: string;
}

const TableBody = ({
isRowFocused,
setIsRowFocused,
selectedKey,
rowHeightClass,
}: TableBodyProps) => {
const {
rows,
Expand Down Expand Up @@ -125,7 +127,8 @@ const TableBody = ({
);

const tableRowClassName = classNames(
'h-5 outline-0 flex divide-x divide-american-silver dark:divide-quartz',
'outline-0 flex divide-x divide-american-silver dark:divide-quartz',
rowHeightClass ?? 'h-5',
selectedKey === null &&
(isRowFocused
? 'bg-gainsboro dark:bg-outer-space'
Expand Down Expand Up @@ -163,6 +166,7 @@ const TableBody = ({
}}
onKeyDown={handleKeyDown}
onRowContextMenu={onRowContextMenu}
rowHeightClass={rowHeightClass}
/>
))}
<div
Expand Down
18 changes: 16 additions & 2 deletions packages/design-system/src/components/table/useTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@
/**
* External dependencies.
*/
import type { CookieTableData, ErroredOutUrlsData } from '@google-psat/common';
import type {
AdsAndBiddersType,
CookieTableData,
InterestGroups,
NoBidsType,
singleAuctionEvent,
ErroredOutUrlsData,
} from '@google-psat/common';

export type TableData = (CookieTableData | ErroredOutUrlsData) & {
export type TableData = (
| CookieTableData
| InterestGroups
| singleAuctionEvent
| NoBidsType[keyof NoBidsType]
| AdsAndBiddersType[keyof AdsAndBiddersType]
| ErroredOutUrlsData
) & {
highlighted?: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ const useColumnResizing = (
);
}
}

return () => {
setColumns([]);
};
}, [getPreferences, setColumnsCallback, tablePersistentSettingsKey]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ const useColumnSorting = (
)?.sortingComparator;

const _sortedData = [...data].sort((a, b) => {
let candidateA = getValueByKey(sortKey, a);
let candidateB = getValueByKey(sortKey, b);
let candidateA = getValueByKey(sortKey, a) ?? '';
let candidateB = getValueByKey(sortKey, b) ?? '';

if (sortingComparator) {
return sortingComparator(candidateA, candidateB) * (ascending ? 1 : -1);
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/src/components/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Tabs = ({ items, activeTab, setActiveTab }: TabsProps) => {
onClick={() => setActiveTab(index)}
onKeyDown={handleKeyDown}
className={classNames(
'pb-1.5 px-3 border-b-2 hover:opacity-80 outline-none text-sm',
'pb-1.5 px-1.5 border-b-2 hover:opacity-80 outline-none text-sm text-nowrap',
{
'border-bright-navy-blue dark:border-jordy-blue text-bright-navy-blue dark:text-jordy-blue':
index === activeTab,
Expand Down
1 change: 1 addition & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"marked-alert": "^2.0.2",
"mermaid": "^11.2.0",
"p-queue": "^7.3.4",
"pretty-print-json": "^3.0.2",
"re-resizable": "^6.9.9",
"react": "^18.2.0",
"react-copy-to-clipboard": "^5.1.0",
Expand Down
97 changes: 96 additions & 1 deletion packages/extension/src/contentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class WebpageContentScript {
*/
isInspecting = false;

/**
* If true, the page is currently being inspected.
*/
mode = 'Cookies';

/**
* If true, the mouse is currently hovering over the page.
*/
Expand Down Expand Up @@ -320,11 +325,18 @@ class WebpageContentScript {
*/
onMessage = (response: ResponseType) => {
this.isInspecting = response.isInspecting;
if (response?.selectedAdUnit) {
this.mode = 'PA';
}

if (response.isInspecting) {
this.removeEventListeners();
this.addEventListeners();
toggleFrameHighlighting(true);
toggleFrameHighlighting(
true,
response?.selectedAdUnit,
this.mode === 'PA'
);
this.insertPopovers(response);
} else {
this.abortInspection();
Expand Down Expand Up @@ -352,6 +364,78 @@ class WebpageContentScript {
return overlay;
}

/**
* Insert tooltip.
* @param {ResponseType} response Response.
* @returns {HTMLElement} Tooltip.
*/
insertProtectedAudienceTooltip(response: ResponseType): HTMLElement | null {
if (!response.selectedAdUnit) {
return null;
}

const frame = document.getElementById(response.selectedAdUnit);

if (!frame) {
return null;
}
removeAllPopovers();
this.insertOverlay(frame);

const tooltip = addTooltip(frame, response, 0, 0);

const arrowElement = document.getElementById('ps-content-tooltip-arrow');

if (frame && tooltip && arrowElement) {
this.cleanup = autoUpdate(frame, tooltip, () => {
computePosition(frame, tooltip, {
platform: platform,
placement: 'top',
middleware: [
shift({
boundary: document.querySelector('body'),
}),
flip({
boundary: document.querySelector('body'),
}),
arrow({
element: arrowElement,
}),
],
}).then(({ x, y, middlewareData, placement }) => {
Object.assign(tooltip.style, {
top: `${y}px`,
left: `${x}px`,
});
const side = placement.split('-')[0];

const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[side];

if (middlewareData.arrow) {
const { x: arrowX, y: arrowY } = middlewareData.arrow;

Object.assign(arrowElement.style, {
left: arrowX ? `${arrowX - 15}px` : '',
top: arrowY ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide as string]: `${arrowElement.offsetWidth / 2}px`,
transform: 'rotate(45deg)',
});
}
return tooltip;
});
});
}

return tooltip;
}

/**
* Insert tooltip.
* @param {HTMLElement} frame Frame
Expand Down Expand Up @@ -477,6 +561,7 @@ class WebpageContentScript {
this.port?.onMessage.removeListener(this.onMessage);
this.port = null;
this.abortInspection();
this.mode = 'Cookies';
};

/**
Expand Down Expand Up @@ -586,6 +671,12 @@ class WebpageContentScript {
* @param {ResponseType} response - The incoming message/response from the port.
*/
insertPopovers(response: ResponseType) {
if (response.isForProtectedAudience) {
const tooltip = this.insertProtectedAudienceTooltip(response);
tooltip?.scrollIntoView();
return;
}

// If the no frame was selected in devtool.
if (response.removeAllFramePopovers && !response.selectedFrame) {
removeAllPopovers();
Expand Down Expand Up @@ -638,6 +729,10 @@ class WebpageContentScript {
*/
// eslint-disable-next-line complexity
handleHoverEvent = (event: MouseEvent) => {
if (this.mode === 'PA') {
return;
}

const target = event.target as HTMLElement;
const isNonIframeElement = target.tagName !== 'IFRAME';
const isTooltipElement =
Expand Down
Loading

0 comments on commit 6485fc6

Please sign in to comment.