Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
nafees87n committed May 20, 2024
2 parents ceb668a + 609886a commit 1e76cd3
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 38 deletions.
12 changes: 7 additions & 5 deletions app/src/components/common/SourceUrl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ export const SourceConditionInput: React.FC<SourceProps> = ({
onSourceChange({ ...source, key: value });
}}
>
{Object.entries(SourceKey).map(([key, value]) => (
<Select.Option key={value} value={value}>
{capitalize(value)}
</Select.Option>
))}
{Object.entries(SourceKey).map(([key, value]) =>
value === SourceKey.PATH ? null : (
<Select.Option key={value} value={value}>
{capitalize(value)}
</Select.Option>
)
)}
</Select>
</Col>
<Col className="shrink-0 source-condition-input-select">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const RequestSourceRow = ({ rowIndex, pair, pairIndex, ruleDetails, isInputDisab
).length
: Object.keys(currentlySelectedRuleData.pairs[pairIndex].source.filters || {}).filter(
(key) => key !== GLOBAL_CONSTANTS.RULE_SOURCE_FILTER_TYPES.PAGE_URL
).length.length;
).length;
},
[currentlySelectedRuleData, isSourceFilterFormatUpgraded]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ import {
trackMigrationNotificationClosed,
trackMigrationNotificationShown,
} from "features/rules/analytics";
import { StorageService } from "init";
import { getAppMode } from "store/selectors";

export function NotificationCard() {
const [isVisible, setIsVisible] = useState(false);
const currentlyActiveWorkspace = useSelector(getCurrentlyActiveWorkspace);
const appMode = useSelector(getAppMode);

const [isVisible, setIsVisible] = useState(false);
const [doesAnyRuleExist, setDoesAnyRuleExist] = useState(false);

const { openMigratonModalAction } = useRulesModalsContext();

Expand Down Expand Up @@ -48,17 +53,36 @@ export function NotificationCard() {
return migratedRulesLogs;
}, [currentlyActiveWorkspace]);

