Skip to content

Commit

Permalink
equals
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Oct 8, 2024
1 parent 99bce8d commit 5160848
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/ui/app/src/atoms/launchdarkly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const SET_LAUNCH_DARKLY_INFO_ATOM = atom(undefined, async (get, set, info: Launc
});

// TODO: support non-boolean flags
export const useLaunchDarklyFlag = (flag: string, not = false): boolean => {
export const useLaunchDarklyFlag = (flag: string, equals = true, not = false): boolean => {
useInitLaunchDarklyClient();

const client = useAtomValue(LD_CLIENT_ATOM);
Expand All @@ -53,9 +53,9 @@ export const useLaunchDarklyFlag = (flag: string, not = false): boolean => {
return not;
}
// force the flag to be a boolean:
const isTrue = !!client.variation(flag, false);
const isTrue = client.variation(flag, false) === equals;
return not ? !isTrue : isTrue;
}, [client, flag, not]);
}, [client, equals, flag, not]);

const [enabled, setEnabled] = useState(getFlagEnabled);

Expand Down
10 changes: 8 additions & 2 deletions packages/ui/app/src/mdx/components/launchdarkly/LaunchDarkly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { LinkPreloadApiRoute } from "../../../components/LinkPreload";

export interface LaunchDarklyProps {
flag: string;
equals?: boolean;
not?: boolean;
}

export function LaunchDarkly({ not = false, flag, children }: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const show = useLaunchDarklyFlag(flag, not);
export function LaunchDarkly({
equals = true,
not = false,
flag,
children,
}: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const show = useLaunchDarklyFlag(flag, equals, not);

return (
<>
Expand Down

0 comments on commit 5160848

Please sign in to comment.