Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
RuntimeTerror10 committed May 16, 2024
2 parents ce0638e + acfbe6e commit 3391e7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import { useEffect } from "react";
import { StorageService } from "init";
import { useSelector } from "react-redux";
import { getAppMode } from "store/selectors";
import { CONSTANTS as GLOBAL_CONSTANTS } from "@requestly/requestly-core";
import { useFeatureValue } from "@growthbook/growthbook-react";
import { getImplicitRuleTestingWidgetConfig, updateImplictRuleTestingWidgetConfig } from "features/settings";
import { isFeatureCompatible } from "utils/CompatibilityUtils";
import APP_CONSTANTS from "config/constants";
import { isNull } from "lodash";
import Logger from "../../../../../../../common/logger";

export const InitImplicitWidgetConfigHandler = () => {
const appMode = useSelector(getAppMode);
const implicitRuleTestingFlag = useFeatureValue("implicit_test_this_rule", null);

useEffect(() => {
if (isFeatureCompatible(APP_CONSTANTS.FEATURES.IMPLICIT_TEST_THIS_RULE)) {
if (!isNull(implicitRuleTestingFlag)) {
if (implicitRuleTestingFlag.enabled) {
getImplicitRuleTestingWidgetConfig(appMode).then((record) => {
if (record === undefined) {
updateImplictRuleTestingWidgetConfig(appMode, {
enabled: true,
visibility: GLOBAL_CONSTANTS.IMPLICIT_RULE_TESTING_WIDGET_VISIBILITY.ALL,
ruleTypes: [],
});
}
});
} else {
StorageService(appMode).removeRecord(GLOBAL_CONSTANTS.STORAGE_KEYS.IMPLICIT_RULE_TESTING_WIDGET_CONFIG);
}
}
getImplicitRuleTestingWidgetConfig(appMode)
.then((record) => {
if (record === undefined) {
updateImplictRuleTestingWidgetConfig(appMode, {
enabled: true,
visibility: GLOBAL_CONSTANTS.IMPLICIT_RULE_TESTING_WIDGET_VISIBILITY.ALL,
ruleTypes: [],
});
}
})
.catch((err) => {
Logger.log("Error fetching implicit rule testing widget config", err);
});
}
}, [appMode, implicitRuleTestingFlag]);
}, [appMode]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RuleTypesOptions } from "./components/RuleTypesOptions";
import { CONSTANTS as GLOBAL_CONSTANTS } from "@requestly/requestly-core";
import { isFeatureCompatible } from "utils/CompatibilityUtils";
import APP_CONSTANTS from "config/constants";
import { useFeatureValue } from "@growthbook/growthbook-react";
import { getImplicitRuleTestingWidgetConfig, updateImplictRuleTestingWidgetConfig } from "./utils";

export const ImplicitRuleTesting = () => {
Expand All @@ -16,7 +15,6 @@ export const ImplicitRuleTesting = () => {
const [widgetVisibility, setWidgetVisibility] = useState(
GLOBAL_CONSTANTS.IMPLICIT_RULE_TESTING_WIDGET_VISIBILITY.ALL
);
const implicitRuleTestingFlag = useFeatureValue("implicit_test_this_rule", null);

const isCompatible = useMemo(() => isFeatureCompatible(APP_CONSTANTS.FEATURES.IMPLICIT_TEST_THIS_RULE), []);

Expand Down Expand Up @@ -44,8 +42,7 @@ export const ImplicitRuleTesting = () => {
}, [appMode]);

return (
isCompatible &&
implicitRuleTestingFlag?.enabled && (
isCompatible && (
<SettingsItem
isActive={isImplicitRuleTestingEnabled}
onChange={handleImplicitRuleTestingToggleChange}
Expand Down

0 comments on commit 3391e7c

Please sign in to comment.