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

Refactor: Update table storage and prefix icon type #546

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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;
Loading