useEffect(() => {
const isShowNotification = useMemo(() => {
const migrationData = getMV3MigrationData();

if (
return (
Object.keys(migratedRulesLogs).length > 0 &&
!migrationData[currentlyActiveWorkspace?.id ?? "private"]?.migrationModalViewed
) {
!migrationData[currentlyActiveWorkspace?.id ?? "private"]?.migrationModalViewed &&
doesAnyRuleExist
);
}, [currentlyActiveWorkspace?.id, doesAnyRuleExist, migratedRulesLogs]);

useEffect(() => {
if (isShowNotification) {
trackMigrationNotificationShown();
setIsVisible(true);
} else {
setIsVisible(false);
}
}, [currentlyActiveWorkspace?.id, migratedRulesLogs]);
}, [isShowNotification]);

useEffect(() => {
Object.keys(migratedRulesLogs).forEach((ruleId) => {
StorageService(appMode)
.getRecord(ruleId)
.then((rule) => {
if (rule) {
setDoesAnyRuleExist(true);
}
});
});
});

const handleOnClick = useCallback(() => {
trackMigrationNotificationClicked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const parseQueryParams = (modifications: QueryParamRuleModification[]): QueryPar
},
};

modifications.forEach((modification) => {
for (const modification of modifications) {
if (modification.type === QueryParamModificationType.ADD) {
transform.queryTransform.addOrReplaceParams.push({
key: modification.param,
Expand All @@ -19,9 +19,13 @@ const parseQueryParams = (modifications: QueryParamRuleModification[]): QueryPar
} else if (modification.type === QueryParamModificationType.REMOVE) {
transform.queryTransform.removeParams.push(modification.param);
} else {
// case remove all
transform.query = "";
// queryTransform is not needed if query is present
delete transform.queryTransform;
break;
}
});
}

return transform;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const parseRedirectRule = (rule: RedirectRule): ExtensionRule[] => {
redirect: {},
};

if (condition.regexFilter) {
if (condition.regexFilter && rulePair.destination.match(/\$[1-9]/g)) {
action.redirect.regexSubstitution = rulePair.destination.replace(/\$([1-9])/g, "\\$1");
} else {
action.redirect.url = rulePair.destination;
Expand Down
2 changes: 1 addition & 1 deletion browser-extension/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface UrlSource {

export interface RuleSourceFilter {
pageDomains: string[];
requestMethod: HttpRequestMethod;
requestMethod: HttpRequestMethod[];
resourceType: ResourceType[];
}

Expand Down
30 changes: 15 additions & 15 deletions browser-extension/mv2/src/external/tabService.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@

ensureTabLoadingComplete(tabId) {
return new Promise((resolve, reject) => {
const tab = this.getTab(tabId);

if (tab) {
if (tab.status === "complete") {
resolve();
chrome.tabs.get(tabId, (tab) => {
if (tab) {
if (tab.status === "complete") {
resolve();
} else {
const handler = (currentTabId, tabChangeInfo) => {
if (currentTabId === tabId && tabChangeInfo.status === "complete") {
chrome.tabs.onUpdated.removeListener(handler);
resolve();
}
};
chrome.tabs.onUpdated.addListener(handler);
}
} else {
const handler = (currentTabId, tabChangeInfo) => {
if (currentTabId === tabId && tabChangeInfo.status === "complete") {
chrome.tabs.onUpdated.removeListener(handler);
resolve();
}
};
chrome.tabs.onUpdated.addListener(handler);
reject();
}
} else {
reject();
}
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export const handleInitiatorDomainFunction = async (
urlFilter: `|${requestDetails.url}|`,
resourceTypes: [chrome.declarativeNetRequest.ResourceType.XMLHTTPREQUEST],
tabIds: [tabId],
requestMethods: [requestDetails.method.toLowerCase() as chrome.declarativeNetRequest.RequestMethod],
requestMethods:
matchedPair?.source?.filters?.[0]?.requestMethod?.map(
(method) => method.toLowerCase() as chrome.declarativeNetRequest.RequestMethod
) ?? undefined,
excludedInitiatorDomains: ["requestly.io", "requestly.com"],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class TabService {
}

ensureTabLoadingComplete(tabId: TabId): Promise<void> {
return new Promise((resolve, reject) => {
const tab = this.getTab(tabId);
return new Promise(async (resolve, reject) => {
const tab = await chrome.tabs.get(tabId);

if (tab) {
if (tab.status === "complete") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const onBeforeRequest = (details: chrome.webRequest.WebRequestBodyDetails) => {
return;
}

rulesStorageService.getEnabledRules().then((enabledRules) => {
let isMainFrameRequest = details.type === "main_frame" ? true : false;
let isMainFrameRequest = details.type === "main_frame" ? true : false;

rulesStorageService.getEnabledRules().then((enabledRules) => {
enabledRules.forEach((rule) => {
switch (rule.ruleType) {
case RuleType.REDIRECT:
Expand All @@ -37,6 +37,8 @@ const onBeforeRequest = (details: chrome.webRequest.WebRequestBodyDetails) => {
};

const onBeforeSendHeaders = (details: chrome.webRequest.WebRequestHeadersDetails) => {
let isMainFrameRequest = details.type === "main_frame" ? true : false;

rulesStorageService.getEnabledRules().then((enabledRules) => {
enabledRules.forEach((rule) => {
switch (rule.ruleType) {
Expand All @@ -50,7 +52,7 @@ const onBeforeSendHeaders = (details: chrome.webRequest.WebRequestHeadersDetails
initiatorDomain: details.initiator,
});
if (isApplied && matchedPair.modifications?.Request && matchedPair.modifications?.Request?.length > 0) {
ruleExecutionHandler.onRuleExecuted(rule, details);
ruleExecutionHandler.onRuleExecuted(rule, details, isMainFrameRequest);
}
break;
default:
Expand All @@ -62,6 +64,8 @@ const onBeforeSendHeaders = (details: chrome.webRequest.WebRequestHeadersDetails
};

const onHeadersReceived = (details: chrome.webRequest.WebResponseHeadersDetails) => {
let isMainFrameRequest = details.type === "main_frame" ? true : false;

rulesStorageService.getEnabledRules().then((enabledRules) => {
enabledRules.forEach((rule) => {
switch (rule.ruleType) {
Expand All @@ -74,7 +78,7 @@ const onHeadersReceived = (details: chrome.webRequest.WebResponseHeadersDetails)
initiatorDomain: details.initiator,
});
if (isApplied && matchedPair.modifications?.Response && matchedPair.modifications?.Response?.length > 0) {
ruleExecutionHandler.onRuleExecuted(rule, details);
ruleExecutionHandler.onRuleExecuted(rule, details, isMainFrameRequest);
}
break;
default:
Expand Down

0 comments on commit 1e76cd3

Please sign in to comment.