Skip to content

Commit

Permalink
馃獰 馃敡 Allow inspecting active experiments on window (#6404)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes committed May 8, 2023
1 parent 1305bc9 commit 368ab20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions airbyte-webapp/src/core/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from "react";

/**
* Utility to make a value via a getter available on the window object for debugging.
*/
export const useDebugVariable = (name: string, getter: () => unknown): void => {
useEffect(() => {
Object.defineProperty(window, name, {
get: getter,
configurable: true,
});
return () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (window as any)[name];
};
// We don't want to reattach this if the getter changes, to make sure consumers
// of this don't need to useCallback the argument.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [name]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LoadingPage } from "components";
import { useConfig } from "config";
import { useI18nContext } from "core/i18n";
import { useAnalyticsService } from "core/services/analytics";
import { useDebugVariable } from "core/utils/debug";
import { useAppMonitoringService, AppActionCodes } from "hooks/services/AppMonitoringService";
import { ExperimentProvider, ExperimentService } from "hooks/services/Experiment";
import type { Experiments } from "hooks/services/Experiment/experiments";
Expand Down Expand Up @@ -131,6 +132,11 @@ const LDInitializationWrapper: React.FC<React.PropsWithChildren<{ apiKey: string
});
}

useDebugVariable("_EXPERIMENTS", () => ({
...ldClient.current?.allFlags(),
...((process.env.REACT_APP_EXPERIMENT_OVERWRITES as unknown as Record<string, unknown>) ?? {}),
}));

useEffectOnce(() => {
const onFeatureFlagsChanged = () => {
// Update analytics context whenever a flag changes
Expand Down

0 comments on commit 368ab20

Please sign in to comment.