Skip to content

Commit

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

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

const client = useAtomValue(LD_CLIENT_ATOM);

// TODO: bootstrap the flag value from the server, and/or local storage
const getFlagEnabled = useCallback(() => {
if (!client) {
return false;
return not;
}
// force the flag to be a boolean:
return !!client.variation(flag, false);
}, [client, flag]);
const isTrue = !!client.variation(flag, false);
return not ? !isTrue : isTrue;
}, [client, flag, not]);

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

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

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

export function LaunchDarkly({ flag, children }: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const ldClient = useLaunchDarklyFlag(flag);

if (!ldClient) {
return null;
}
export function LaunchDarkly({ not = false, flag, children }: PropsWithChildren<LaunchDarklyProps>): ReactNode {
const show = useLaunchDarklyFlag(flag, not);

return (
<>
<LinkPreloadApiRoute href="/api/fern-docs/integrations/launchdarkly" />
{children}
{show && children}
</>
);
}

0 comments on commit 99bce8d

Please sign in to comment.