Skip to content

Commit

Permalink
Refactor: Update table storage and prefix icon type (#546)
Browse files Browse the repository at this point in the history
* ref: update prefix icon type and render component directly

* ref: use session storage for persistence
  • Loading branch information
mayan-000 authored Mar 11, 2024
1 parent 8ad44f0 commit 8a59d4e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ interface BodyCellProps {
row: TableRow;
hasIcon?: boolean;
showIcon?: boolean | null;
icon?: () => React.JSX.Element;
icon?: {
Element: (props: any) => React.JSX.Element;
};
onRowClick: (e: React.MouseEvent<HTMLDivElement>) => void;
}

const BodyCell = ({
cell,
width,
isRowFocused,
row,
hasIcon = false,
showIcon = false,
icon,
isHighlighted = false,
}: BodyCellProps) => {
const IconElement = icon?.Element;

return (
<div
tabIndex={0}
Expand Down Expand Up @@ -72,7 +77,13 @@ const BodyCell = ({
>
{hasIcon && (
<div className="h-full grid place-items-center min-w-[15px] pr-1">
{Boolean(showIcon) && icon?.()}
{Boolean(showIcon) && IconElement && (
<IconElement
{...{
originalData: row.originalData,
}}
/>
)}
</div>
)}
{cell?.() ?? ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ const BodyRow = ({
showIcon={
showBodyCellPrefixIcon ? showBodyCellPrefixIcon(row) : false
}
icon={
bodyCellPrefixIcon ? () => bodyCellPrefixIcon(row) : undefined
}
icon={bodyCellPrefixIcon ?? undefined}
/>
)
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ const extractChromeStorage = async (
): Promise<TablePersistentSettingsStoreContext['state']> => {
const tabId = chrome.devtools.inspectedWindow.tabId.toString();

const data = await chrome.storage.local.get();
const tableData = data?.[tabId];
const data = await chrome.storage.session.get();
const tableData = data?.[tabId + persistenceKey];
if (tableData) {
const persistenceData = tableData?.[persistenceKey];
if (persistenceData) {
return persistenceData;
}
return tableData;
}

return {} as TablePersistentSettingsStoreContext['state'];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ const updateChromeStorage = async (
}
const tabId = chrome.devtools.inspectedWindow.tabId.toString();

const data = await chrome.storage.local.get();
const data = await chrome.storage.session.get();

let tableData: TablePersistentSettingsStoreContext['state'] =
data?.[tabId]?.[TABLE_PERSISTENT_SETTINGS_STORE_KEY];
data?.[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY];
let requiredData = tableData?.[persistenceKey];

if (requiredData) {
Expand All @@ -108,9 +108,9 @@ const updateChromeStorage = async (
requiredData = storageData;
}

if (!tableData && data[tabId]) {
data[tabId][TABLE_PERSISTENT_SETTINGS_STORE_KEY] = {};
tableData = data[tabId][TABLE_PERSISTENT_SETTINGS_STORE_KEY];
if (!tableData) {
data[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY] = {};
tableData = data[tabId + TABLE_PERSISTENT_SETTINGS_STORE_KEY];
}

if (tableData && !tableData[persistenceKey]) {
Expand All @@ -120,7 +120,7 @@ const updateChromeStorage = async (
tableData[persistenceKey] = requiredData;
}

await chrome.storage.local.set(data);
await chrome.storage.session.set(data);

return tableData;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export type TableColumn = {
cell: (info: InfoType, details?: TableData) => React.JSX.Element | InfoType;
enableHiding?: boolean;
enableBodyCellPrefixIcon?: boolean;
bodyCellPrefixIcon?: (row: TableRow) => React.JSX.Element;
bodyCellPrefixIcon?: {
Element: (props: any) => React.JSX.Element;
};
showBodyCellPrefixIcon?: (row: TableRow) => boolean;
widthWeightagePercentage?: number;
width?: number; // For internal use only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import { useCookieStore } from '../../../../stateProviders/syncCookieStore';
import useHighlighting from './useHighlighting';
import { useSettingsStore } from '../../../../stateProviders/syncSettingsStore';
import namePrefixIconSelector from './namePrefixIconSelector';
import NamePrefixIconSelector from './namePrefixIconSelector';

const useCookieListing = (domainsInAllowList: Set<string>) => {
const { selectedFrame, cookies, getCookiesSetByJavascript } = useCookieStore(
Expand All @@ -64,7 +64,9 @@ const useCookieListing = (domainsInAllowList: Set<string>) => {
enableHiding: false,
widthWeightagePercentage: 13,
enableBodyCellPrefixIcon: isUsingCDP,
bodyCellPrefixIcon: namePrefixIconSelector,
bodyCellPrefixIcon: {
Element: NamePrefixIconSelector,
},
showBodyCellPrefixIcon: (row: TableRow) => {
const isBlocked = Boolean(
(row.originalData as CookieTableData)?.blockingStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import React from 'react';
import { BLOCK_STATUS, type CookieTableData } from '@ps-analysis-tool/common';
import {
type TableRow,
GreenTick,
InboundIcon,
OutboundIcon,
Expand All @@ -29,7 +28,13 @@ import {
OutboundInboundColoredIcon,
} from '@ps-analysis-tool/design-system';

const namePrefixIconSelector = ({ originalData }: TableRow) => {
interface NamePrefixIconSelectorProps {
originalData: CookieTableData;
}

const NamePrefixIconSelector = ({
originalData,
}: NamePrefixIconSelectorProps) => {
const data = originalData as CookieTableData;

const isDomainInAllowList = data?.isDomainInAllowList;
Expand Down Expand Up @@ -93,4 +98,4 @@ const namePrefixIconSelector = ({ originalData }: TableRow) => {
return <></>;
};

export default namePrefixIconSelector;
export default NamePrefixIconSelector;

0 comments on commit 8a59d4e

Please sign in to comment.